steilerDev / homebridge-openhab2-complete

A homebridge plugin for openHAB, that has the expectation to fully support all Services offered by Apple's Homekit Accessory Protocol (HAP)
GNU General Public License v3.0
52 stars 16 forks source link

Turning on a dimmer sets the default value to 0% #13

Closed extric99 closed 4 years ago

extric99 commented 5 years ago

Describe the bug When asking Siri to turn on a dimmer light, the value is set to 0% instead of 100% "Siri turn on Bed" results in the bed light turned on at 0%. When I ask "Siri turn bed on at 100%" it works but this should not be necessary.

Expected behavior The light should be turned on at 100%. This also happens with the other openhab homekit middleware and my hue lights.

Logs: Asking Siri to turn on the bed I get following homekit log entries.

2019-03-11 20:34:18 [OpenHAB2-Complete] Received State: 0 (transformed to false) for Bed [Dimmer_Slaapkamer2] 2019-03-11 20:34:18 [OpenHAB2-Complete] Received State: 0 (transformed to 0) for Bed [Dimmer_Slaapkamer2] 2019-03-11 20:34:32 [OpenHAB2-Complete] Updating State of Bed with Item Dimmer_Slaapkamer2 to 0

Environment (please complete the following information): Openhabian Docker:oznu latest

steilerDev commented 5 years ago

Seems to be related to #12

steilerDev commented 5 years ago

Could you please manually install the latest commit on the master branch and check if this fixes your issue?

extric99 commented 5 years ago

Happy to do so but not sure how exactly. I tried to google and came up with

npm install --save https://github.com/steilerDev/homebridge-openhab2-complete/tarball/master Would that be correct? Just want to be sure i am acrually testing a new version

steilerDev commented 5 years ago

Since you are also running homebridge inside the docker container, do the following:

  1. Remove the current installation This depends on how you added the plugin in the first place. If you installed it via docker exec <container name or id> npm install homebridge-openhab2-complete you need to docker exec <container name or id> npm remove homebridge-openhab2-complete or just remove the docker container (docker stop <container name or id> && docker rm <container name or id>). Otherwise remove the relevant line from startup.sh, in order to be sure, remove the container anyway.

  2. Download the latest version: Navigate to your homebridge volume, create a folder (I am using custom_node_modules). Then download the repository:

    git clone https://github.com/steilerDev/homebridge-openhab2-complete.git
  3. Install the downloaded version: Add the following line to your startup.sh

    npm install -g /homebridge/custom_node_modules/homebridge-openhab2-complete/

Let me know if you run into any issues.

extric99 commented 5 years ago

I think I need to resolve a permission issue for the download directory as it complains about missing write access

/homebridge # npm install -g dowload/homebridge-openhab2-complete/
npm WARN checkPermissions Missing write access to /homebridge/dowload/homebridge-openhab2- complete/node_modules/@types/node

steilerDev commented 5 years ago

The easiest way would be sudo chmod -R ugo+rwx <your folder> :P

steilerDev commented 5 years ago

Did you have the time to test this? The other issue was reported to be fixed, I'm curious if this is also the case for you.

extric99 commented 5 years ago

I tried earlier this week but was unable to get it installed. Was abroad until today so i will try to test over the weekend.

steilerDev commented 5 years ago

Unfortunately I broke the current master branch, if you want to test it anyway you should go to the 4687d560b7b58a21d66962fdd7929ba04aa26271 commit.

extric99 commented 5 years ago

Didn’t manage over the weekend as we are renovating the downstairs and back abroad this week so i will try asap when i return

steilerDev commented 5 years ago

No worries :)

jewesta commented 5 years ago

I did some tests today. While I had to use your current 0.10.0 release because I didn't know how to use the master I "manually" changed SetAndCommitLight.js and alternated between "0" and "OFF". Unfortunately the dimmer is switched to "0%" either way.

This is what I'm getting with "0" in the code:

"Hey Siri, Licht im Wohnzimmer auf 25%"

[3/31/2019, 1:43:24 PM] [openHAB2-Complete] Updating state of Licht im Wohnzimmer with item DimmerLivingRoom to 25
[3/31/2019, 1:43:24 PM] [openHAB2-Complete] Received push with new state for item DimmerLivingRoom: 25
[3/31/2019, 1:43:24 PM] [openHAB2-Complete] Received push with new state for item DimmerLivingRoom: 25
[3/31/2019, 1:43:24 PM] [openHAB2-Complete] Received push with new state for item DimmerLivingRoom: 1
[3/31/2019, 1:43:24 PM] [openHAB2-Complete] Received push with new state for item DimmerLivingRoom: 1
[3/31/2019, 1:43:27 PM] [openHAB2-Complete] Received push with new state for item DimmerLivingRoom: 25
[3/31/2019, 1:43:27 PM] [openHAB2-Complete] Received push with new state for item DimmerLivingRoom: 25

"Hey Siri, Licht im Wohnzimmer ausschalten."

[3/31/2019, 1:43:43 PM] [openHAB2-Complete] Updating state of Licht im Wohnzimmer with item DimmerLivingRoom to OFF
[3/31/2019, 1:43:43 PM] [openHAB2-Complete] Received push with new state for item DimmerLivingRoom: 0
[3/31/2019, 1:43:43 PM] [openHAB2-Complete] Received push with new state for item DimmerLivingRoom: 0
[3/31/2019, 1:43:43 PM] [openHAB2-Complete] Received push with new state for item DimmerLivingRoom: 24
[3/31/2019, 1:43:43 PM] [openHAB2-Complete] Received push with new state for item DimmerLivingRoom: 24
[3/31/2019, 1:43:45 PM] [openHAB2-Complete] Received push with new state for item DimmerLivingRoom: 0
[3/31/2019, 1:43:45 PM] [openHAB2-Complete] Received push with new state for item DimmerLivingRoom: 0

"Hey Siri, Licht im Wohnzimmer einschalten."

[3/31/2019, 1:45:29 PM] [openHAB2-Complete] Updating state of Licht im Wohnzimmer with item DimmerLivingRoom to 0

Here's the same with "OFF" in the code:

"Hey Siri, Licht im Wohnzimmer auf 25%"

[3/31/2019, 1:59:05 PM] [openHAB2-Complete] Updating state of Licht im Wohnzimmer with item DimmerLivingRoom to 25
[3/31/2019, 1:59:05 PM] [openHAB2-Complete] Received push with new state for item DimmerLivingRoom: 25
[3/31/2019, 1:59:05 PM] [openHAB2-Complete] Received push with new state for item DimmerLivingRoom: 25
[3/31/2019, 1:59:05 PM] [openHAB2-Complete] Received push with new state for item DimmerLivingRoom: 0
[3/31/2019, 1:59:05 PM] [openHAB2-Complete] Received push with new state for item DimmerLivingRoom: 0
[3/31/2019, 1:59:07 PM] [openHAB2-Complete] Received push with new state for item DimmerLivingRoom: 25
[3/31/2019, 1:59:07 PM] [openHAB2-Complete] Received push with new state for item DimmerLivingRoom: 25

"Hey Siri, Licht im Wohnzimmer ausschalten."

[3/31/2019, 1:59:14 PM] [openHAB2-Complete] Updating state of Licht im Wohnzimmer with item DimmerLivingRoom to OFF
[3/31/2019, 1:59:14 PM] [openHAB2-Complete] Received push with new state for item DimmerLivingRoom: 0
[3/31/2019, 1:59:14 PM] [openHAB2-Complete] Received push with new state for item DimmerLivingRoom: 0
[3/31/2019, 1:59:14 PM] [openHAB2-Complete] Received push with new state for item DimmerLivingRoom: 24
[3/31/2019, 1:59:14 PM] [openHAB2-Complete] Received push with new state for item DimmerLivingRoom: 24
[3/31/2019, 1:59:17 PM] [openHAB2-Complete] Received push with new state for item DimmerLivingRoom: 0
[3/31/2019, 1:59:17 PM] [openHAB2-Complete] Received push with new state for item DimmerLivingRoom: 0

"Hey Siri, Licht im Wohnzimmer einschalten."

[3/31/2019, 1:59:21 PM] [openHAB2-Complete] Updating state of Licht im Wohnzimmer with item DimmerLivingRoom to 0

What's really weird is that the brightness level is changing a couple of times after each command (except the final "switch on" command). This is only visible on the console. The "real" light is not showing those inbetween brightness states.

Hope that helps! Will do further experiments, if you want.

Cheers, Jens

steilerDev commented 5 years ago

I just released V0.10.1, could you please check if the issue still exists? @jewesta @extric99

jewesta commented 5 years ago

I tested 0.10.1 and I'm very sorry to report that the issue still exists. Unfortunately I also noticed that if I use a slider in Apple's Home app to adjust a dimmer, then the dimmer changes rapidly between various brightness settings. It looks like an endless loop at first but after a couple of seconds the constant changing stops at a certain (seemingly random) level. Not sure if this behavior is new.

steilerDev commented 5 years ago

I noticed this behavior as well (with the random reduction if set through the slider and below 50%). I actually don't have a clue what is causing this.

But the original issue (using Siri to set a specific value) still does not work?

extric99 commented 5 years ago

I finally figured out how to update :-(

Just tested with 0.10.1 and it still has the issue unfortunately. When you ask Siri to turn something on that is a dimmer the value is set to 0%

torpex77 commented 5 years ago

For what it's worth, I can confirm this behavior in the current version. I installed fresh using docker, then added "npm install homebridge-openhab2-complete" to startup.sh. Then added a couple of my dimmers.

Let me know if there is anything I can do to help test/debug.

Doug

jewesta commented 5 years ago

Is there anything I can do to assist in terms of the slider / value changing back and forth issue? Unfortunately this issue is beginning to significantly lower the homekit acceptance factor in my house. ;-) I am also observing it with roller shutters where it is a real pain in the butt. The shutters can sometimes start moving up and down for minutes if I am making the mistake of using a homekit slider. Because of this I have stopped using sliders in homekit altogether.

Would it help to peek into the code of homekit-openhab2 where the sliders do not show this strange behavior? Sorry, just grasping for straws here. I know you have probably done this already.

steilerDev commented 5 years ago

I just stopped using the slider or just adjust and immediately quit the view.

I tried to hunt down the problem and I Wasn't able to track it down. Feel free to look at the logs and everything I am happy about every hint. The problem is that it seems that homekit actually sends the request for the new values. The one thing I can image is a rounding error. Maybe I'll get around to look at this again.

torpex77 commented 4 years ago

I turned up debugging this morning and I think I found this.

My OpenHab item:

Dimmer Kitchen_Island_Light_Level

My Homebridge accessory:

        {
          "name": "Island",
          "type": "light",
          "item": "Kitchen_Island_Light_Level"
        }

I say "Hey Siri, turn on the Island LIghts". What happens: The light level is set to 0.

Here are the logs:

[7/14/2019, 10:49:07 AM] [openHAB2-Complete] Change binary target state of Island to true
[7/14/2019, 10:49:07 AM] [openHAB2-Complete] Preparing commit
[7/14/2019, 10:49:07 AM] [openHAB2-Complete] Received commit with object {"binary":true}
[7/14/2019, 10:49:07 AM] [openHAB2-Complete] Commiting light state with vectors (B,H,S,B): true,undefined,undefined,0

Here's the code from SetAndCommitLight.js

        this._log.debug(`Commiting light state with vectors (B,H,S,B): ${binary},${hue},${saturation},${brightness}`);
        if(binary === undefined && hue === undefined && saturation === undefined && brightness === undefined) {
            command = new Error("Unable to commit state, since necessary information are missing");
        } else if (hue === undefined && saturation === undefined && brightness === undefined) {
            command = binary ? "ON" : "OFF";
        } else if (hue === undefined && saturation === undefined) {
            command = binary ? `${brightness}` : "OFF";
        } else {
            command = binary ? `${hue},${saturation},${brightness}` : "OFF";
        }

Basically, homekit is setting binary as true, but brightness as 0. Which executes:

command = binary ? `${brightness}` : "OFF";

setting the light to 0, instead of turning the light ON

I ran a few more tests, it looks like when I say "turn the island light on" and "turn the island light off" the value in brightness is the current brightness setting, not the target. Only binary matters.

I don't have a Color device to test hue, saturation, brightness with.

But it seems like at least for a dimmer that when it receives a binary true it should send an ON, not set the light level to the brightness setting received.

Thanks,

Doug

steilerDev commented 4 years ago

Based on @grzegorz914 pull request (thank you very much for that one!) I added some adjustments. Please test my latest commit and let me know if this fixes the issue: fc33b50

grzegorz914 commented 4 years ago

Hi, after some test not fixed #43, fixed only #13. With Your code send value 100 or 0/OFF, with my code send ON/100 and 0/OFF always. If U look on my rule in #43 state ON enabled light and set to the latest state of brightness(value 100 is ignored), with Your code the light is enabled with 100% of brightness.

steilerDev commented 4 years ago

Merged PR that should fix the problem.