kpsuperplane / homebridge-wiz-lan

Control Wiz lights over LAN
Apache License 2.0
116 stars 37 forks source link

Can we fix the dimming.ts file? #114

Closed MoTechnicalities closed 2 years ago

MoTechnicalities commented 2 years ago

RE Code Line 45:

// for some reason < 10% is invalid, so we gotta fit 0% <-> 100% it into 10% <-> 100% // 0%, 1% -> 10% since that's the minimum acceptable value

Notice:

"Brightness" refers to HomeKit settings [0 ... 100]. "Dimming" refers to WiZ bulb internal settings [10 ... 100].

I now understand the problem with the Code but I am unable to do the needed fix. Can someone help fix it please?

If HomeKit brightness slider level is dropped to 0 then the plugin should turn the bulb OFF by setting "state":false,"dimming":100. Note that HomeKit brightness = 0 is accomplished by using the Home App brightness slider in the tile settings, or by a direct command to Siri to set brightness to zero, which is interpreted as to turn the light OFF. However, when the bulb is turned off this way the bulb state and dimming are not currently set correctly.

Dimming should be set back to 100 and state set to false under the above conditions (when Brightness is set to 0) so that when the bulb's state is set back to true (ON) by the press of a tile then the bulb will illuminate properly at 100. Such an arrangement corresponds to what I have seen with Lutron Caseta dimmer switch settings.

Only if the HomeKit brightness is set grater than 0 and in the range 1 to 100 should we normalize with the bulb's dimming: 10 to 100 setting. Then if a command is given or tile clicked to turn the bulb OFF and then back ON, the bulb will return to previous set dimming levels.

Also, the SceneID should always be set to zero unless specifically using the plugin with WiZ scenes turned ON.