Giter VIP home page Giter VIP logo

Comments (12)

Trauma avatar Trauma commented on May 24, 2024

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.

from tuya-mqtt.

too-far-away avatar too-far-away commented on May 24, 2024

I see, but unfortunately in my case this does not happen. It looks like separately all the pieces work fine, not together though.
tuya-mqtt seems to connect to the HA MQTT broker and also to the device. Other devices (e.g. tasmota flashed sonoff switch) can be automatically discovered by HA.
My device type is smart IR. Could the reason be that such a device is not supported and therefore the discovery does not work? Should I post tyua-mqtt log here?

from tuya-mqtt.

tsightler avatar tsightler commented on May 24, 2024

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.

from tuya-mqtt.

too-far-away avatar too-far-away commented on May 24, 2024

This device is Tuya compatible WiFi IR remote control, able to learn and transmit IR commands allowing to control various appliances.
If in devices.conf I set its type to SmartSwitch it is successfully discovered by HA and appears where all the switches are.
Is it possible to make a generic device discoverable? Should a template be created for this purpose?
Below is the output when there is no type configured:

tuya-mqtt:info Connection established to MQTT server +0ms
tuya-mqtt:tuyapi Search for device id --------b5 +0ms
tuya-mqtt:tuyapi Found device id --------b5 +832ms
tuya-mqtt:tuyapi Received JSON data from device --------b5 -> {"1":"send_ir"} +26ms
tuya-mqtt:tuyapi Connected to device Smart IR (--------b5, ----------) +987ms
tuya-mqtt:tuyapi Received JSON data from device --------b5 -> {"1":"send_ir"} +112ms
tuya-mqtt:state MQTT DPS JSON: tuya/smart_ir/dps/state ->  {"1":"send_ir"} +0ms
tuya-mqtt:state MQTT DPS1: tuya/smart_ir/dps/1/state ->  send_ir +2ms

from tuya-mqtt.

tsightler avatar tsightler commented on May 24, 2024

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.

from tuya-mqtt.

too-far-away avatar too-far-away commented on May 24, 2024

Thank you very much for your support. Here are a few observations:

  1. If tuya app is connected to the device tuya-mqtt can not connect to it. I read somewhere that there can be only one connection to the device...
  2. In order for tuya-mqtt to connect to the device it has to be "rebooted" (powered off and then on).
  3. Once tuya-mqtt is connected to the device and I try to control it with the SmartLife app the log shows no more then 2 actions (sometimes just 1). All these actions are the same "send_ir" command.
  4. In mqtt explorer (and also in tuya-mqtt log) there is no indication of "send_ir" payload. I would expect it to have some, because the device basically acts as IR remote control and has to receive data to actually transmit it to an appliance, e.g. TV.

from tuya-mqtt.

Flip76 avatar Flip76 commented on May 24, 2024

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:

codetheweb/tuyapi#134

from tuya-mqtt.

tsightler avatar tsightler commented on May 24, 2024

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.

from tuya-mqtt.

too-far-away avatar too-far-away commented on May 24, 2024

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.
Unfortunately, flashing tasmota on this specific device (although apparently possible) requires breaking the case as it looks sealed and then likely some soldering. TuyaConvert does not work on it. So I was hoping to avoid this, but it looks like there is no cleaner solution to the problem...

from tuya-mqtt.

tsightler avatar tsightler commented on May 24, 2024

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.

from tuya-mqtt.

too-far-away avatar too-far-away commented on May 24, 2024

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.
In the second setup I put the app and the device in separate networks so that the app (as far as my understanding goes) can not directly contact the device because the latter is behind a router. This setup also works.
So it looks like while there is some kind of fallback built-in to the app, the main operation mode assumes that both have access to tuya cloud. Or at least I assume so...

from tuya-mqtt.

tsightler avatar tsightler commented on May 24, 2024

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.

from tuya-mqtt.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.