TheAgentK / tuya-mqtt

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

Home Assistant integration how? #64

Closed lizeidsness closed 3 years ago

lizeidsness commented 3 years ago

I read in Issue #55 about Home Assistant Integration being possible, but I'm not sure if you mean running this instead of the built in MQTT broker? or something else? I think I'm missing some knowledge or understanding.

I have 2 smart bulbs that are geeni, which is based on Tuya like so many of them. I have registered these bulbs as instructed in the TuyaAPI setup pages, and they are retrieved with the tuya-cli wizard. However, I'm not sure how to make the next step of getting this step into Home Assistant. It appears as though by default the Home Assistant MQTT connector for Tuya only works with Tuya App, Smart life and Jinvoo, which do not require the cloud app setup as described. So I'm not sure how this all fits together. I would like to use this project as it implies I might be able to send requests to the bulbs directly.

Thanks

tsightler commented 3 years ago

Unfortunately, using this project requires a basic understanding of MQTT and, to integrate it with Home Assistant, how Home Assistant and MQTT work together. This knowledge is best gained by reading the Home Assistant MQTT documentation. The builtin Tuya component in Home Assistant has nothing to do with MQTT, it's a native component that talks directly to a special Home Assistant API which frontends Tuya Cloud and makes it very easy to control Tuya devices. It generally works reasonably well, but has a few quirks such as very slow state updates and it does require all commands to go through Tuya cloud. There is also a custom Tuya component for Home Assistant available to control Tuya devices locally called localtuya. If you don't have a strong understanding of Home Assistant and MQTT and your use case is specifically with regard to Home Assistant, then the localtuya project may be easier for you to use and I highly recommend it.

This project is simply acts as a bridge between Tuya devices and MQTT. It does not replace anything in Home Assistant, it simply connects to an MQTT broker just like Home Assistant does. That's pretty much all MQTT is a broker which various clients connect to, these clients publish messages to the broker and can also subscribe to topics to receive messages they are interested in from other clients.

If you have configured Home Assistant and the MQTT broker then all you need to do is setup this project to connect to the same broker and configure your device types and, during script startup, it will send automatic MQTT discovery via MQTT that Home Assistant will receive and automatically use to setup the devices.

If you have a device that is not supported "out-of-box" with this script (something other than a simple on/off or dimmable switch/light, or RGBTW light), then you'll need to create a custom template and manually define the device in Home Assistant, but this should not be required for a light.

lizeidsness commented 3 years ago

Great! This helped fill in the big part of this system that was missing for me. I hope my post will help someone else too.

I have this (tuya-mqtt) I think working after a a little tweaking of my devices file. My devices are now discovered by Home Assistant, and I can turn them on/off by issuing commands from HA's MQTT client. However as 'entities' they are showing as 'unavailable', which is a problem. I will continue to poke at it, and see if I can figure that out next.

EDIT: rebooted HA, all is well :-)