jasonacox / tinytuya

Python API for Tuya WiFi smart devices using a direct local area network (LAN) connection or the cloud (TuyaCloud API).
MIT License
867 stars 157 forks source link

Problem with tuya door (domo-23) device #469

Closed joluinfante closed 4 months ago

joluinfante commented 4 months ago

Hello. I bought a tuya device (domo-23) that allows you to detect the opening and closing of doors. I have it configured so that, connected to the tuya cloud, it detects openings and closings. But, it does so extremely slowly. It seems that the equipment "falls asleep", and, when it changes state, it takes an IP from the network (via dhcp I suppose), connects to the internet and sends the event. And this is done in a very long time. So, the most logical thing is that I integrate it into my home assistant. The problem is that, as it periodically goes to sleep, and I don't know if it's always the same ipé (the mesh router sort of gets confused that it's alive for a while and then goes to sleep). I need, then, to obtain the ipe, and know exactly which dsp I have to control to detect the status. What is the most appropriate way to do this?

jasonacox commented 4 months ago

Battery powered Tuya devices typically work this way to save battery life. They only connect to the WiFi when a state changes and update the cloud. I have heard of some who set up a do-nothing smart plug and build a SmartLife or Alexa trigger that when the door is detected as open, the plug switches on. When the door closes, the plug switches off. By doing that, you can use Home Assistant or your own scripts to monitor the plug state as the state of the door.

joluinfante commented 4 months ago

I understood the concept. Now, my question is: the device has wiring within its firmware that, upon a change of state, takes an IP from the network, and sends a message to the tuya cloud. The problem I have is that I have too many IoT devices, and this transmission time is excessively high. The idea I had was (to avoid wiring) is to place this device on the bathroom door, and, when the door is closed, it sends a message to the cloud, the cloud sends a signal to a switch, to which I have connected the bathroom extractor fan. And, when I open the door, the opposite effect would occur. What happens is that this set of actions is not done in a reasonable time. Therefore, I thought of isolating these devices and managing them in ha, locally. But, I get the impression that I won't be able to stop that message that the device sends to your cloud from happening. The ideal would be to modify that destination host address, and put something on it that is listening locally on my network. I explain? Maybe this is not a topic I can raise in this forum (and I don't think your people care, since their business is selling their IoT model in the cloud, which, particularly, for everything I explain, in unfeasible for someone in Argentina), but, perhaps, other people have this problem. I'll give you another example: I also have the alarm compatible with smartlife. And that alarm acts as a "host" for the alarm sensors (like the one I am using, but for the entrance door), and it works perfectly, because it solves the problem locally (the sensor reports to the alarm console). Well, sorry for the length. Yes, I would like to know other opinions about it (because if not, it's like I bought this device and I won't be able to use it).

joluinfante commented 4 months ago

A clarification. Where it says "and I don't think your people care" corresponds "I don't think Tuya cares." It happens that Google Translator understands "Tuya" as a word in Spanish.

uzlonewolf commented 4 months ago

The problem is the device may wait a significant amount of time before connecting to the WiFi to transmit the open/close event(s). There is nothing you can do about this, they do it to save battery power as otherwise the batteries would only last a couple days.

If you must use a battery powered switch then I recommend looking into the Zigbee ones. These transmit immediately as Zigbee uses a fraction of the power of WiFi and the wired hub they connect to can be monitored for events.

joluinfante commented 4 months ago

I understand the point. Now, I have smartlife (tuya), ewelink and broadlink devices. To use Zigbee brand devices, I also need to include a Zigbee hub to integrate into smartlife, right? Could you tell me models of both types of equipment? Anyway, I intend, in the future, not to depend on the Internet for all these devices, and to manage them locally with HA. I have friends in the US who, many years ago, built their entire smart home with devices from one brand, then, suddenly the brand disappeared, and they had to unwire everything, to use the mechanical keys again to turn on lights, etc.

uzlonewolf commented 4 months ago

Yes, Zigbee devices need a hub. The good thing about Zigbee is it's an open protocol that has quite a few different manufacturers making devices and hubs so you don't have to worry about them disappearing. I've used several different Tuya-compatible hubs from MOES and Lidl and they all seem to work fine. Just search for "Tuya Zigbee door sensor" and "Tuya Zigbee hub". If you're going to be using HA then a Zigbee USB stick such as the "SONOFF Zigbee 3.0 USB Dongle Plus" would also work and seems to be preferred by the HA community.

joluinfante commented 4 months ago

Thank you all for the explanation and help. I think we can close this thread now. If I can contribute something later, from the experience I gain later, I will do so. Greetings!