mnordseth / enet-homeassistant

Enet Smart Home integration for Home Assistant
Apache License 2.0
26 stars 7 forks source link

Gira eNet lights not setting accurate brightness level from Homey #13

Closed JOR200 closed 1 year ago

JOR200 commented 1 year ago

Thanks for a very good integration for Gira eNet Server in HA. I primary use HA as a gateway between eNet Server and Homey and have a small isue as follows: The brightness level for eNet lights are not set accurate in HA when controlled from Homey. This vary a bit, but seem to be 0%, 1% or 2% off in the whole range of the scale. Settng 1% in Homey will set to 0% (Off) in HA. HA and eNet server seem to agree on the level. This may be a HACS issue. All my other lights (wich are not HACS integrations) are have matching levels in HA and Homey. Only my eNet lights brighness level differs slightly in HA and Homey.

mnordseth commented 1 year ago

Hi, I am not able to test this use case as I do not use or have Homey.

I do not think it is related HACS as that is purely a way of installing integrations. The enet integration implement the Light interface in Home Assistant, and should behave similar to Philips Hue and other integrations.

Can you provide some debug output from the enet plugin with desciption of what you do from homey and expected results?

JOR200 commented 1 year ago

Thanks for responding to this issue. I just added IKEA Trådfri bridge integration (not HACS) to HA and the brightness levels matches exactly in Homey, HA and IKEA mobile app. I'm not sure how to get the debug output from enet plugin but here's som info from HA: image

Levels in HA and eNet server matches exactly, but they do not match exactly in Homey. Here's some value examples for an eNet light:

Homey HA / eNet server 100 100 99 97 80 80 70 69 60 60 50 49 15 14 1 0

The one thing I can think of is the way values are converted between a scale of 0-100% and 0-255. Is this done differently with HACS integrations than ordinary integrations?

The screenshot shows 100% brightness values for light.benk_vaskerom (IKEA) as 254 and 100% brightness value for light.hjornelampe (eNet) as 255.

JOR200 commented 1 year ago

My table for brighness level did not show correctly... First column is for Homey, the second is for HA/eNet server.

mnordseth commented 1 year ago

Hi, I believe this is a precision issue. Home Assistant operates with a 8 bit value for brightness, ie 0-255. Enet operates with integers of 0-100. From your example it seems like Homey operates with 0-100 as well.

So what I think happens is that Homey sets the value to 99. That number is coverted to the value 252 in Home Assistant (99/100)255), which is converted to the value 98 (252/255100) and sent to the Enet Server. When Home assistant reads that back, it is converted to the value 249 (98/255100), which by Homey will be read as 97 (249/255100).

JOR200 commented 1 year ago

Hi. Yes, I agree. The presicion is not very important except for the differnce between 0% and 1%. My eNet lights are set to turn on with 1% brightness in the eNet server. They are emidiatly turned of again because Homey believes they are set to 0% (Off). I only see this behaviour for my eNet lights. All other lights does not seem to have this precision issue. That's why I wondered if this was an issue with HACS. How can I set the lights to 1%? (1/100)255=2.55? If I set the lights to 2% in Homey, HA and eNet server says they are at 1% and they stay on. This is not the case for other lights wich don't use HACS.

Just trying to figure out if this is a bug and where it can be addressed. And why only an issue with the eNet lights? I do not have other lights with HACS integration.

JOR200 commented 1 year ago

Hi, again. I really think this is a presicion issue too, and I think I know how to fix it quite easily.

When brightness level is written to the eNet server, a fixed value of 0.49% should be added to the value you already have. This will round the values upwards to nearest percentage instead of downwards except for a byte value of zero. 0 will give 0.49% (0,0049) on the eNet server witch will be rounded downwards to 0. The same goes for a byte value of FF (255) witch will give a value of 100.49% on the eNet server. This value should be rounded downwards to 100%. Now, when you read back the values from eNet server, you should pretty much get a match with the value that was originally written. I am pretty sure this will solve my isuue since a byte value of 0 will be the only value that will set eNet server to 0%.

Do you agree with me?

JOR200 commented 1 year ago

Why only add 0.49 to the write value and not 0.5? Because 0.5 will also round the persentage value of zero up to 1% and the persentage value of 100 will be rounded upwards to 101. You do not wan't that.

mnordseth commented 1 year ago

Agree. I updated it to math.ceil(float(brightness) / 255 * 100) which I believe should resolve it. I have released a new version which should be available in HACS soon.

JOR200 commented 1 year ago

This should do it. I'm pretty sure this will also handle the exact values for 0% and 100% correctly. Looking forward to test the new verison. Thanks a lot...

JOR200 commented 1 year ago

Hi. I've testet the new version. When controlled from Homey, everything matches up. Values in Homey, HA and eNet server matches perfectly. I now can set the brightness to any given level. But, there is a but... Looks like HA does not respond very well anymore to the levels when set in eNet mobile app. Also eNet server values seem to be set slightly off when set directly in HA. Do you think similar modifications are needed when reading values from eNet server?

mnordseth commented 1 year ago

I am unable to reproduce that. For me the values match up between the enet app and home assistant (both directions).

On Wed, Mar 29, 2023, 18:25 JOR200 @.***> wrote:

Hi. I've testet the new version. When controlled from Homey, everything matches up. Values in Homey, HA and eNet server matches perfectly. I now can set the brightness to any given level. But, there is a but... Looks like HA does not respond very well anymore to the levels when set in eNet mobile app. Also eNet server values seem to be set slightly off when set directly in HA. Do you think similar modifications are needed when reading values from eNet server?

— Reply to this email directly, view it on GitHub https://github.com/mnordseth/enet-homeassistant/issues/13#issuecomment-1488920816, or unsubscribe https://github.com/notifications/unsubscribe-auth/AARX6LB5X7LYFLD2Z3YH2G3W6RO6JANCNFSM6AAAAAAWGUF2WU . You are receiving this because you commented.Message ID: @.***>

JOR200 commented 1 year ago

I'm glad you did not reproduce the behavior. I was affraid this fix had broken functionality for other users. Strange thing. Never the less, I did a another reatart of HA and tested again. Now all values match up in all directions. eNet server, Homey and HA show the same. I don't know why the reading of eNet server values did not work properly after installing the update and restart HA, but now it does.

I will do some more testing, but expect this to work perfectly.

Thanks a lot...

JOR200 commented 1 year ago

Everything seems to work as desired. I'm closing the issue. Thanks again.

JOR200 commented 1 year ago

Hi. I have reopened this issue as I still have an issue. I have set the turn on brightness in eNet server to 1%. When lights are turned on from eNet mobile app or wall switch the lights are set to 1% brughness as expected. A second or so after that, HA turns the lights off again.

I have the same behaviour with or without Homey.

Maybe the value read from eNet server schould be rounded upwards in the same way as for writing?

mnordseth commented 1 year ago

Hi, I am unable to reproduce this. In my setup the values set from the enet mobile app are reflected perfectly in Home Assistant.

You say HA turn the lights off. Is that just the representation in HA or does the actual light turn off. If the latter is the case, how do you know HA is controlling it? What is the logbook output when you do this?

JOR200 commented 1 year ago

Hi. This is what Logbook says: image

I took it for granted that HA did this, but when I turn off my HA server I still have this behaviour. It must be a bug in eNet server itselves.

Here's how I configured most of my lights in eNet server: image image

Can you try to set up like this and just turn the lights on with a wall switch? Do you see the same behaviour?

I have eNet server version 2.4.0.

JOR200 commented 1 year ago

By setting Switch-on brightness to 1% or 2%, the lights will just turn off again. 3% and above will keep the lights on.

nestorix1343 commented 1 year ago

Just my two cents: When just looking at my Jung eNet setup, some lights will not light up if the minimum settings is below 5%. Some other LED lights light up from 3%. Some LED lights light up randomly when turning on at such a low percentage, so I set the minimum based on a test what the minimum is.

It appears to be dependent on the make and brand of the LED lights.

I tried several settings like the phase settings but that did not seem to help.

JOR200 commented 1 year ago

Yeah. The minimum set to 1% works for me for dim level. My lights are mostly old fashion ones (not LED). It's the Switch-on level below 3% that has issues and just turn the lights off again. This got nothing to do with the eNet server integration for HA.

Thanks for verifying.

JOR200 commented 1 year ago

I closed the issue.... Again.

mnordseth commented 1 year ago

I think the enet actuators are "smart" in the sense that if the load is too low, they turn off. I have seen this behaviour on some bulbs.