normen / homebridge-433-arduino

A homebridge plugin to control 433MHz switches using an Arduino as transceiver
25 stars 11 forks source link

Support for dimmers #19

Open ahorvat opened 4 years ago

ahorvat commented 4 years ago

I might me missing something, but I do not see any support for dimmers. This should be possible using the ESPiLight protocol, but I am unsure how to add them in the configuration.

normen commented 4 years ago

Theres no support for dimmers, no. I don't have any so I couldn't really test it either. If you can gather the necessary info (what does the lamp put out etc.) I can look into it, a PR is even more welcome :)

ahorvat commented 4 years ago

Hi @normen, I intended to follow up here some time ago, but unfortunately the virus forced me towards other priorities.

In the meantime I have spent some time looking into this and have worked out a prototype for this feature. Dimming is supported natively by piLight and by your inclusion of the library no changes are needed in the ESP/Arduino code. According to the HAP specification "Brightness" is supported on 3 device types: Doorbell, Lightbulb, and Television. Because I'm mainly interested in lighting, I've only implemented Lightbulb, so far. It's fairly straightforward, the JSON message needs to contain a K/V pair containing "dimlevel" instead of the "on" pair present in switches. Additionally HAP.js seems to split the Brightness event into two events, a "brightness" event and an "on" event. So some state logic is needed for these older devices to avoid cyclic dimming when receiving an "on" event when in the "on" state (a hardware feature).

The code I've written successfully commands devices I have available, however there an issue which I haven't been able to resolve yet. After send a command to the new ArduinoDimmerAccessory type, the Home app will show the device reporting "No Response", even though the command has been successfully sent to the RF slave. I can't quite work out why this is happening.

Would you be willing to take a look? You can find my fork here. For reference there's an example of using the Brightness characteristic on the HAP NodeJS repo here.

Looking forward to hearing if you can spot what I'm missing.

normen commented 4 years ago

Cool, nice work.

Given the behavior my first guess would be that the callback isn't executed at some point. Even if the device doesn't really execute the command the callback should return, giving the value that is actually set. From a quick look maybe its in the corner where you intercept the dim and on commands, looks like some paths there don't execute cb().

I'll have another look when I have more time, maybe you find something based on this info.

Cheers, Normen

On Fri Sep 4, 2020 at 1:35 AM CEST, Aleksej Horvat wrote:

Hi @normen, I intended to follow up here some time ago, but unfortunately the virus forced me towards other priorities.

In the meantime I have spent some time looking into this and have worked out a prototype for this feature. Dimming is supported natively by piLight and by your inclusion of the library no changes are needed in the ESP/Arduino code. According to the HAP specification "Brightness" is supported on 3 device types: Doorbell, Lightbulb, and Television. Because I'm mainly interested in lighting, I've only implemented Lightbulb, so far. It's fairly straightforward, the JSON message needs to contain a K/V pair containing "dimlevel" instead of the "on" pair present in switches. Additionally HAP.js seems to split the Brightness event into two events, a "brightness" event and an "on" event. So some state logic is needed for these older devices to avoid cyclic dimming when receiving an "on" event when in the "on" state (a hardware feature).

The code I've written successfully commands devices I have available, however there an issue which I haven't been able to resolve yet. After send a command to the new ArduinoDimmerAccessory type, the Home app will show the device reporting "No Response", even though the command has been successfully sent to the RF slave. I can't quite work out why this is happening.

Would you be willing to take a look? You can find my fork here. For reference there's an example of using the Brightness characteristic on the HAP NodeJS repo here.

Looking forward to hearing if you can spot what I'm missing.

-- You are receiving this because you were mentioned. Reply to this email directly or view it on GitHub: https://github.com/normen/homebridge-433-arduino/issues/19#issuecomment-686816604

ahorvat commented 4 years ago

looks like some paths there don't execute cb()

You are absolutely right, well spotted. I haven't worked with javascript in over 15 years, still need to get my head around callbacks and async. Moving cb() outside the conditional eliminates the behaviour.

I'll cleanup a few things, update the docs / config.schema and issue a PR.