Hi,
I’m trying to understand how Local Tuya still works for me, even after my devices changed their IP, and why do we need to configure a host attribute at all.
I have configured my devices (lights and plug) manually with Local Tuya and provided each device’s IP in the host attribute.
After a power failure in my apartment, my devices reconnected to the router and got a different IP than they had. Still, HA showed the devices and I was able to control them.
Looking at the logs, I saw that LocalTuya uses UDP broadcast to identify devices, and I assumed it was able to match the reported device ID with the the device ID I provided in the configuration. I was also able to get the devices to respond after changing the host attribute of each device to a non-valid IP (for example - “…”).
Is LocalTuya indeed able to reconnect to devices even after they change their IP?
Is (1) is true, then why do we need to provide a host attribute?
Given that I provide device_id and device_key for all my devices, is it ok to set an invalid IP in the host attribute and let LocalTuya discover their IP?
You are correct. Localtuya listens to broadcasts from devices (based on device id) and updates incorrect IP addresses automatically. I added it since devices often change IP address due to DHCP, this way the integration recovers automatically. You can basically enter anything and it will eventually recover, once a broadcast message has been received.
The host field exists both due to legacy reasons (before this feature even existed) but also to handle the case where devices are on a different VLAN, so broadcasts aren’t received at all. By keeping the host field up-to-date, you don’t get any failure to connect in the logs which you will get otherwise if the IP is not correct. If you set up via config flow, the stored address is updated to that it persists between restarts of Home Assistant. That does not happen with YAML (you need to update manually), it only works during runtime.
Thanks. That is a very useful feature, especially since I can’t set a static IP for any of my Tuya devices, and my locked-down router doesn’t provide me a way to reserve IP addresses.
I noticed that sometimes after a power failure, HA loads with one of my Tuya devices disabled. Is this because the device did not respond in time to the broadcast? Is it only checked when HA loads?
Good to know. I’m actually waiting for my ISP to upgrade my connection, which also comes with a new router. Already made sure the new model supports reserving IPs
Disabled as in the same way as when you pick “Disable” in the …-menu next to the integration (and it no longer shows in the integrations list)? That shouldn’t happen and I would suspect a bug in core.
Next time it happens, I’ll check the logs. Thanks.
I’ve set the default log level to warning and LocalTuya logs to debug. Is this enough to troubleshoot such a use case?
Anything specific I should look for, any keyword to search for?
I think you should see it with just warning or so, but debug is fine. There’s likely an error message about failure to connect or so, hard to tell as it depends on the problem.
I have 2 Question. This answered a lot of questions for me, but I have a situation where I’m using a bulb that has some limitations it’s a felt Eletric product. For some reason in their great wisdom they have made their bulbs only work with their app. Yet I can bring it into smart life but I lose some functionality such as scenery and grouping. I followed all the instructions and got them to be brought into local Tuya. I was worried about the IP change but this answered that question. But in my discovery of this when I got the Device found and I went into HA Local Tuya to configure it. Sometimes I would not get all the pins that I needed well ID’s or whatever you wanna call it to reference. I was missing pin 24 and 25 which would make them unusable. So I couldn’t attach it to a reference point. I found a work around by doing this. Going into the smart life app and changing the color, the color temp and Dimming once then on the site the pins showed up. I have put a recommendation in the forum for adding a private Template library or even better a community one . Once you got the Devices configured you can put it in a template to pull from later. That would be a great time saver. But it this got me thinking if this fix the pin number so I could see it to map it. This got me thinking the show up in this process and after your married to Smart life and developer is there a way to get to see the other pins that have the built with sent command in developers Site So I Can posable get the effects Aka imbedded Scenes to work. So I then can link those into my configuration also getting more potential out of the Device. I’m sorry this turned into such a long question. Also on the configuration you can set intervals if they don’t update do you recommend doing that and will that make the broadcast happen faster. And or do you have a number in mind to set it. One last crazy thought I saw you were talking about V Lan is there a way to set up a V LAN or separate network with a route with Any Tuya device So if a hacker can hacks the Device they don’t get access to my full network. I originally had two networks at my house one for any device like these plus my ring cameras to prevent that. But when I realized I need local Tuya I just bought them in on my network. I look forward to your answer and thank you in advance.
I wanna give an update I actually figured it out to speed up the process I installed the DNSMASQ doing my DHCP and my DNS I will say this corrected the problem 100% for a lot of issues not just Tuya products as we all venture down this way through smart home technology. I think going forward a lot of people should look into doing DNSMASQ also note a lot of routers do not support reserving IP addresses over either 16 or 32 which can be done the same way like I’ve done but if you have so many devices you’re out of luck so learn from my experience the dnsmasq you can do it with no problem only issue I have is I could not use the one that installs in home assistant I had to install it on my qnap because they have a different configuration I will give an example below. Unfortunately the hacks addon for dnsmasq I could not get to work that is why I have to move this to the qnap now I’m going to reach out to the man that set that one up and see if we can fix it
what this does is increases the speed so when you do turn on a two week device it gets the IP address almost immediately and truly speeds up the search process highly highly recommend doing this this was a game changer and I spent a lot of time figuring it out plus you can assign an IP address to all your devices in your house so they don’t change and home assistant has a much easier way of controlling them. You won’t regret adding this let’s see if we can get the add-on to work so it’s all in one box just to see you please let me know what you think.
interface=enp3s0
bogus-priv
expand-hosts
domain=dt.net
dhcp-option=option:router,192.168.1.1
dhcp-option=option:ntp-server,132.163.96.5
dhcp-option=option:dns-server,192.168.1.8
dhcp-option=option:netmask,255.255.255.0
local=/dt.net/
Hello, is there a way to connect in Local Tuya a device which is not in a LAN? With external IP or DDNS? I know that I have tried this for shelly, and it worked… but not sure it this can be done here. If yes, probably port fwding, but on what port? Thank you.