New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Home Assistant integration #55
Comments
Tuya mqtt (v3) is integrated with home-assistant through the mqtt integration and discovery feature. If tuya-mqtt is configured correctly for your devices AND home-assistant mqtt integration works, they will appear in home-assistant. |
I see, but unfortunately in my case this does not happen. It looks like separately all the pieces work fine, not together though. |
I have no idea what "Smart IR" device is, but tuya-mqtt can still support it as a generic device but it's going to be totally on you to figure out what DPS values map to what functions and how to control them and either drive them directly or create a template for it. If you create a template you can then manually configure Home Assistant to access those devices assuming they are supported devices by the Home Assistant MQTT integration. |
This device is Tuya compatible WiFi IR remote control, able to learn and transmit IR commands allowing to control various appliances.
|
No, it's not possible to make a generic device discoverable because tuya-mqtt has no idea about the device. There are literally dozens if not hundreds of different Tuya devices that all behave differently, using different DPS values for various commands but, for discovery, tuya-mqtt must understand enough about a device to know exactly how to configure it for Home Assistant. However, if you can figure out how the device works, what the various DPS values do and how they work, then you can create a template and manually configure Home Assistant (assuming there is some MQTT integration on the Home Assistant side that is usable for the functions you want to do). The tuya-mqtt GenericDevice (also the default device) exposes all Tuya DPS values via MQTT. If you use a tool like MQTT Explorer to connect the the MQTT broker you can manipulate your device with the Tuya app and you will see the various DPS values changing. If you can figure out what the different values mean, then you can make a template, but figuring out the different values and what they do is the first step to using any generic Tuya device. For example, in your logs above you can see that the device is sending "send_ir" string value via DPS 1. I have no idea what this means, but it's something, however, I'm sure that device uses many DPS values so you'll need to figure out what these functions are, at least for the functions that you want to use for your integration. |
Thank you very much for your support. Here are a few observations:
|
As tuya-mqtt is based on TuyApi, I think the points 1 to 3 are all related to one problem which is documented here: https://github.com/codetheweb/tuyapi#-notes Only one TCP connection can be in use with a device at once. If using this, do not have the app on your phone open. This seems to be a restriction from Tuya in generell... I only used the app to add all my devices. After I got all my device keys, I closed the app and never opened it again... Instead I am using the Home Automation to control the devices... Regarding point 4. - I think there is already an open issue on TuyApi: |
It's true that Tuya app will block connection of tuya-mqtt since most devices only accept a single connection. However, for most devices you can usually close and kill the Tuya app and, in a few minutes, the device will clear the local connection and except a new connection from tuya-mqtt, reboot should not normally be requied. If you leave the Tuya app running in the background on your device, then only a reboot would allow a connection. This behavior is largely the same for all Tuya devices when attempting local control, most of them only allow one connection, although I do have at least one newer device that seems to not experience this issue. However, if you connect with tuya-mqtt first, the app will still work with cloud connection. Unfortunately, if TuyAPI is only returning a single DPS value then I doubt there is much tuya-mqtt can do with it. It's possible they use some other layered protocol for the control data, rather than DPS values. It sounds like the best option for this device is to flash it with Tasmota, based on the thread the @Flip76 linked to. I am wondering if the device works similar to the Zigbee gateway, where each device is really a "virtual device" with it's own key and id, but using the same gwid. Unfortunately TuyAPI doesn't have support for this right now, and I don't have such a device or the time to work on it. |
My humble opinion suggests this device does not behave as a gateway. After Smart IR is linked in tuya app it allows creation of multiple IR remote controls, each able to control a dedicated appliance. These appliances appear in the app as separate [virtual] devices, but I think it is an abstraction existing only in the app. Each time a user taps a button on any virtual remote control tuya cloud should in theory send a message to the device containing payload to be transmitted by IR emitter. It is hard to imagine that data on hundreds of appliances would be stored on the physical device itself. |
It's not that hard for me to believe that data on hundreds of devices are stored in the device since any universal remote purchased at a big box store has such (I own a simple dumb remote that has 1000's of codes in it). We've seen for sure in the TuyAPI thread that data sent to the device use they're own virtual device ID directed to the same gateway ID, which is exactly how the Zigbee hub works as well, but indeed, without having such a device it is impossible for me to guess any further and you could just as well be right (I just assume Tuya would not develop an entirely different protocol just for this device). However, I certainly don't have any idea how it works, and I don't have one. If it has no ability to local control via the app (easiest thing to do is just block the device running the app from accessing the internet and see if it can control it locally) then it may simply not be possible to control it with TuyAPI and thus tuya-mqtt. Looks like the devices are cheap so perhaps I'll acquire one to play with, but I don't have an abundance of time right now so it probably won't be soon. If you do block the device running the Tuya app from the internet and force it to fail over to local control and it works, that would be telling. |
I conducted 2 experiments. In the first one both the app and the device were isolated from the internet, but were in the same local network. The app loads device list but for loading remote control layout for specific appliance it requires an internet connection. As you've guessed this setup worked, it looks like the app is able to directly communicate with the device. I have not taken any network traffic captures as I'm not an expert. |
I'm going to close this for now as I don't really see how it will be able to support this without valid packet captures of local data and I don't have a device. If someone has one of these devices and is willing to do this leg work we can revisit, but for now I just consider these devices unsupported. |
Is it possible to integrate tuya-mqtt with Home Assistant?
The text was updated successfully, but these errors were encountered: