rospogrigio / localtuya

local handling for Tuya devices
GNU General Public License v3.0
2.7k stars 529 forks source link

localtuya do not try to connect to devices #285

Open Marco-Kl opened 3 years ago

Marco-Kl commented 3 years ago

Hello developer, first of all i would say "thankyou" to you and the developers around home assistant or better around all open source smart home projects. I used open hab 2 since years and was very happy with OH2. I think HA is a little bit better for my requests and i like python and not java. So i am HA noob .

My environment: PFSense Firwall. Server and clients ( mobile phones , pc's an kodi's ) are in 192.168.0.0/24 All ( ip cam's, mqtt devices and the tuya devices are in 192.168.200.0/24 routed via firewall. Dafault Any:Any and every device is block individual if is needed. HA 192.168.0.10

So now my test case: Before i completly switch over to HA i tested some of my self made mqtt projects with HA and for this i worked with a virtual machine running in a VMWare Player ( network bridged ) downloaded as OVA from the HA homepage. I followed the guide to control the devices lacally. Unbelivable how you find out these and spend yout time into this tuya devices. Finally everything works as expected.

My production case: I imported the same OVA into my KVM system on my server, start up the HA and configured the system like my test system. Everything works with this network. MQTT, Addon install, Zoneminder ( also great project ) but the localtuya won't work. I can ping the device form the HA cli. I double checked the config. The port 6668 of the devices are open. I can check this only from an other host in the network because there is not telnet client available on the HA cli. I delete all devices in my app and on the tuya platform and repeate everythink until i have the new api key and device keys ( device ids are still the same [ looks like based UUID + MAC ] ) . Still no success.

Tested with current master and release 3.2.0 Not working Tested with HA 2020.12.1 & 2020.12.2 Not working Testet on RPI4 Not working

logger:
  default: info
  logs:
    custom_components.localtuya: debug

In the debug log i find no entries from locatuya, only the following if i restart the service from the development tools:

2020-12-31 12:14:46 DEBUG (MainThread) [custom_components.localtuya.switch] [453...ae3] Adding switch.dose01 with configuration: {'platform': 'binary_sensor', 'friendly_name': 'P1', 'id': 1, 'device_class': 'power', 'state_on': 'true', 'state_off': 'false'}
2020-12-31 12:14:46 DEBUG (MainThread) [custom_components.localtuya.binary_sensor] [453...ae3] Adding binary_sensor.dose01 with configuration: {'platform': 'binary_sensor', 'friendly_name': 'P1', 'id': 1, 'device_class': 'power', 'state_on': 'true', 'state_off': 'false'}
2020-12-31 12:14:46 DEBUG (MainThread) [custom_components.localtuya.switch] [453...66f] Adding switch.p2 with configuration: {'platform': 'binary_sensor', 'friendly_name': 'P2', 'id': 1, 'device_class': 'power', 'state_on': 'true', 'state_off': 'false'}
2020-12-31 12:14:46 DEBUG (MainThread) [custom_components.localtuya.binary_sensor] [453...66f] Adding binary_sensor.p2 with configuration: {'platform': 'binary_sensor', 'friendly_name': 'P2', 'id': 1, 'device_class': 'power', 'state_on': 'true', 'state_off': 'false'}
2020-12-31 12:14:46 DEBUG (MainThread) [custom_components.localtuya.switch] [506...24d] Adding switch.p3 with configuration: {'platform': 'binary_sensor', 'friendly_name': 'P3', 'id': 1, 'device_class': 'power', 'state_on': 'true', 'state_off': 'false'}
2020-12-31 12:14:46 DEBUG (MainThread) [custom_components.localtuya.binary_sensor] [506...24d] Adding binary_sensor.p3 with configuration: {'platform': 'binary_sensor', 'friendly_name': 'P3', 'id': 1, 'device_class': 'power', 'state_on': 'true', 'state_off': 'false'}

If i try to run set_dp from the development tools with the data from a device :

{ device_id : "453005617003XXXXXXXe3", dp : 1, value : "true" }

i got this:

2020-12-31 12:14:46 INFO (MainThread) [homeassistant.components.switch] Setting up switch.localtuya
2020-12-31 12:14:46 INFO (MainThread) [homeassistant.components.binary_sensor] Setting up binary_sensor.localtuya
2020-12-31 12:18:34 ERROR (MainThread) [homeassistant.components.websocket_api.http.connection] [140502768885040] not connected to device
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 135, in handle_call_service
    await hass.services.async_call(
  File "/usr/src/homeassistant/homeassistant/core.py", line 1445, in async_call
    task.result()
  File "/usr/src/homeassistant/homeassistant/core.py", line 1480, in _execute_service
    await handler.job.target(service_call)
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 663, in admin_handler
    await result
  File "/config/custom_components/localtuya/__init__.py", line 148, in _handle_set_dp
    raise HomeAssistantError("not connected to device")
homeassistant.exceptions.HomeAssistantError: not connected to device

If i start a tcpdump between this devices on the firewall i can see no kind of communication between this HA and the devices and this correcponding to the error message in HA. But i don't no why......

Could this be an issue of my network bridge when everything else is working? Can i do something wrong when i am copying the folder localtuya into the custom_components? I stopped my mobile phone app. If i install the tuya app i can control the devices via cloud ( FW rules disabled ). App removed again... So i have no ideas

Thanks allot for any kind of help. Best regards Marco

System Health

version 2020.12.2
installation_type Home Assistant OS
dev false
hassio true
docker true
virtualenv false
python_version 3.8.6
os_name Linux
os_version 5.4.84
arch x86_64
timezone UTC
Home Assistant Cloud logged_in | false -- | -- can_reach_cert_server | ok can_reach_cloud_auth | ok can_reach_cloud | ok
Hass.io host_os | Home Assistant OS 5.9 -- | -- update_channel | stable supervisor_version | 2020.12.7 docker_version | 19.03.13 disk_total | 30.8 GB disk_used | 2.7 GB healthy | true supported | true board | ova supervisor_api | ok version_api | ok installed_addons | Check Home Assistant configuration (3.6.0), File editor (5.2.0), Mosquitto broker (5.1), Samba share (9.3.0), Terminal & SSH (8.10.0), Log Viewer (0.9.1)
Lovelace dashboards | 1 -- | -- mode | storage views | 1 resources | 0
KTibow commented 3 years ago

Use triple backticks, not just one.

juan11perez commented 3 years ago

I have a similar scenario. I have 1 device in the same subnet as HA and 5 in a different subnets. Witth tuya 3.1 this worked fine. Devices were found all over and worked correctly.

in 3.2 this stopped working. So the device in the same HA subnet appears unavailable on HA restart. I have to manually activate it once to be found. After that it turns on/off (so unless you cant physically access it, it wont appear).

The other devices in the different subnet are not found. I added the 6666 & 6667 ports to the rule that allows access to HA and they still dont show up.

reverting to 3.1 brings it all up.

Marco-Kl commented 3 years ago

Use triple backticks, not just one.

Thanks. It looks better now.

postlund commented 3 years ago

Please try #288.

Marco-Kl commented 3 years ago

Hello and a happy new year!!!

There is no communication between HA and device. For example this is my test system ( 192.168.0.133 ):

    192.168.0.133.36008 > 192.168.200.201.6668: Flags [P.], cksum 0xbec5 (correct), seq 2397441508:2397441563, ack 8333, win 63997, length 55
13:44:59.736703 70:03:9f:4b:5a:e3 > 4c:cc:6a:22:1f:ab, ethertype IPv4 (0x0800), length 60: (tos 0x0, ttl 255, id 153, offset 0, flags [none], proto TCP (6), length 40)
    192.168.200.201.6668 > 192.168.0.133.36008: Flags [.], cksum 0xefd5 (correct), seq 1, ack 55, win 4380, length 0
13:44:59.740119 70:03:9f:4b:5a:e3 > 4c:cc:6a:22:1f:ab, ethertype IPv4 (0x0800), length 82: (tos 0x0, ttl 255, id 154, offset 0, flags [none], proto TCP (6), length 68)
    192.168.200.201.6668 > 192.168.0.133.36008: Flags [P.], cksum 0x9447 (correct), seq 1:29, ack 55, win 4380, length 28
13:44:59.740667 4c:cc:6a:22:1f:ab > 70:03:9f:4b:5a:e3, ethertype IPv4 (0x0800), length 54: (tos 0x0, ttl 63, id 29099, offset 0, flags [DF], proto TCP (6), length 40)
    192.168.0.133.36008 > 192.168.200.201.6668: Flags [.], cksum 0x06d8 (correct), seq 55, ack 29, win 63997, length 0
13:45:02.316942 70:03:9f:4b:5a:e3 > 4c:cc:6a:22:1f:ab, ethertype IPv4 (0x0800), length 161: (tos 0x0, ttl 255, id 155, offset 0, flags [none], proto TCP (6), length 147)
    192.168.200.201.6668 > 192.168.0.133.36008: Flags [P.], cksum 0x7676 (correct), seq 29:136, ack 55, win 4380, length 107
13:45:02.317885 4c:cc:6a:22:1f:ab > 70:03:9f:4b:5a:e3, ethertype IPv4 (0x0800), length 54: (tos 0x0, ttl 63, id 29100, offset 0, flags [DF], proto TCP (6), length 40)
    192.168.0.133.36008 > 192.168.200.201.6668: Flags [.], cksum 0x066d (correct), seq 55, ack 136, win 63997, length 0
13:45:03.234888 70:03:9f:4b:5a:e3 > 4c:cc:6a:22:1f:ab, ethertype IPv4 (0x0800), length 73: (tos 0x0, ttl 255, id 156, offset 0, flags [none], proto UDP (17), length 59)
    192.168.200.201.49153 > 192.168.0.1.53: [udp sum ok] 37495+ A? m2.tuyaeu.com. (31)
13:45:03.272267 70:03:9f:4b:5a:e3 > 4c:cc:6a:22:1f:ab, ethertype IPv4 (0x0800), length 73: (tos 0x0, ttl 255, id 157, offset 0, flags [none], proto UDP (17), length 59)
    192.168.200.201.49153 > 192.168.0.1.53: [udp sum ok] 37495+ A? m2.tuyaeu.com. (31)
13:45:04.255631 70:03:9f:4b:5a:e3 > 4c:cc:6a:22:1f:ab, ethertype IPv4 (0x0800), length 161: (tos 0x0, ttl 255, id 158, offset 0, flags [none], proto TCP (6), length 147)
    192.168.200.201.6668 > 192.168.0.133.36008: Flags [P.], cksum 0xfeaf (correct), seq 136:243, ack 55, win 4380, length 107
13:45:04.256563 4c:cc:6a:22:1f:ab > 70:03:9f:4b:5a:e3, ethertype IPv4 (0x0800), length 54: (tos 0x0, ttl 63, id 29101, offset 0, flags [DF], proto TCP (6), length 40)
    192.168.0.133.36008 > 192.168.200.201.6668: Flags [.], cksum 0x0602 (correct), seq 55, ack 243, win 63997, length 0
13:45:04.272047 70:03:9f:4b:5a:e3 > 4c:cc:6a:22:1f:ab, ethertype IPv4 (0x0800), length 73: (tos 0x0, ttl 255, id 159, offset 0, flags [none], proto UDP (17), length 59)
    192.168.200.201.49153 > 192.168.0.1.53: [udp sum ok] 37495+ A? m2.tuyaeu.com. (31)
13:45:05.705010 70:03:9f:4b:5a:e3 > 4c:cc:6a:22:1f:ab, ethertype IPv4 (0x0800), length 161: (tos 0x0, ttl 255, id 160, offset 0, flags [none], proto TCP (6), length 147)
    192.168.200.201.6668 > 192.168.0.133.36008: Flags [P.], cksum 0xeea9 (correct), seq 243:350, ack 55, win 4380, length 107
13:45:05.705583 4c:cc:6a:22:1f:ab > 70:03:9f:4b:5a:e3, ethertype IPv4 (0x0800), length 54: (tos 0x0, ttl 63, id 29102, offset 0, flags [DF], proto TCP (6), length 40)
    192.168.0.133.36008 > 192.168.200.201.6668: Flags [.], cksum 0x0597 (correct), seq 55, ack 350, win 63997, length 0
13:45:06.322164 70:03:9f:4b:5a:e3 > 4c:cc:6a:22:1f:ab, ethertype IPv4 (0x0800), length 73: (tos 0x0, ttl 255, id 161, offset 0, flags [none], proto UDP (17), length 59)
    192.168.200.201.49153 > 192.168.0.1.53: [udp sum ok] 37495+ A? m2.tuyaeu.com. (31)
13:45:06.879298 70:03:9f:4b:5a:e3 > 4c:cc:6a:22:1f:ab, ethertype IPv4 (0x0800), length 161: (tos 0x0, ttl 255, id 162, offset 0, flags [none], proto TCP (6), length 147)
    192.168.200.201.6668 > 192.168.0.133.36008: Flags [P.], cksum 0x6a85 (correct), seq 350:457, ack 55, win 4380, length 107
13:45:06.879838 4c:cc:6a:22:1f:ab > 70:03:9f:4b:5a:e3, ethertype IPv4 (0x0800), length 54: (tos 0x0, ttl 63, id 29103, offset 0, flags [DF], proto TCP (6), length 40)
    192.168.0.133.36008 > 192.168.200.201.6668: Flags [.], cksum 0x052c (correct), seq 55, ack 457, win 63997, length 0

You can see com. between HA and device ( 192.168.0.133 <--> 192.168.200.201 ) Periodicly DNS requests but they will blocked. everything as i expected.

An now here my com. between the prod system and the device ater reconnecting the device and restart the HA:

13:50:26.640888 4c:cc:6a:22:1f:ab > 70:03:9f:4b:5a:e3, ethertype IPv4 (0x0800), length 342: (tos 0x10, ttl 128, id 0, offset 0, flags [none], proto UDP (17), length 328)
    192.168.200.1.67 > 192.168.200.201.68: [udp sum ok] BOOTP/DHCP, Reply, length 300, xid 0x19a42627, Flags [none] (0x0000)
      Your-IP 192.168.200.201
      Client-Ethernet-Address 70:03:9f:4b:5a:e3
      Vendor-rfc1048 Extensions
        Magic Cookie 0x63825363
        DHCP-Message Option 53, length 1: Offer
        Server-ID Option 54, length 4: 192.168.200.1
        Lease-Time Option 51, length 4: 7200
        Subnet-Mask Option 1, length 4: 255.255.255.0
        Default-Gateway Option 3, length 4: 192.168.200.1
        Domain-Name-Server Option 6, length 4: 192.168.0.1
        Domain-Name Option 15, length 16: "fam-kloepfer.lan"
13:50:26.647577 4c:cc:6a:22:1f:ab > 70:03:9f:4b:5a:e3, ethertype IPv4 (0x0800), length 342: (tos 0x10, ttl 128, id 0, offset 0, flags [none], proto UDP (17), length 328)
    192.168.200.1.67 > 192.168.200.201.68: [udp sum ok] BOOTP/DHCP, Reply, length 300, xid 0xb32259f9, Flags [none] (0x0000)
      Your-IP 192.168.200.201
      Client-Ethernet-Address 70:03:9f:4b:5a:e3
      Vendor-rfc1048 Extensions
        Magic Cookie 0x63825363
        DHCP-Message Option 53, length 1: ACK
        Server-ID Option 54, length 4: 192.168.200.1
        Lease-Time Option 51, length 4: 7200
        Subnet-Mask Option 1, length 4: 255.255.255.0
        Default-Gateway Option 3, length 4: 192.168.200.1
        Domain-Name-Server Option 6, length 4: 192.168.0.1
        Domain-Name Option 15, length 16: "fam-kloepfer.lan"
13:50:28.017506 70:03:9f:4b:5a:e3 > 4c:cc:6a:22:1f:ab, ethertype IPv4 (0x0800), length 73: (tos 0x0, ttl 255, id 2, offset 0, flags [none], proto UDP (17), length 59)
    192.168.200.201.49153 > 192.168.0.1.53: [udp sum ok] 24872+ A? a3.tuyaeu.com. (31)
13:50:28.017932 70:03:9f:4b:5a:e3 > 4c:cc:6a:22:1f:ab, ethertype IPv4 (0x0800), length 73: (tos 0x0, ttl 255, id 3, offset 0, flags [none], proto UDP (17), length 59)
    192.168.200.201.49153 > 192.168.0.1.53: [udp sum ok] 24872+ A? a3.tuyaeu.com. (31)
13:50:28.024383 70:03:9f:4b:5a:e3 > 4c:cc:6a:22:1f:ab, ethertype IPv4 (0x0800), length 73: (tos 0x0, ttl 255, id 4, offset 0, flags [none], proto UDP (17), length 59)
    192.168.200.201.49153 > 192.168.0.1.53: [udp sum ok] 19754+ A? m2.tuyaeu.com. (31)
13:50:29.012869 70:03:9f:4b:5a:e3 > 4c:cc:6a:22:1f:ab, ethertype IPv4 (0x0800), length 73: (tos 0x0, ttl 255, id 5, offset 0, flags [none], proto UDP (17), length 59)
    192.168.200.201.49153 > 192.168.0.1.53: [udp sum ok] 24872+ A? a3.tuyaeu.com. (31)
13:50:29.015280 70:03:9f:4b:5a:e3 > 4c:cc:6a:22:1f:ab, ethertype IPv4 (0x0800), length 73: (tos 0x0, ttl 255, id 6, offset 0, flags [none], proto UDP (17), length 59)
    192.168.200.201.49153 > 192.168.0.1.53: [udp sum ok] 19754+ A? m2.tuyaeu.com. (31)
13:50:30.014500 70:03:9f:4b:5a:e3 > 4c:cc:6a:22:1f:ab, ethertype IPv4 (0x0800), length 73: (tos 0x0, ttl 255, id 7, offset 0, flags [none], proto UDP (17), length 59)
    192.168.200.201.49153 > 192.168.0.1.53: [udp sum ok] 19754+ A? m2.tuyaeu.com. (31)
13:50:30.034838 70:03:9f:4b:5a:e3 > ff:ff:ff:ff:ff:ff, ethertype IPv4 (0x0800), length 230: (tos 0x0, ttl 255, id 8, offset 0, flags [none], proto UDP (17), length 216)
    192.168.200.201.49154 > 255.255.255.255.6667: [udp sum ok] UDP, length 188
13:50:31.012695 70:03:9f:4b:5a:e3 > 4c:cc:6a:22:1f:ab, ethertype IPv4 (0x0800), length 73: (tos 0x0, ttl 255, id 9, offset 0, flags [none], proto UDP (17), length 59)
    192.168.200.201.49153 > 192.168.0.1.53: [udp sum ok] 24872+ A? a3.tuyaeu.com. (31)
13:50:32.012507 70:03:9f:4b:5a:e3 > 4c:cc:6a:22:1f:ab, ethertype IPv4 (0x0800), length 73: (tos 0x0, ttl 255, id 10, offset 0, flags [none], proto UDP (17), length 59)
    192.168.200.201.49153 > 192.168.0.1.53: [udp sum ok] 19754+ A? m2.tuyaeu.com. (31)
13:50:35.029618 70:03:9f:4b:5a:e3 > ff:ff:ff:ff:ff:ff, ethertype IPv4 (0x0800), length 230: (tos 0x0, ttl 255, id 11, offset 0, flags [none], proto UDP (17), length 216)
    192.168.200.201.49154 > 255.255.255.255.6667: [udp sum ok] UDP, length 188
13:50:39.038834 70:03:9f:4b:5a:e3 > 4c:cc:6a:22:1f:ab, ethertype IPv4 (0x0800), length 73: (tos 0x0, ttl 255, id 12, offset 0, flags [none], proto UDP (17), length 59)
    192.168.200.201.49153 > 192.168.0.1.53: [udp sum ok] 19255+ A? a3.tuyaeu.com. (31)
13:50:40.012600 70:03:9f:4b:5a:e3 > 4c:cc:6a:22:1f:ab, ethertype IPv4 (0x0800), length 73: (tos 0x0, ttl 255, id 13, offset 0, flags [none], proto UDP (17), length 59)
    192.168.200.201.49153 > 192.168.0.1.53: [udp sum ok] 19255+ A? a3.tuyaeu.com. (31)
13:50:40.033799 70:03:9f:4b:5a:e3 > ff:ff:ff:ff:ff:ff, ethertype IPv4 (0x0800), length 230: (tos 0x0, ttl 255, id 14, offset 0, flags [none], proto UDP (17), length 216)
    192.168.200.201.49154 > 255.255.255.255.6667: [udp sum ok] UDP, length 188
13:50:40.038602 70:03:9f:4b:5a:e3 > 4c:cc:6a:22:1f:ab, ethertype IPv4 (0x0800), length 73: (tos 0x0, ttl 255, id 15, offset 0, flags [none], proto UDP (17), length 59)
    192.168.200.201.49153 > 192.168.0.1.53: [udp sum ok] 33053+ A? m2.tuyaeu.com. (31)
13:50:41.012834 70:03:9f:4b:5a:e3 > 4c:cc:6a:22:1f:ab, ethertype IPv4 (0x0800), length 73: (tos 0x0, ttl 255, id 16, offset 0, flags [none], proto UDP (17), length 59)
    192.168.200.201.49153 > 192.168.0.1.53: [udp sum ok] 19255+ A? a3.tuyaeu.com. (31)
13:50:41.015108 70:03:9f:4b:5a:e3 > 4c:cc:6a:22:1f:ab, ethertype IPv4 (0x0800), length 73: (tos 0x0, ttl 255, id 17, offset 0, flags [none], proto UDP (17), length 59)
    192.168.200.201.49153 > 192.168.0.1.53: [udp sum ok] 33053+ A? m2.tuyaeu.com. (31)
13:50:42.022749 70:03:9f:4b:5a:e3 > 4c:cc:6a:22:1f:ab, ethertype IPv4 (0x0800), length 73: (tos 0x0, ttl 255, id 18, offset 0, flags [none], proto UDP (17), length 59)
    192.168.200.201.49153 > 192.168.0.1.53: [udp sum ok] 33053+ A? m2.tuyaeu.com. (31)
13:50:43.017276 70:03:9f:4b:5a:e3 > 4c:cc:6a:22:1f:ab, ethertype IPv4 (0x0800), length 73: (tos 0x0, ttl 255, id 19, offset 0, flags [none], proto UDP (17), length 59)
    192.168.200.201.49153 > 192.168.0.1.53: [udp sum ok] 19255+ A? a3.tuyaeu.com. (31)
13:50:44.017201 70:03:9f:4b:5a:e3 > 4c:cc:6a:22:1f:ab, ethertype IPv4 (0x0800), length 73: (tos 0x0, ttl 255, id 20, offset 0, flags [none], proto UDP (17), length 59)
    192.168.200.201.49153 > 192.168.0.1.53: [udp sum ok] 33053+ A? m2.tuyaeu.com. (31)
13:50:45.030931 70:03:9f:4b:5a:e3 > ff:ff:ff:ff:ff:ff, ethertype IPv4 (0x0800), length 230: (tos 0x0, ttl 255, id 21, offset 0, flags [none], proto UDP (17), length 216)
    192.168.200.201.49154 > 255.255.255.255.6667: [udp sum ok] UDP, length 188
13:50:50.028919 70:03:9f:4b:5a:e3 > ff:ff:ff:ff:ff:ff, ethertype IPv4 (0x0800), length 230: (tos 0x0, ttl 255, id 22, offset 0, flags [none], proto UDP (17), length 216)
    192.168.200.201.49154 > 255.255.255.255.6667: [udp sum ok] UDP, length 188
13:50:52.025685 70:03:9f:4b:5a:e3 > 4c:cc:6a:22:1f:ab, ethertype IPv4 (0x0800), length 73: (tos 0x0, ttl 255, id 23, offset 0, flags [none], proto UDP (17), length 59)
    192.168.200.201.49153 > 192.168.0.1.53: [udp sum ok] 51921+ A? m2.tuyaeu.com. (31)
13:50:53.017165 70:03:9f:4b:5a:e3 > 4c:cc:6a:22:1f:ab, ethertype IPv4 (0x0800), length 73: (tos 0x0, ttl 255, id 24, offset 0, flags [none], proto UDP (17), length 59)
    192.168.200.201.49153 > 192.168.0.1.53: [udp sum ok] 51921+ A? m2.tuyaeu.com. (31)
13:50:54.017205 70:03:9f:4b:5a:e3 > 4c:cc:6a:22:1f:ab, ethertype IPv4 (0x0800), length 73: (tos 0x0, ttl 255, id 25, offset 0, flags [none], proto UDP (17), length 59)
    192.168.200.201.49153 > 192.168.0.1.53: [udp sum ok] 51921+ A? m2.tuyaeu.com. (31)
13:50:55.029379 70:03:9f:4b:5a:e3 > ff:ff:ff:ff:ff:ff, ethertype IPv4 (0x0800), length 230: (tos 0x0, ttl 255, id 26, offset 0, flags [none], proto UDP (17), length 216)
    192.168.200.201.49154 > 255.255.255.255.6667: [udp sum ok] UDP, length 188
13:50:56.049025 70:03:9f:4b:5a:e3 > 4c:cc:6a:22:1f:ab, ethertype IPv4 (0x0800), length 73: (tos 0x0, ttl 255, id 27, offset 0, flags [none], proto UDP (17), length 59)
    192.168.200.201.49153 > 192.168.0.1.53: [udp sum ok] 46198+ A? a3.tuyaeu.com. (31)
13:50:56.051445 70:03:9f:4b:5a:e3 > 4c:cc:6a:22:1f:ab, ethertype IPv4 (0x0800), length 73: (tos 0x0, ttl 255, id 28, offset 0, flags [none], proto UDP (17), length 59)
    192.168.200.201.49153 > 192.168.0.1.53: [udp sum ok] 51921+ A? m2.tuyaeu.com. (31)
13:50:56.055274 70:03:9f:4b:5a:e3 > 4c:cc:6a:22:1f:ab, ethertype IPv4 (0x0800), length 73: (tos 0x0, ttl 255, id 29, offset 0, flags [none], proto UDP (17), length 59)
    192.168.200.201.49153 > 192.168.0.1.53: [udp sum ok] 46198+ A? a3.tuyaeu.com. (31)
13:50:57.052269 70:03:9f:4b:5a:e3 > 4c:cc:6a:22:1f:ab, ethertype IPv4 (0x0800), length 73: (tos 0x0, ttl 255, id 30, offset 0, flags [none], proto UDP (17), length 59)
    192.168.200.201.49153 > 192.168.0.1.53: [udp sum ok] 46198+ A? a3.tuyaeu.com. (31)
13:50:59.052462 70:03:9f:4b:5a:e3 > 4c:cc:6a:22:1f:ab, ethertype IPv4 (0x0800), length 73: (tos 0x0, ttl 255, id 31, offset 0, flags [none], proto UDP (17), length 59)
    192.168.200.201.49153 > 192.168.0.1.53: [udp sum ok] 46198+ A? a3.tuyaeu.com. (31)
13:51:00.028640 70:03:9f:4b:5a:e3 > ff:ff:ff:ff:ff:ff, ethertype IPv4 (0x0800), length 230: (tos 0x0, ttl 255, id 32, offset 0, flags [none], proto UDP (17), length 216)
    192.168.200.201.49154 > 255.255.255.255.6667: [udp sum ok] UDP, length 188
13:51:04.060081 70:03:9f:4b:5a:e3 > 4c:cc:6a:22:1f:ab, ethertype IPv4 (0x0800), length 73: (tos 0x0, ttl 255, id 33, offset 0, flags [none], proto UDP (17), length 59)
    192.168.200.201.49153 > 192.168.0.1.53: [udp sum ok] 40429+ A? m2.tuyaeu.com. (31)
13:51:05.028222 70:03:9f:4b:5a:e3 > ff:ff:ff:ff:ff:ff, ethertype IPv4 (0x0800), length 230: (tos 0x0, ttl 255, id 34, offset 0, flags [none], proto UDP (17), length 216)
    192.168.200.201.49154 > 255.255.255.255.6667: [udp sum ok] UDP, length 188
13:51:05.047179 70:03:9f:4b:5a:e3 > 4c:cc:6a:22:1f:ab, ethertype IPv4 (0x0800), length 73: (tos 0x0, ttl 255, id 35, offset 0, flags [none], proto UDP (17), length 59)
    192.168.200.201.49153 > 192.168.0.1.53: [udp sum ok] 40429+ A? m2.tuyaeu.com. (31)
13:51:06.052524 70:03:9f:4b:5a:e3 > 4c:cc:6a:22:1f:ab, ethertype IPv4 (0x0800), length 73: (tos 0x0, ttl 255, id 36, offset 0, flags [none], proto UDP (17), length 59)
    192.168.200.201.49153 > 192.168.0.1.53: [udp sum ok] 40429+ A? m2.tuyaeu.com. (31)
13:51:08.052448 70:03:9f:4b:5a:e3 > 4c:cc:6a:22:1f:ab, ethertype IPv4 (0x0800), length 73: (tos 0x0, ttl 255, id 37, offset 0, flags [none], proto UDP (17), length 59)
    192.168.200.201.49153 > 192.168.0.1.53: [udp sum ok] 40429+ A? m2.tuyaeu.com. (31)
13:51:10.028075 70:03:9f:4b:5a:e3 > ff:ff:ff:ff:ff:ff, ethertype IPv4 (0x0800), length 230: (tos 0x0, ttl 255, id 38, offset 0, flags [none], proto UDP (17), length 216)
    192.168.200.201.49154 > 255.255.255.255.6667: [udp sum ok] UDP, length 188
13:51:15.028541 70:03:9f:4b:5a:e3 > ff:ff:ff:ff:ff:ff, ethertype IPv4 (0x0800), length 230: (tos 0x0, ttl 255, id 39, offset 0, flags [none], proto UDP (17), length 216)
    192.168.200.201.49154 > 255.255.255.255.6667: [udp sum ok] UDP, length 188
13:51:16.055537 70:03:9f:4b:5a:e3 > 4c:cc:6a:22:1f:ab, ethertype IPv4 (0x0800), length 73: (tos 0x0, ttl 255, id 40, offset 0, flags [none], proto UDP (17), length 59)
    192.168.200.201.49153 > 192.168.0.1.53: [udp sum ok] 11777+ A? m2.tuyaeu.com. (31)
13:51:17.052868 70:03:9f:4b:5a:e3 > 4c:cc:6a:22:1f:ab, ethertype IPv4 (0x0800), length 73: (tos 0x0, ttl 255, id 41, offset 0, flags [none], proto UDP (17), length 59)
    192.168.200.201.49153 > 192.168.0.1.53: [udp sum ok] 11777+ A? m2.tuyaeu.com. (31)
13:51:17.073549 70:03:9f:4b:5a:e3 > 4c:cc:6a:22:1f:ab, ethertype IPv4 (0x0800), length 73: (tos 0x0, ttl 255, id 42, offset 0, flags [none], proto UDP (17), length 59)
    192.168.200.201.49153 > 192.168.0.1.53: [udp sum ok] 28757+ A? a3.tuyaeu.com. (31)
13:51:18.052831 70:03:9f:4b:5a:e3 > 4c:cc:6a:22:1f:ab, ethertype IPv4 (0x0800), length 73: (tos 0x0, ttl 255, id 43, offset 0, flags [none], proto UDP (17), length 59)
    192.168.200.201.49153 > 192.168.0.1.53: [udp sum ok] 11777+ A? m2.tuyaeu.com. (31)
13:51:18.055056 70:03:9f:4b:5a:e3 > 4c:cc:6a:22:1f:ab, ethertype IPv4 (0x0800), length 73: (tos 0x0, ttl 255, id 44, offset 0, flags [none], proto UDP (17), length 59)
    192.168.200.201.49153 > 192.168.0.1.53: [udp sum ok] 28757+ A? a3.tuyaeu.com. (31)
13:51:19.062514 70:03:9f:4b:5a:e3 > 4c:cc:6a:22:1f:ab, ethertype IPv4 (0x0800), length 73: (tos 0x0, ttl 255, id 45, offset 0, flags [none], proto UDP (17), length 59)
    192.168.200.201.49153 > 192.168.0.1.53: [udp sum ok] 28757+ A? a3.tuyaeu.com. (31)
13:51:20.028060 70:03:9f:4b:5a:e3 > ff:ff:ff:ff:ff:ff, ethertype IPv4 (0x0800), length 230: (tos 0x0, ttl 255, id 46, offset 0, flags [none], proto UDP (17), length 216)
    192.168.200.201.49154 > 255.255.255.255.6667: [udp sum ok] UDP, length 188
13:51:20.057306 70:03:9f:4b:5a:e3 > 4c:cc:6a:22:1f:ab, ethertype IPv4 (0x0800), length 73: (tos 0x0, ttl 255, id 47, offset 0, flags [none], proto UDP (17), length 59)
    192.168.200.201.49153 > 192.168.0.1.53: [udp sum ok] 11777+ A? m2.tuyaeu.com. (31)
13:51:21.064816 70:03:9f:4b:5a:e3 > 4c:cc:6a:22:1f:ab, ethertype IPv4 (0x0800), length 73: (tos 0x0, ttl 255, id 48, offset 0, flags [none], proto UDP (17), length 59)
    192.168.200.201.49153 > 192.168.0.1.53: [udp sum ok] 28757+ A? a3.tuyaeu.com. (31)
13:51:25.027911 70:03:9f:4b:5a:e3 > ff:ff:ff:ff:ff:ff, ethertype IPv4 (0x0800), length 230: (tos 0x0, ttl 255, id 49, offset 0, flags [none], proto UDP (17), length 216)
    192.168.200.201.49154 > 255.255.255.255.6667: [udp sum ok] UDP, length 188
13:51:27.782589 70:03:9f:4b:5a:e3 > 4c:cc:6a:22:1f:ab, ethertype IPv4 (0x0800), length 73: (tos 0x0, ttl 255, id 50, offset 0, flags [none], proto UDP (17), length 59)
    192.168.200.201.49153 > 192.168.0.1.53: [udp sum ok] 21459+ A? a3.tuyaeu.com. (31)
13:51:28.063435 70:03:9f:4b:5a:e3 > 4c:cc:6a:22:1f:ab, ethertype IPv4 (0x0800), length 73: (tos 0x0, ttl 255, id 51, offset 0, flags [none], proto UDP (17), length 59)
    192.168.200.201.49153 > 192.168.0.1.53: [udp sum ok] 21459+ A? a3.tuyaeu.com. (31)
13:51:29.800859 4c:cc:6a:22:1f:ab > 70:03:9f:4b:5a:e3, ethertype IPv4 (0x0800), length 342: (tos 0x10, ttl 128, id 0, offset 0, flags [none], proto UDP (17), length 328)
    192.168.200.1.67 > 192.168.200.201.68: [udp sum ok] BOOTP/DHCP, Reply, length 300, xid 0x613a5639, Flags [none] (0x0000)
      Your-IP 192.168.200.201
      Client-Ethernet-Address 70:03:9f:4b:5a:e3
      Vendor-rfc1048 Extensions
        Magic Cookie 0x63825363
        DHCP-Message Option 53, length 1: Offer
        Server-ID Option 54, length 4: 192.168.200.1
        Lease-Time Option 51, length 4: 7200
        Subnet-Mask Option 1, length 4: 255.255.255.0
        Default-Gateway Option 3, length 4: 192.168.200.1
        Domain-Name-Server Option 6, length 4: 192.168.0.1
        Domain-Name Option 15, length 16: "fam-kloepfer.lan"
13:51:29.807402 4c:cc:6a:22:1f:ab > 70:03:9f:4b:5a:e3, ethertype IPv4 (0x0800), length 342: (tos 0x10, ttl 128, id 0, offset 0, flags [none], proto UDP (17), length 328)
    192.168.200.1.67 > 192.168.200.201.68: [udp sum ok] BOOTP/DHCP, Reply, length 300, xid 0x561085cc, Flags [none] (0x0000)
      Your-IP 192.168.200.201
      Client-Ethernet-Address 70:03:9f:4b:5a:e3
      Vendor-rfc1048 Extensions
        Magic Cookie 0x63825363
        DHCP-Message Option 53, length 1: ACK
        Server-ID Option 54, length 4: 192.168.200.1
        Lease-Time Option 51, length 4: 7200
        Subnet-Mask Option 1, length 4: 255.255.255.0
        Default-Gateway Option 3, length 4: 192.168.200.1
        Domain-Name-Server Option 6, length 4: 192.168.0.1
        Domain-Name Option 15, length 16: "fam-kloepfer.lan"
13:51:31.086396 70:03:9f:4b:5a:e3 > 4c:cc:6a:22:1f:ab, ethertype IPv4 (0x0800), length 73: (tos 0x0, ttl 255, id 55, offset 0, flags [none], proto UDP (17), length 59)
    192.168.200.201.49153 > 192.168.0.1.53: [udp sum ok] 21459+ A? a3.tuyaeu.com. (31)
13:51:32.078835 70:03:9f:4b:5a:e3 > 4c:cc:6a:22:1f:ab, ethertype IPv4 (0x0800), length 73: (tos 0x0, ttl 255, id 56, offset 0, flags [none], proto UDP (17), length 59)
    192.168.200.201.49153 > 192.168.0.1.53: [udp sum ok] 64389+ A? m2.tuyaeu.com. (31)
13:51:35.028630 70:03:9f:4b:5a:e3 > ff:ff:ff:ff:ff:ff, ethertype IPv4 (0x0800), length 230: (tos 0x0, ttl 255, id 57, offset 0, flags [none], proto UDP (17), length 216)
    192.168.200.201.49154 > 255.255.255.255.6667: [udp sum ok] UDP, length 188

You can see no com. between HA and device ( 192.168.0.10 <--> 192.168.200.201 ) Periodicly DNS requests but they will blocked. Nothing with port 6667 or 6668. Only a broadcast. But the broacast will not forwarded to other subnets.

The issue about DNS i already know. If DNS is blocked the device it is unavailable ( zombie ) until i press the switch button on the device. I think it is fixable by simulating a part of the amazon cloud or answer with a fake answer.

postlund commented 3 years ago

As stated in the change log, the broadcasts are what's important as those are what trigger connections at all. So I recommend that you forward those. I opened #288 which re-adds re-connection logic similar to before (re-connects are made every 60s). But having broadcasts forwarded will make recovery much faster.

imkebe commented 3 years ago

@postlund are you aware that without special network hacks broadcast packets cannot be forwarded between subnets (that's ipv4 network architecture by design) ? just tellin you.

For those who want to preserve separated subnets architecture:

I use socat on my OpenWRT box: socat UDP4-RECVFROM:6667,fork,so-bindtodevice=<networkInterfaceToListenOn> UDP4-SENDTO:<homeAssistantIP>:6667

It should do the same for any linux box in the same network. The only reqiriement is generic routing between iot subnet and HA subnet. Since socat rewrites broadcast packets and forks them to the single IP, it should be allowed to pass through inter subnet gateway (which is not possible for broadcast packets by design as i stated previously).

Marco-Kl commented 3 years ago

Hello @imkebe, thanks for the hint. I am aware of it. I am using pfsense, so i will configure a relay for that. But if nobody is listening to that broadcast it makes no sense to relay it. From my point of view it is only mandantory to detect devices in case they are new. The Tuya devices always want to connect to the Tuya HQ. If I block or reject the dns and internet traffic they will never going ready to connect. If I resolv the tuya lookup with fake ip's the device will go into endless reboot loop. I think shelly devices are the only ones the will support custom firmware with no cloud connect.

Regards Marco