0x5e / homebridge-tuya-platform

Make homebridge-tuya-platform great again.
MIT License
216 stars 67 forks source link

Add support for devices supporting only a single state change at any time #205

Open 2bsc opened 1 year ago

2bsc commented 1 year ago

Hi there, first of all: thanks a lot for taking matters into your own hands with the formerly broken Tuya plugin!

My feature request arises from a characteristic that I notices some months back, using another plugin at that time. My fan at home (Windcalm DC) seems to refuse two instructions at the same time. Using the HomeKit-slider to change fan speeds, it seems to command ON and RotationSpeed (or OFF and minSpeed when all the way down.) This makes sense to be able to control both states at the time, but my fan doesn't like that at all. I validated this behavior using Tuya's "Device Debugging" page, where one can use JSON-Editing. Only sending one single command yielded a change in state, arrays didn't go through.

In the old plugin I was able to suppress sending multiple instructions at the time (altering SimpleFan.json or whatever it was called), but unfortunately I'm not that far into JavaScript to succeed this time around...

Now my request: is there a way to send the bulk commands as multiple single requests (time delayed if necessary) so Apple's slider functionality still works properly?

Alternatively (but less elegant), could it be implemented to only send a single command? Using the HomeKit-slider with my fan, which supports 6 speed-levels, would mean:

When turned off, only commanding a rotation speed still turns the fan on to the correct speed, but the internal status remains OFF, which is the inelegant part ;)

Thanks for your support! Carl

0x5e commented 1 year ago

Everytime when you touch the slider, homekit will trigger the on event. #195 have the similar issue. I will update a version and then you can add a config to skip send on/off command when touching brightness/speed slider. This need to be added manually, so for normal devices their behavior won't get changed.

0x5e commented 1 year ago

Please try beta.22, and according to example here: https://github.com/0x5e/homebridge-tuya-platform/blob/develop_1.7.0/ADVANCED_OPTIONS.md#skip-send-onoff-command-when-touching-brightnessspeed-slider

2bsc commented 1 year ago

Hey there, thanks so much for the quick response, it works! I copied your solution (though simplified) in the fan_speed section to allow using the slider down to 0% to turn it off as well:

My fan, as previously mentioned has 6 steps (1-6), so I added a "fictional" 7th step (-> 0) indicating to the logic to suppress the fan_speed command this time around and let the false signal of fan_switch go through alone.

"schema": [ {
         "oldCode": "fan_speed",
         "code": "fan_speed",
         "onSet": "(value === 0) ? undefined : value",
         "property": {
                  "min": 0,
                  "max": 6,
                  "scale": 1,
                  "step": 1
         }
}, {
         "oldCode": "fan_switch",
         "code": "fan_switch",
         "onSet": "(value === device.status.find(status => status.code === 'fan_switch').value) ? undefined : value"
} ]

The only thing left is, when the fan in turned off and I try to start it using the slider, I need to press twice, but that's ok with me 😏