TheAgentK / tuya-mqtt

Nodejs-Script to combine tuyaapi and openhab via mqtt
MIT License
173 stars 80 forks source link

Wait for Firmeware v2.0 compatibility #18

Closed TheAgentK closed 3 years ago

TheAgentK commented 5 years ago

See Issue codetheweb/tuyapi#175

tsightler commented 5 years ago

@TheAgentK I have coded up an attempt to implement support for 3.3 protocol using the tuyapi 5.1.1 code released a few days ago. There was a challenge in that, to use the 3.3 protocol when not leveraging auto discovery, the API requires explicitly specifying the protocol version. I wasn't really sure how to do that without changing the topic structure.

Instead, I decided to hack in device discovery support, which required minimal changes and I think is useful anyway since it allows you to specify only two items (id and key) so even if IP changes via DHCP the topics will stay consistent. To do this with minimum changes I modified the code to accept "discover" in place of the IP address. I suppose it would also be possible to use something like 0.0.0.0 or 255.255.255.255, but I wanted it to be really clear what the setting meant.

https://github.com/tsightler/tuya-mqtt

If you have other thoughts on how to implement with explicit IP I'm happy to take a stab at it. I've actually been wanting to add support for Home Assistant style MQTT discovery but to do that ideally you want to be able to provide device names so I'm thinking perhaps the best option might be a devices.json file with ID/key/IP/protocol_ver/device_name, so that might be an option, however, I wasn't sure if you were interested in such patches. I'm happy to fork a Home Assistant specific branch if not.

rudders commented 5 years ago

I just gave your fork a try @tsightler and now have mqtt access to a couple of new Tuya based generic switches I purchased. Great solution until tuya-convert works with the new firmware. ESPHome would be the ideal solution but until then I might try and build a hassio add-on for it for my Home Assistant environment.

tsightler commented 5 years ago

Thanks for giving it a spin @rudders. It should be easy enough to make it a hassio addon. Based on what @TheAgentK wants to do I'll consider forking a hassio version and maintaining it if I go forward with the HA discovery support.

tsightler commented 5 years ago

BTW, I also have one more minor update that I'll push in the next day or two that provides a method of specifying the protocol version explicitly for those that do want to continue to use a specific IP. To keep the changes to a minimum I'm simply overloading the old "socket/lightbulb" topic level that is no loger used/required in the newer code base. This allows to reuse this field to specify the protocol version instead. This way it will have zero impact on existing users and be super easy for future users that don't want to or otherwise can't leverage device discovery.

rudders commented 5 years ago

I was a bit optimistic about my available time but will have a crack at some time and pull in your latest - i think this is a great solution for local tuya control for HA but I don't have the coding skills to do it properly I fear. Nice work BTW!

tsightler commented 3 years ago

Released 2.1.0 which has 3.3 support.