smarthomej / addons

SmartHome/J addons for openHAB
Eclipse Public License 2.0
59 stars 23 forks source link

Q: If tuyaDevice is OFFLINE should switch item appear to turn ON or raise an error? #373

Closed owl770 closed 2 years ago

owl770 commented 2 years ago

Hi. I am using version 3.2.12 of the SmartHome/J Tuya Binding and have a question about the relationship between a tuyaDevice THING and its linked switch ITEM. As far as I can tell, with a tuya smart switch there is normally a 1-to-1 relationship between the tuyaDevice THING and the switch ITEM but I know this is not always the case.

If the tuyaDevice THING is not ONLINE (so OFFLINE or UNINITIALIZED) you can still turn the switch ITEM ON and OFF - no error is raised (that I can see). Is this intentional? You can think you have turned the switch ON but because the underlying THING is not ONLINE, the switch is actually OFF. Hope that makes sense.

It would be good if there was an error of some kind so that the situation could be detected and handled in some way. I am using Rules DSL and from what I can see it is not possible to go from the ITEM UID to the THING UID to determine if the THING is ONLINE or not (no access to the ItemChannelLinkRegistry in Rules DSL).

J-N-K commented 2 years ago

Did you try setting the "autoUpdate=false" on the item? Then the item state should only change after a response from the device was received. But you are correct, a device that is not ONLINE should not accept a command either.

It's not possible to return a "failed" state if the device is not connected. The best we can do is log a warning.

owl770 commented 2 years ago

Not sure of the implications of this suggestion but could you set the item state to NULL or UNDEFINED if the associated thing is offline (or can it only be ON or OFF)?