leeyuentuen / localtuya

local handling for Tuya devices
GNU General Public License v3.0
72 stars 17 forks source link

Devices become unavailable randomly #22

Closed Anycubic closed 1 year ago

Anycubic commented 1 year ago

Suddenly and apparently randomly devices become unavailable forever. I have 6 TRV valves connected to a ZIgbee Gateway, in Tuya they work fine. Reloading Local Tuya does not help, to fix it I have to restart Home Assistant. Unfortunately after a while the same thing happens.

Environment Localtuya version: 3.6.1 Last working localtuya version (if known and relevant): 3.5.3 Home Assistant Core version: 2022.12 Are you using the Home Assistant Tuya Cloud component ? no Are you using the Tuya App in parallel ? Just for reading devices status

home-assistant_2022-12-21T21-35-32.480Z copy.txt

leeyuentuen commented 1 year ago

@Anycubic can you take a look at the https://github.com/leeyuentuen/localtuya/releases/tag/3.6.2-beta if this solved the problem?

Anycubic commented 1 year ago

@leeyuentuen I've just installed 3.6.2-beta code, I'll let you know, thanks!

leeyuentuen commented 1 year ago

I don't have climate stuff, so I can't test that part of the code.

Anycubic commented 1 year ago

I don't have climate stuff, so I can't test that part of the code.

I can test it for you, more than happy to help!

Anycubic commented 1 year ago

Hello @leeyuentuen , this morning I had again the issue on all of the devices, like that:

2022-12-29 01:25:47.409 WARNING (SyncWorker_6) [custom_components.localtuya.climate] [84b...f48] Entity climate.sala_nord is requesting unknown DPS index 101

But I saw you published 3.6.2-beta.3 addressing the same issue, just installed it and report back.

leeyuentuen commented 1 year ago

have you more logs? because this error is just that the tuya can't get value from DPS because the device is not available, but we need to know if it has crashed before

edit: typically the Zigbee gateway is unavailable for some reason (lost signal, typically after recovery, the value should be getting). But if the Localtuya has crashed due to some reason (which should be shown in the log) then you won't get the value anymore. So I'm searching for the crash of the localtuya log

Anycubic commented 1 year ago

@leeyuentuen unfortunately the only errors I have in the log with 3.6.2 beta are those ones, nothing wrong regarding local tuya before them like it was happening with 3.6.1

leeyuentuen commented 1 year ago

maybe add this in your configuration for more debug logs?

https://github.com/leeyuentuen/localtuya#debugging

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

but next thing that I would implement is passive dps state from here: https://github.com/rospogrigio/localtuya/pull/956/files#diff-a3f5eb9a8d6d90187aad3eb57dacfb61863c40352af98dfcf1fb31cde8a778ed

Anycubic commented 1 year ago

Ok, I'll that for logs.

Anycubic commented 1 year ago

@leeyuentuen 3.6.3 broke the integration, all of the devices became unavailable since HA startup. Had to go back to 3.6.2

leeyuentuen commented 1 year ago

i need to check on 3.6.3. it is still a alpha version that could be break. maybe i remove them here from the list before other people also download them

Anycubic commented 1 year ago

@leeyuentuen I had to restart my Zigbee gateway and everything went south, any of my devices are available anymore. I tried to delete and re-add them but don't know why DPS are not recognised anymore (just on of them is recognised). I deleted everything and started from scratch but I have always the same problem 😢 Is this related to https://github.com/leeyuentuen/localtuya/issues/28#issue-1519567674 maybe?

I really don't know what to do now, any help would be appreciated, thanks

leeyuentuen commented 1 year ago

i'm not sure, need to check, but one of my wired zigbee gateway got a firmware update, then it also failed on localtuya. could be a change of version 3.3 to 3.4 platform (tuya platform data message platform). this is also on my todo list to check the issue.

at the moment 3.6.2 is a stable version

Anycubic commented 1 year ago

@leeyuentuen I don't have automatic update on any device, so I doubt this is the reason. Do I need to reset anything starting from reinstalling standard Tuya integration? I deleted it

leeyuentuen commented 1 year ago

are the zigbee device recognized in tuya app on your mobile phone? to be sure if they are connected?

Anycubic commented 1 year ago

Yep

leeyuentuen commented 1 year ago

you can comment all the localtuya code and reboot, then remove the tuya devices in home assistant devices and reboot. remove the comment away from the gateway and see if there are error in the logs. and try uncomment one zigbee device and see if it recognized

Anycubic commented 1 year ago

Actually now I recalled the very same thing happened to me also in the past with 3.6.1, reinstalled everything from scratch and it worked. Not this time

leeyuentuen commented 1 year ago

normally if your device are unavailable, you should see something in the logs

Anycubic commented 1 year ago

you can comment all the localtuya code and reboot, then remove the tuya devices in home assistant devices and reboot. remove the comment away from the gateway and see if there are error in the logs. and try uncomment one zigbee device and see if it recognized

In which config file?

Anycubic commented 1 year ago

normally if you device are unavailable, you should see something in the logs

Thats funny because the first thing I did was looking at the logs but devices were recognised and no errors at all but they were unavailable

leeyuentuen commented 1 year ago

you can comment all the localtuya code and reboot, then remove the tuya devices in home assistant devices and reboot. remove the comment away from the gateway and see if there are error in the logs. and try uncomment one zigbee device and see if it recognized

In which config file?

you have add them in yaml?

something with localtuya: .....

Anycubic commented 1 year ago

you can comment all the localtuya code and reboot, then remove the tuya devices in home assistant devices and reboot. remove the comment away from the gateway and see if there are error in the logs. and try uncomment one zigbee device and see if it recognized

In which config file?

you have add them in yaml?

something with localtuya: .....

I just added the gateway from scratch and I don't have anything in /config/configuration.yaml

leeyuentuen commented 1 year ago

you can comment all the localtuya code and reboot, then remove the tuya devices in home assistant devices and reboot. remove the comment away from the gateway and see if there are error in the logs. and try uncomment one zigbee device and see if it recognized

In which config file?

you have add them in yaml? something with localtuya: .....

I just added the gateway from scratch and I don't have anything in /config/configuration.yaml

ah, you add them from the config flow instead of adding in configuration yaml

Anycubic commented 1 year ago

Exactly

leeyuentuen commented 1 year ago

you are sure running 3.6.2? not the alpha version?

what for error do you see in the log? maybe add the logging:

https://github.com/leeyuentuen/localtuya#debugging

Anycubic commented 1 year ago

I don't know why, but reconfiguring "standard" Tuya integration fixed also Local Tuya

alexualbu commented 1 year ago

@Anycubic , it happens to me too (i found all of my devices in that state this morning - both independent and sub-devices). I managed to reconnect them by reloading each device individually in settings. After activating debugging i can see that the "Requesting unknown DPS" warning appears when the device is disconnected by localtuya.

2023-01-16 12:19:21.044 DEBUG (MainThread) [custom_components.localtuya.pytuya] [bfb...bhd] Heartbeat failed due to timeout, disconnecting 2023-01-16 12:19:21.047 DEBUG (MainThread) [custom_components.localtuya.pytuya] [bfb...bhd] Connection lost: None 2023-01-16 12:19:21.048 DEBUG (MainThread) [custom_components.localtuya.common] [bfb...bhd] Disconnected - waiting for discovery broadcast 2023-01-16 12:19:21.049 WARNING (SyncWorker_11) [custom_components.localtuya.climate] [bfb...bhd] Entity climate.underfloor_heating is requesting unknown DPS index 1 2023-01-16 12:19:21.052 WARNING (SyncWorker_11) [custom_components.localtuya.climate] [bfb...bhd] Entity climate.underfloor_heating is requesting unknown DPS index 16 2023-01-16 12:19:21.057 WARNING (SyncWorker_11) [custom_components.localtuya.climate] [bfb...bhd] Entity climate.underfloor_heating is requesting unknown DPS index 24 2023-01-16 12:19:21.064 WARNING (SyncWorker_11) [custom_components.localtuya.climate] [bfb...bhd] Entity climate.underfloor_heating is requesting unknown DPS index 2 2023-01-16 12:19:21.067 WARNING (SyncWorker_11) [custom_components.localtuya.climate] [bfb...bhd] Entity climate.underfloor_heating is requesting unknown DPS index 2 2023-01-16 12:19:21.071 WARNING (SyncWorker_11) [custom_components.localtuya.climate] [bfb...bhd] Entity climate.underfloor_heating is requesting unknown DPS index 3 2023-01-16 12:19:21.075 WARNING (SyncWorker_11) [custom_components.localtuya.climate] [bfb...bhd] Entity climate.underfloor_heating is requesting unknown DPS index 3

I'll keep watching it the logs. What I suspect might be happening is that localtuya gets disconnected from the device and somehow does not manage to reconnect.

Anycubic commented 1 year ago

@alexualbu for me re-addding the devices with integration was not working at all, as I said as strange as it could seem I had to reinstall Tuya integration and everything was back ok. I believe that I messed up with devices name (Tuya name and Local Tuya were the same, though I had deleted Tuya integration) when I re added my devices I just added also "_local" to their name, not to mess up again

Anycubic commented 1 year ago

@leeyuentuen and btw 3.6.2 is not showing the "unavailable" bug since at least one week, finger crossed

alexualbu commented 1 year ago

@Anycubic, i had named mine differently (with '_local' :) ) from the beginning. I didn't re-add the devices, clicked reload in the Integrations UI. Did you also restart home-assistant when reinstalling the tuya integration? Restarting seems to also fix it as well. Also running 3.6.2 btw.

Anycubic commented 1 year ago

@alexualbu last time I had a different kind of problem, everything went bananas after restarting my Zigbee gateway, nothing was working (erased everything, re-added devices, nothing). Then I configured Tuya again (I had removed it totally) and this made my day. Go figure...

alexualbu commented 1 year ago

So I think I was on to something: gateway disconnected, sub-devices disconnected, errors about unknown DPS appear (1), gateway reconnects - i believe (2), sub-devices did not reconnect automatically afterwards, only with a reload of the device (3). But then it happened again (4) and the gateway did not reconnect (absolutely no log entries for its device id) and a reload of the sub-device does not work anymore(5). And here is where it gets interesting - a reload of the gateway (6) starts producing normal logs(7)... except they appear as unavailable in the UI, even though the history shows data for them (8). After I went in the Smart Life app and changed something the status of the sub-device in HA is magically not unavailable anymore and the history is also updated with a new gap ?! - (9) Apparently this also works if a change is made on the TRV itself. So any status update from the sub-device will do. With this info I can also find another disconnect event dispatched from the gateway to the sub-devices(10)

So my line of thinking now is that if the gateway gets disconnected from localtuya the sub-devices are not added back until they send an update themselves or are reloaded (11). Which I think results in 2 courses of actions:

  1. identify why the gateway does not reconnect sometimes
  2. re-add subdevices to the gateway then it reconnects itself

@leeyuentuen , does this make sense?

(1) `2023-01-17 10:19:49.079 DEBUG (MainThread) [custom_components.localtuya.pytuya] [bfc...gnc] Connection lost: None 2023-01-17 10:19:49.087 DEBUG (MainThread) [custom_components.localtuya.common] [bfc...gnc] Dispatching event event_disconnected to sub-device 804b50fffe1a8b4f with data None 2023-01-17 10:19:49.089 DEBUG (MainThread) [custom_components.localtuya.common] [bfc...gnc] Dispatching event event_disconnected to sub-device 804b50fffe2536ca with data None 2023-01-17 10:19:49.090 DEBUG (MainThread) [custom_components.localtuya.common] [bfc...gnc] Dispatching event event_disconnected to sub-device 804b50fffe2bf6fc with data None 2023-01-17 10:19:49.091 DEBUG (MainThread) [custom_components.localtuya.common] [bfc...gnc] Dispatching event event_disconnected to sub-device 804b50fffe219467 with data None 2023-01-17 10:19:49.096 DEBUG (MainThread) [custom_components.localtuya.common] [bfc...gnc] Dispatching event event_disconnected to sub-device 847127fffef500ca with data None 2023-01-17 10:19:49.097 DEBUG (MainThread) [custom_components.localtuya.common] [bfc...gnc] Dispatching event event_disconnected to sub-device 804b50fffe1a7e73 with data None 2023-01-17 10:19:49.098 DEBUG (MainThread) [custom_components.localtuya.common] [bfc...gnc] Dispatching event event_disconnected to sub-device 847127fffef501a1 with data None 2023-01-17 10:19:49.099 DEBUG (MainThread) [custom_components.localtuya.common] [bfc...gnc] Dispatching event event_disconnected to sub-device 804b50fffe1a8979 with data None 2023-01-17 10:19:49.099 DEBUG (MainThread) [custom_components.localtuya.common] [bfc...gnc] Disconnected - waiting for discovery broadcast 2023-01-17 10:19:49.100 DEBUG (SyncWorker_4) [custom_components.localtuya.common] [804...b4f] Received event event_disconnected from gateway with data None 2023-01-17 10:19:49.102 DEBUG (SyncWorker_4) [custom_components.localtuya.common] [804...b4f] Disconnected 2023-01-17 10:19:49.103 DEBUG (SyncWorker_11) [custom_components.localtuya.common] [804...6ca] Received event event_disconnected from gateway with data None 2023-01-17 10:19:49.134 DEBUG (SyncWorker_3) [custom_components.localtuya.common] [804...6fc] Received event event_disconnected from gateway with data None 2023-01-17 10:19:49.134 DEBUG (SyncWorker_4) [custom_components.localtuya.common] [804...467] Received event event_disconnected from gateway with data None 2023-01-17 10:19:49.142 DEBUG (MainThread) [custom_components.localtuya.pytuya] [bfb...bhd] Connection lost: None 2023-01-17 10:19:49.146 DEBUG (SyncWorker_11) [custom_components.localtuya.common] [804...6ca] Disconnected 2023-01-17 10:19:49.147 DEBUG (SyncWorker_11) [custom_components.localtuya.common] [847...0ca] Received event event_disconnected from gateway with data None 2023-01-17 10:19:49.153 DEBUG (SyncWorker_0) [custom_components.localtuya.common] [804...e73] Received event event_disconnected from gateway with data None 2023-01-17 10:19:49.156 DEBUG (SyncWorker_20) [custom_components.localtuya.common] [847...1a1] Received event event_disconnected from gateway with data None 2023-01-17 10:19:49.178 WARNING (SyncWorker_5) [custom_components.localtuya.select] [804...b4f] Entity select.radiator_bedroom_valve_setting is requesting unknown DPS index 106 2023-01-17 10:19:49.180 WARNING (SyncWorker_2) [custom_components.localtuya.sensor] [804...b4f] Entity sensor.radiator_bedroom_valve_status is requesting unknown DPS index 109 `
(2) ` 2023-01-17 10:20:06.157 DEBUG (MainThread) [custom_components.localtuya.pytuya] [bfc...gnc] Sending command heartbeat (device type: type_0d) 2023-01-17 10:20:06.158 DEBUG (MainThread) [custom_components.localtuya.pytuya] [bfc...gnc] Send payload: b'{}' 2023-01-17 10:20:06.160 DEBUG (MainThread) [custom_components.localtuya.pytuya] [bfc...gnc] Waiting for sequence number -100 2023-01-17 10:20:06.247 DEBUG (MainThread) [custom_components.localtuya.pytuya] [bfc...gnc] Dispatching message TuyaMessage(seqno=0, cmd=9, retcode=0, payload=b'', crc=2958142211, crcpassed=True) 2023-01-17 10:20:06.248 DEBUG (MainThread) [custom_components.localtuya.pytuya] [bfc...gnc] Got heartbeat response 2023-01-17 10:20:06.694 DEBUG (MainThread) [custom_components.localtuya.pytuya] [bfc...gnc] Decrypted payload: {} 2023-01-17 10:20:16.698 DEBUG (MainThread) [custom_components.localtuya.pytuya] [bfc...gnc] Sending command heartbeat (device type: type_0d) 2023-01-17 10:20:16.700 DEBUG (MainThread) [custom_components.localtuya.pytuya] [bfc...gnc] Send payload: b'{}' 2023-01-17 10:20:16.710 DEBUG (MainThread) [custom_components.localtuya.pytuya] [bfc...gnc] Waiting for sequence number -100 2023-01-17 10:20:16.719 DEBUG (MainThread) [custom_components.localtuya.pytuya] [bfc...gnc] Dispatching message TuyaMessage(seqno=0, cmd=9, retcode=0, payload=b'', crc=2958142211, crcpassed=True) 2023-01-17 10:20:16.719 DEBUG (MainThread) [custom_components.localtuya.pytuya] [bfc...gnc] Got heartbeat response 2023-01-17 10:20:16.728 DEBUG (MainThread) [custom_components.localtuya.pytuya] [bfc...gnc] Decrypted payload: {} 2023-01-17 10:20:26.731 DEBUG (MainThread) [custom_components.localtuya.pytuya] [bfc...gnc] Sending command heartbeat (device type: type_0d) 2023-01-17 10:20:26.731 DEBUG (MainThread) [custom_components.localtuya.pytuya] [bfc...gnc] Send payload: b'{}' 2023-01-17 10:20:26.738 DEBUG (MainThread) [custom_components.localtuya.pytuya] [bfc...gnc] Waiting for sequence number -100 2023-01-17 10:20:26.798 DEBUG (MainThread) [custom_components.localtuya.pytuya] [bfc...gnc] Dispatching message TuyaMessage(seqno=0, cmd=9, retcode=0, payload=b'', crc=2958142211, crcpassed=True) 2023-01-17 10:20:26.799 DEBUG (MainThread) [custom_components.localtuya.pytuya] [bfc...gnc] Got heartbeat response 2023-01-17 10:20:26.800 DEBUG (MainThread) [custom_components.localtuya.pytuya] [bfc...gnc] Decrypted payload: {} `
(3) ` 2023-01-17 11:04:46.440 DEBUG (MainThread) [custom_components.localtuya.pytuya] [bfc...gnc] Sending command heartbeat (device type: type_0d) 2023-01-17 11:04:46.442 DEBUG (MainThread) [custom_components.localtuya.pytuya] [bfc...gnc] Send payload: b'{}' 2023-01-17 11:04:46.443 DEBUG (MainThread) [custom_components.localtuya.pytuya] [bfc...gnc] Waiting for sequence number -100 2023-01-17 11:04:46.452 DEBUG (MainThread) [custom_components.localtuya.pytuya] [bfc...gnc] Dispatching message TuyaMessage(seqno=0, cmd=9, retcode=0, payload=b'', crc=2958142211, crcpassed=True) 2023-01-17 11:04:46.453 DEBUG (MainThread) [custom_components.localtuya.pytuya] [bfc...gnc] Got heartbeat response 2023-01-17 11:04:46.454 DEBUG (MainThread) [custom_components.localtuya.pytuya] [bfc...gnc] Decrypted payload: {} 2023-01-17 11:04:53.411 DEBUG (MainThread) [custom_components.localtuya.common] [804...b4f] Dispatching request request_remove to gateway with content None 2023-01-17 11:04:53.435 DEBUG (MainThread) [custom_components.localtuya.common] [bfc...gnc] Received request request_remove from 804b50fffe1a8b4f with content None 2023-01-17 11:04:53.435 DEBUG (MainThread) [custom_components.localtuya.common] [bfc...gnc] Dispatching event event_disconnected to sub-device 804b50fffe1a8b4f with data None 2023-01-17 11:04:53.473 DEBUG (MainThread) [custom_components.localtuya.select] Display Options Configured: Normal;Forced Open;Forced Close 2023-01-17 11:04:53.474 DEBUG (MainThread) [custom_components.localtuya.select] Total Raw Options: 3 - Total Display Options: 3 2023-01-17 11:04:53.505 DEBUG (MainThread) [custom_components.localtuya.sensor] [804...b4f] Adding sensor.radiator_bedroom_valve_status with configuration: {'friendly_name': 'Radiator Bedroom Valve Status', 'unit_of_measurement': '%', 'id': 109, 'platform': 'sensor'} `
(4) ` 2023-01-17 12:32:07.423 DEBUG (MainThread) [custom_components.localtuya.pytuya] [bfc...gnc] Sending command heartbeat (device type: type_0d) 2023-01-17 12:32:07.423 DEBUG (MainThread) [custom_components.localtuya.pytuya] [bfc...gnc] Send payload: b'{}' 2023-01-17 12:32:07.456 DEBUG (MainThread) [custom_components.localtuya.pytuya] [bfc...gnc] Waiting for sequence number -100 2023-01-17 12:32:09.081 DEBUG (MainThread) [custom_components.localtuya.pytuya] [bfc...gnc] Connection lost: None 2023-01-17 12:32:09.082 DEBUG (MainThread) [custom_components.localtuya.common] [bfc...gnc] Dispatching event event_disconnected to sub-device 804b50fffe2536ca with data None 2023-01-17 12:32:09.083 DEBUG (MainThread) [custom_components.localtuya.common] [bfc...gnc] Dispatching event event_disconnected to sub-device 804b50fffe2bf6fc with data None 2023-01-17 12:32:09.083 DEBUG (MainThread) [custom_components.localtuya.common] [bfc...gnc] Dispatching event event_disconnected to sub-device 804b50fffe219467 with data None 2023-01-17 12:32:09.083 DEBUG (MainThread) [custom_components.localtuya.common] [bfc...gnc] Dispatching event event_disconnected to sub-device 847127fffef500ca with data None 2023-01-17 12:32:09.084 DEBUG (MainThread) [custom_components.localtuya.common] [bfc...gnc] Dispatching event event_disconnected to sub-device 804b50fffe1a7e73 with data None 2023-01-17 12:32:09.085 DEBUG (MainThread) [custom_components.localtuya.common] [bfc...gnc] Dispatching event event_disconnected to sub-device 847127fffef501a1 with data None 2023-01-17 12:32:09.086 DEBUG (MainThread) [custom_components.localtuya.common] [bfc...gnc] Dispatching event event_disconnected to sub-device 804b50fffe1a8979 with data None 2023-01-17 12:32:09.089 DEBUG (MainThread) [custom_components.localtuya.common] [bfc...gnc] Dispatching event event_disconnected to sub-device 804b50fffe1a8b4f with data None 2023-01-17 12:32:09.242 DEBUG (MainThread) [custom_components.localtuya.common] [bfc...gnc] Disconnected - waiting for discovery broadcast 2023-01-17 12:32:09.263 DEBUG (SyncWorker_11) [custom_components.localtuya.common] [804...b4f] Received event event_disconnected from gateway with data None 2023-01-17 12:32:09.321 WARNING (SyncWorker_26) [custom_components.localtuya.sensor] [804...b4f] Entity sensor.radiator_bedroom_valve_status is requesting unknown DPS index 109 2023-01-17 12:32:09.354 WARNING (SyncWorker_19) [custom_components.localtuya.sensor] [804...b4f] Entity sensor.radiator_bedroom_temperature is requesting unknown DPS index 3 2023-01-17 12:32:09.373 WARNING (SyncWorker_35) [custom_components.localtuya.number] [804...b4f] Entity number.radiator_bedroom_target_temperature is requesting unknown DPS index 2 2023-01-17 12:32:09.381 DEBUG (SyncWorker_11) [custom_components.localtuya.common] [804...b4f] Disconnected 2023-01-17 12:32:09.382 WARNING (SyncWorker_11) [custom_components.localtuya.select] [804...b4f] Entity select.radiator_bedroom_valve_setting is requesting unknown DPS index 106 2023-01-17 12:32:09.803 WARNING (SyncWorker_11) [custom_components.localtuya.select] [804...b4f] Entity select.radiator_bedroom_valve_setting is requesting unknown DPS index 106 `
(5) ` 2023-01-17 12:59:12.476 DEBUG (MainThread) [custom_components.localtuya.common] [bfc...gnc] Received request request_remove from 847127fffef500ca with content None 2023-01-17 12:59:12.477 DEBUG (MainThread) [custom_components.localtuya.common] [bfc...gnc] Dispatching event event_disconnected to sub-device 847127fffef500ca with data None 2023-01-17 12:59:12.533 DEBUG (MainThread) [custom_components.localtuya.common] [bfc...gnc] Received request request_add from 847127fffef500ca with content {'dps': {109: None, 106: None, 3: None, 2: None}} 2023-01-17 12:59:12.534 DEBUG (MainThread) [custom_components.localtuya.common] [bfc...gnc] Dispatching event event_connected to sub-device 847127fffef500ca with data None 2023-01-17 12:59:12.534 DEBUG (MainThread) [custom_components.localtuya.common] [bfc...gnc] Dispatching event event_status_updated to sub-device 847127fffef500ca with data {'use_last_status': True} 2023-01-17 12:59:19.162 DEBUG (MainThread) [custom_components.localtuya.common] [bfc...gnc] Received request request_remove from 804b50fffe2536ca with content None 2023-01-17 12:59:19.162 DEBUG (MainThread) [custom_components.localtuya.common] [bfc...gnc] Dispatching event event_disconnected to sub-device 804b50fffe2536ca with data None 2023-01-17 12:59:19.201 DEBUG (MainThread) [custom_components.localtuya.common] [bfc...gnc] Received request request_add from 804b50fffe2536ca with content {'dps': {106: None, 109: None, 3: None, 2: None}} 2023-01-17 12:59:19.201 DEBUG (MainThread) [custom_components.localtuya.common] [bfc...gnc] Dispatching event event_connected to sub-device 804b50fffe2536ca with data None 2023-01-17 12:59:19.202 DEBUG (MainThread) [custom_components.localtuya.common] [bfc...gnc] Dispatching event event_status_updated to sub-device 804b50fffe2536ca with data {'use_last_status': True} 2023-01-17 12:59:33.679 DEBUG (MainThread) [custom_components.localtuya.common] [bfc...gnc] Received request request_remove from 804b50fffe1a7e73 with content None `
(6) ` 2023-01-17 13:35:16.835 DEBUG (MainThread) [custom_components.localtuya.common] [bfc...gnc] Connecting to gateway 192.168.33.50 2023-01-17 13:35:16.846 DEBUG (MainThread) [custom_components.localtuya.pytuya] [bfc...gnc] Started heartbeat loop 2023-01-17 13:35:16.846 DEBUG (MainThread) [custom_components.localtuya.pytuya] [bfc...gnc] Sending command heartbeat (device type: type_0d) 2023-01-17 13:35:16.847 DEBUG (MainThread) [custom_components.localtuya.pytuya] [bfc...gnc] Send payload: b'{}' 2023-01-17 13:35:16.849 DEBUG (MainThread) [custom_components.localtuya.pytuya] [bfc...gnc] Waiting for sequence number -100 2023-01-17 13:35:16.854 DEBUG (MainThread) [custom_components.localtuya.pytuya] [bfc...gnc] Dispatching message TuyaMessage(seqno=0, cmd=9, retcode=0, payload=b'', crc=2958142211, crcpassed=True) 2023-01-17 13:35:16.854 DEBUG (MainThread) [custom_components.localtuya.pytuya] [bfc...gnc] Got heartbeat response 2023-01-17 13:35:16.855 DEBUG (MainThread) [custom_components.localtuya.pytuya] [bfc...gnc] Decrypted payload: {} 2023-01-17 13:35:25.003 DEBUG (MainThread) [custom_components.localtuya.common] [804...b4f] Dispatching request request_remove to gateway with content None 2023-01-17 13:35:25.016 DEBUG (MainThread) [custom_components.localtuya.common] [bfc...gnc] Received request request_remove from 804b50fffe1a8b4f with content None 2023-01-17 13:35:25.016 DEBUG (MainThread) [custom_components.localtuya.common] [bfc...gnc] Dispatching event event_disconnected to sub-device 804b50fffe1a8b4f with data None 2023-01-17 13:35:25.017 DEBUG (MainThread) [custom_components.localtuya.common] [bfc...gnc] Received request request_remove from 804b50fffe1a8b4f with content None 2023-01-17 13:35:25.017 WARNING (MainThread) [custom_components.localtuya.common] [bfc...gnc] Invalid sub-device removal request for 804b50fffe1a8b4f 2023-01-17 13:35:25.107 DEBUG (MainThread) [custom_components.localtuya.sensor] [804...b4f] Adding sensor.radiator_bedroom_valve_status with configuration: {'friendly_name': 'Radiator Bedroom Valve Status', 'unit_of_measurement': '%', 'id': 109, 'platform': 'sensor'} `
(7) ` 2023-01-17 13:36:57.125 DEBUG (MainThread) [custom_components.localtuya.pytuya] [bfc...gnc] Sending command heartbeat (device type: type_0d) 2023-01-17 13:36:57.126 DEBUG (MainThread) [custom_components.localtuya.pytuya] [bfc...gnc] Send payload: b'{}' 2023-01-17 13:36:57.130 DEBUG (MainThread) [custom_components.localtuya.pytuya] [bfc...gnc] Waiting for sequence number -100 2023-01-17 13:36:57.138 DEBUG (MainThread) [custom_components.localtuya.pytuya] [bfc...gnc] Dispatching message TuyaMessage(seqno=0, cmd=9, retcode=0, payload=b'', crc=2958142211, crcpassed=True) 2023-01-17 13:36:57.138 DEBUG (MainThread) [custom_components.localtuya.pytuya] [bfc...gnc] Got heartbeat response 2023-01-17 13:36:57.139 DEBUG (MainThread) [custom_components.localtuya.pytuya] [bfc...gnc] Decrypted payload: {} 2023-01-17 13:37:00.297 DEBUG (MainThread) [custom_components.localtuya.common] [bfc...gnc] Received request request_set_dp from 847127fffef501a1 with content {'value': 55.0, 'dp_index': 2} 2023-01-17 13:37:00.297 DEBUG (MainThread) [custom_components.localtuya.common] [bfc...gnc] Received request request_set_dp from 847127fffef501a1 with content {'value': 55.0, 'dp_index': 2} 2023-01-17 13:37:00.297 DEBUG (MainThread) [custom_components.localtuya.pytuya] [bfc...gnc] Sending command set (device type: type_0d) 2023-01-17 13:37:00.298 DEBUG (MainThread) [custom_components.localtuya.pytuya] [bfc...gnc] Send payload: b'{"cid":"847127fffef501a1","ctype":0,"dps":{"2":55.0}}' 2023-01-17 13:37:00.300 DEBUG (MainThread) [custom_components.localtuya.pytuya] [bfc...gnc] Waiting for sequence number 29 2023-01-17 13:37:00.311 DEBUG (MainThread) [custom_components.localtuya.common] [bfc...gnc] Received request request_set_dp from 804b50fffe1a8979 with content {'value': 55.0, 'dp_index': 2} 2023-01-17 13:37:00.312 DEBUG (MainThread) [custom_components.localtuya.common] [bfc...gnc] Received request request_set_dp from 804b50fffe1a8979 with content {'value': 55.0, 'dp_index': 2} 2023-01-17 13:37:00.312 DEBUG (MainThread) [custom_components.localtuya.pytuya] [bfc...gnc] Sending command set (device type: type_0d) 2023-01-17 13:37:00.312 DEBUG (MainThread) [custom_components.localtuya.pytuya] [bfc...gnc] Send payload: b'{"cid":"804b50fffe1a8979","ctype":0,"dps":{"2":55.0}}' 2023-01-17 13:37:00.314 DEBUG (MainThread) [custom_components.localtuya.pytuya] [bfc...gnc] Waiting for sequence number 30 2023-01-17 13:37:00.324 DEBUG (MainThread) [custom_components.localtuya.pytuya] [bfc...gnc] Dispatching message TuyaMessage(seqno=29, cmd=13, retcode=0, payload=b'', crc=513162411, crcpassed=True) 2023-01-17 13:37:00.324 DEBUG (MainThread) [custom_components.localtuya.pytuya] [bfc...gnc] Dispatching sequence number 29 `
(8) ![image](https://user-images.githubusercontent.com/48317290/212897688-cb04c9f9-9d5b-4d31-81a2-4a2ac2160662.png)
(9) ![image](https://user-images.githubusercontent.com/48317290/212899912-bc4f226d-9747-4818-955f-65bb912f2252.png)
(10) `2023-01-17 13:50:44.481 DEBUG (MainThread) [custom_components.localtuya.pytuya] [bfc...gnc] Sending command heartbeat (device type: type_0d) 2023-01-17 13:50:44.482 DEBUG (MainThread) [custom_components.localtuya.pytuya] [bfc...gnc] Send payload: b'{}' 2023-01-17 13:50:44.637 DEBUG (MainThread) [custom_components.localtuya.pytuya] [bfc...gnc] Waiting for sequence number -100 2023-01-17 13:50:45.021 DEBUG (MainThread) [custom_components.localtuya.pytuya] [bfc...gnc] Connection lost: None 2023-01-17 13:50:45.024 DEBUG (MainThread) [custom_components.localtuya.common] [bfc...gnc] Dispatching event event_disconnected to sub-device 804b50fffe1a8b4f with data None 2023-01-17 13:50:45.026 DEBUG (MainThread) [custom_components.localtuya.common] [bfc...gnc] Dispatching event event_disconnected to sub-device 847127fffef500ca with data None 2023-01-17 13:50:45.049 DEBUG (MainThread) [custom_components.localtuya.common] [bfc...gnc] Dispatching event event_disconnected to sub-device 804b50fffe1a7e73 with data None 2023-01-17 13:50:45.050 DEBUG (MainThread) [custom_components.localtuya.common] [bfc...gnc] Dispatching event event_disconnected to sub-device 804b50fffe2bf6fc with data None 2023-01-17 13:50:45.051 DEBUG (MainThread) [custom_components.localtuya.common] [bfc...gnc] Dispatching event event_disconnected to sub-device 847127fffef501a1 with data None 2023-01-17 13:50:45.051 DEBUG (MainThread) [custom_components.localtuya.common] [bfc...gnc] Dispatching event event_disconnected to sub-device 804b50fffe1a8979 with data None 2023-01-17 13:50:45.052 DEBUG (MainThread) [custom_components.localtuya.common] [bfc...gnc] Dispatching event event_disconnected to sub-device 804b50fffe219467 with data None 2023-01-17 13:50:45.052 DEBUG (MainThread) [custom_components.localtuya.common] [bfc...gnc] Dispatching event event_disconnected to sub-device 804b50fffe2536ca with data None 2023-01-17 13:50:45.052 DEBUG (MainThread) [custom_components.localtuya.common] [bfc...gnc] Disconnected - waiting for discovery broadcast 2023-01-17 13:50:45.108 DEBUG (SyncWorker_7) [custom_components.localtuya.common] [804...b4f] Received event event_disconnected from gateway with data None 2023-01-17 13:50:45.110 DEBUG (SyncWorker_7) [custom_components.localtuya.common] [804...b4f] Disconnected 2023-01-17 13:50:45.165 WARNING (SyncWorker_21) [custom_components.localtuya.sensor] [804...b4f] Entity sensor.radiator_bedroom_valve_status is requesting unknown DPS index 109 2023-01-17 13:50:45.169 WARNING (SyncWorker_15) [custom_components.localtuya.sensor] [804...b4f] Entity sensor.radiator_bedroom_temperature is requesting unknown DPS index 3 `
(11) ` 2023-01-17 14:33:26.711 DEBUG (MainThread) [custom_components.localtuya.pytuya] [bfc...gnc] Got status update 2023-01-17 14:33:26.714 DEBUG (MainThread) [custom_components.localtuya.pytuya] [bfc...gnc] Decrypted payload: {"dps":{"2":150},"cid":"847127fffef500ca","type":"query","t":1673958806} 2023-01-17 14:33:26.714 DEBUG (MainThread) [custom_components.localtuya.pytuya] [bfc...gnc] Sub-device status update ignored because cid 847127fffef500ca is not added 2023-01-17 14:33:26.715 DEBUG (MainThread) [custom_components.localtuya.pytuya] [bfc...gnc] Re-add subdevice cid 847127fffef500ca 2023-01-17 14:33:27.506 DEBUG (MainThread) [custom_components.localtuya.pytuya] [bfc...gnc] Sending command heartbeat (device type: type_0d) 2023-01-17 14:33:27.506 DEBUG (MainThread) [custom_components.localtuya.pytuya] [bfc...gnc] Send payload: b'{}' 2023-01-17 14:33:27.509 DEBUG (MainThread) [custom_components.localtuya.pytuya] [bfc...gnc] Waiting for sequence number -100 2023-01-17 14:33:27.517 DEBUG (MainThread) [custom_components.localtuya.pytuya] [bfc...gnc] Dispatching message TuyaMessage(seqno=0, cmd=9, retcode=0, payload=b'', crc=2958142211, crcpassed=True) 2023-01-17 14:33:27.518 DEBUG (MainThread) [custom_components.localtuya.pytuya] [bfc...gnc] Got heartbeat response 2023-01-17 14:33:27.518 DEBUG (MainThread) [custom_components.localtuya.pytuya] [bfc...gnc] Decrypted payload: {} 2023-01-17 14:33:37.520 DEBUG (MainThread) [custom_components.localtuya.pytuya] [bfc...gnc] Sending command heartbeat (device type: type_0d) 2023-01-17 14:33:37.520 DEBUG (MainThread) [custom_components.localtuya.pytuya] [bfc...gnc] Send payload: b'{}' 2023-01-17 14:33:37.523 DEBUG (MainThread) [custom_components.localtuya.pytuya] [bfc...gnc] Waiting for sequence number -100 2023-01-17 14:33:37.558 DEBUG (MainThread) [custom_components.localtuya.pytuya] [bfc...gnc] Dispatching message TuyaMessage(seqno=0, cmd=9, retcode=0, payload=b'', crc=2958142211, crcpassed=True) 2023-01-17 14:33:37.559 DEBUG (MainThread) [custom_components.localtuya.pytuya] [bfc...gnc] Got heartbeat response 2023-01-17 14:33:37.560 DEBUG (MainThread) [custom_components.localtuya.pytuya] [bfc...gnc] Decrypted payload: {} 2023-01-17 14:33:37.915 DEBUG (MainThread) [custom_components.localtuya.pytuya] [bfc...gnc] Dispatching message TuyaMessage(seqno=0, cmd=8, retcode=0, payload=b'3.3\x00\x00\x00\x00\x00\x01\xc2F\x00\x00\x00\x01\xb2]R\xa7\x84n\xb7\x80\xbb\xb1\xaar\x08\x7fFb\xd1\n\xec|pk\x19\x17\x16\xc8\xd1\xd6\xfa\x8d\xfe\xa3\x04\x1e\x98\xd8\x95E\xd0\x81YT\xa0{\x98V1\xa2\xa2{\xae2sCw*\x82+\xf4!\xab\x15k\x1d', crc=2091098169, crcpassed=True) 2023-01-17 14:33:37.916 DEBUG (MainThread) [custom_components.localtuya.pytuya] [bfc...gnc] Got status update 2023-01-17 14:33:37.917 DEBUG (MainThread) [custom_components.localtuya.pytuya] [bfc...gnc] Decrypted payload: {"dps":{"2":155},"cid":"847127fffef500ca","t":1673958817} 2023-01-17 14:33:37.918 DEBUG (MainThread) [custom_components.localtuya.common] [bfc...gnc] Dispatching event event_status_updated to sub-device 847127fffef500ca with data {'2': 155} `
Anycubic commented 1 year ago

So I think I was on to something: gateway disconnected, sub-devices disconnected, errors about unknown DPS appear (1), gateway reconnects - i believe (2), sub-devices did not reconnect automatically afterwards, only with a reload of the device (3). But then it happened again (4) and the gateway did not reconnect (absolutely no log entries for its device id) and a reload of the sub-device does not work anymore(5). And here is where it gets interesting - a reload of the gateway (6) starts producing normal logs(7)... except they appear as unavailable in the UI, even though the history shows data for them (8). After I went in the Smart Life app and changed something the status of the sub-device in HA is magically not unavailable anymore and the history is also updated with a new gap ?! - (9) Apparently this also works if a change is made on the TRV itself. So any status update from the sub-device will do. With this info I can also find another disconnect event dispatched from the gateway to the sub-devices(10)

So my line of thinking now is that if the gateway gets disconnected from localtuya the sub-devices are not added back until they send an update themselves or are reloaded (11). Which I think results in 2 courses of actions:

  1. identify why the gateway does not reconnect sometimes
  2. re-add subdevices to the gateway then it reconnects itself

@leeyuentuen , does this make sense?

(1) (2) (3) (4) (5) (6) (7) (8) (9) (10) (11)

@alexualbu this is 100% what I'm also seeing with 3.6.4 beta. Was this fixed in 3.6.4 stable maybe?

alexualbu commented 1 year ago

@Anycubic , i don't believe there were any changes to 3.6.4 on top of the beta.

On the actual issue, i have an automation running right now that reloads the sub-device when it becomes unavailable (and if it fails it attempts to also reload the gateway) and it seems to be working flawlessly. I expect my hardware set-up is problematic in the sense that the gateway doesn't have great connection to the devices and this is why it's more obvious (it happens many times during the day), but I am pretty sure there is some issue with automatically reconnecting the sub-devices. I was pretty distracted by work (😢 ) this past week, but I hope come weekend I can spend some time to check out the code and try some things since it seems easy to reproduce. I'll keep you updated.

Anycubic commented 1 year ago

@Anycubic , i don't believe there were any changes to 3.6.4 on top of the beta.

On the actual issue, i have an automation running right now that reloads the sub-device when it becomes unavailable (and if it fails it attempts to also reload the gateway) and it seems to be working flawlessly. I expect my hardware set-up is problematic in the sense that the gateway doesn't have great connection to the devices and this is why it's more obvious (it happens many times during the day), but I am pretty sure there is some issue with automatically reconnecting the sub-devices. I was pretty distracted by work (😢 ) this past week, but I hope come weekend I can spend some time to check out the code and try some things since it seems easy to reproduce. I'll keep you updated.

@alexualbu could you please share you automation code? Giving the situation it could be very useful. I also don't know whether it is better to open a new issue, with 3.6.4, when adding new devices (yes, I had to start again from scratch, upgraded to 3.6.4 and all of the devices were unavailable with no solution...) so when adding new devices recognised DPS are very erratic: all devices are the same, but some of them are with all of the DPSs, other with just 2 or 3 of them. I never saw such a behaviour before

alexualbu commented 1 year ago

@Anycubic , here's the automation YAML

Automation code alias: Reload LocalTuya Sub-device when unavailable description: "" trigger: - platform: state entity_id: - select.radiator_bedroom_valve_setting #use whatever entity of the device works for you to: unavailable for: hours: 0 minutes: 0 seconds: 30 #give it some time to recover on its own condition: [] action: - service: system_log.write data: message: >- {{state_attr(trigger.entity_id, 'friendly_name')}} became unavailable. Reloading... level: warning - repeat: while: - condition: template value_template: "{{ states(trigger.entity_id) == 'unavailable' }}" sequence: - service: homeassistant.reload_config_entry data: entry_id: |- {% set config_entries = { 'select.radiator_bedroom_valve_setting': '' } %} {{ config_entries[trigger.entity_id] }} - delay: hours: 0 minutes: 0 seconds: 10 #give it time to actually reload milliseconds: 0 - if: - condition: template value_template: "{{ states(trigger.entity_id) == 'unavailable' }}" alias: Sub-device still unavailable then: - service: homeassistant.reload_config_entry data: entry_id: alias: Reload Tuya Gateway - service: system_log.write data: level: warning message: >- {{state_attr(trigger.entity_id, 'friendly_name')}} still unavailable. Reloading gateway... - delay: hours: 0 minutes: 0 seconds: 5 #give the gateway time ro reload milliseconds: 0 alias: Reload Tuya Gateway if device still unavailable alias: Reload sub-advice while it's unavailable mode: queued max: 20 trace: stored_traces: 20

Interesting behavior with 3.6.4 - i haven't done the actual update, but it sounds very strange, like the config entries get corrupted. I'll give it a try hopefully later today.

leeyuentuen commented 1 year ago

I've created a new beta version. What I have tried is disconnecting the power of my gateway, the device became unavailable, reconnect the gateway and it will automatically reconnect (to simulate wifi disconnection?).

2023-01-25 21:33:10.358 DEBUG (MainThread) [custom_components.localtuya.pytuya] [bf4...2qe] Connection lost: None
2023-01-25 21:33:10.358 DEBUG (MainThread) [custom_components.localtuya.common] [bf4...2qe] Dispatching event event_disconnected to sub-device a4c138669e188bb2 with data None
2023-01-25 21:33:10.359 DEBUG (MainThread) [custom_components.localtuya.common] [bf4...2qe] Disconnected (TuyaGatewayDevice) - event dispatch event_disconnected
2023-01-25 21:33:10.359 DEBUG (MainThread) [custom_components.localtuya.common] [bf4...2qe] Disconnected (TuyaGatewayDevice) - waiting for discovery broadcast
2023-01-25 21:33:10.359 DEBUG (SyncWorker_4) [custom_components.localtuya.common] [a4c...bb2] Received event event_disconnected from gateway with data None
2023-01-25 21:33:10.360 WARNING (SyncWorker_0) [custom_components.localtuya.sensor] [a4c...bb2] Entity sensor.local_motion_sensor_bedroom_battery is requesting unknown DPS index 4
2023-01-25 21:33:10.362 WARNING (SyncWorker_0) [custom_components.localtuya.sensor] [a4c...bb2] Entity sensor.local_motion_sensor_bedroom_timeout is requesting unknown DPS index 10
2023-01-25 21:33:10.365 WARNING (SyncWorker_3) [custom_components.localtuya.binary_sensor] [a4c...bb2] Entity binary_sensor.local_motion_sensor_bedroom is requesting unknown DPS index 1
2023-01-25 21:33:10.366 DEBUG (SyncWorker_4) [custom_components.localtuya.common] [a4c...bb2] Disconnected TuyaSubDevice: localtuya_a4c138669e188bb2
2023-01-25 21:33:10.368 WARNING (SyncWorker_3) [custom_components.localtuya.binary_sensor] [a4c...bb2] Entity binary_sensor.local_motion_sensor_bedroom is requesting unknown DPS index 1
2023-01-25 21:33:10.375 DEBUG (MainThread) [custom_components.localtuya.common] [bf4...2qe] Connecting to gateway 172.16.0.60
2023-01-25 21:33:11.226 DEBUG (MainThread) [custom_components.localtuya.pytuya] [bf4...2qe] Heartbeat failed due to timeout, disconnecting
2023-01-25 21:33:31.433 WARNING (MainThread) [custom_components.localtuya.common] [bf4...2qe] Connect to gateway 172.16.0.60 failed
2023-01-25 21:34:16.305 DEBUG (MainThread) [custom_components.localtuya.common] [bf4...2qe] Connecting to gateway 172.16.0.60
2023-01-25 21:34:16.417 DEBUG (MainThread) [custom_components.localtuya.pytuya] [bf4...2qe] Started heartbeat loop
2023-01-25 21:34:16.417 DEBUG (MainThread) [custom_components.localtuya.pytuya] [bf4...2qe] Sending command heartbeat (device type: type_0d)
2023-01-25 21:34:16.417 DEBUG (MainThread) [custom_components.localtuya.pytuya] [bf4...2qe] Send payload: b'{}'
2023-01-25 21:34:16.419 DEBUG (MainThread) [custom_components.localtuya.pytuya] [bf4...2qe] Waiting for sequence number -100
2023-01-25 21:34:16.452 DEBUG (MainThread) [custom_components.localtuya.pytuya] [bf4...2qe] Dispatching message TuyaMessage(seqno=0, cmd=9, retcode=0, payload=b'', crc=2958142211, crcpassed=True)
2023-01-25 21:34:16.452 DEBUG (MainThread) [custom_components.localtuya.pytuya] [bf4...2qe] Got heartbeat response
2023-01-25 21:34:16.454 DEBUG (MainThread) [custom_components.localtuya.pytuya] [bf4...2qe] Decrypted payload: {}
2023-01-25 21:34:26.456 DEBUG (MainThread) [custom_components.localtuya.pytuya] [bf4...2qe] Sending command heartbeat (device type: type_0d)
2023-01-25 21:34:26.456 DEBUG (MainThread) [custom_components.localtuya.pytuya] [bf4...2qe] Send payload: b'{}'
2023-01-25 21:34:26.457 DEBUG (MainThread) [custom_components.localtuya.pytuya] [bf4...2qe] Waiting for sequence number -100
2023-01-25 21:34:26.470 DEBUG (MainThread) [custom_components.localtuya.pytuya] [bf4...2qe] Dispatching message TuyaMessage(seqno=0, cmd=9, retcode=0, payload=b'', crc=2958142211, crcpassed=True)
2023-01-25 21:34:26.470 DEBUG (MainThread) [custom_components.localtuya.pytuya] [bf4...2qe] Got heartbeat response
2023-01-25 21:34:26.472 DEBUG (MainThread) [custom_components.localtuya.pytuya] [bf4...2qe] Decrypted payload: {}
2023-01-25 21:34:35.120 DEBUG (MainThread) [custom_components.localtuya.pytuya] [bf4...2qe] Dispatching message TuyaMessage(seqno=0, cmd=8, retcode=0, payload=b'3.3\x00\x00\x00\x00\x00\x00\xee.\x00\x00\x00\x01\xee {\xb1k\x1c\x96\\\xc9 5\xb1\x93\xf2\xc0h\xc7\xd0\xc4\x9c3\x98_\x7f\xff\xc5E\xae\x7f\xc3\x82I\xd9\x0b_)\xc2\xb3\x134\x9d\x93\xd6\xff\xcb\xc7\xc6g\xb3\xde}l\x86z\xa1\xef>\x9e\x0be\xf68\xd0#', crc=41981344, crcpassed=True)
2023-01-25 21:35:04.951 DEBUG (MainThread) [custom_components.localtuya.pytuya] [bf4...2qe] Got status update
2023-01-25 21:35:04.952 DEBUG (MainThread) [custom_components.localtuya.pytuya] [bf4...2qe] Decrypted payload: {"dps":{"1":"pir"},"cid":"a4c138669e188bb2","t":1674682505}
2023-01-25 21:35:04.952 DEBUG (MainThread) [custom_components.localtuya.common] [bf4...2qe] Dispatching event event_status_updated to sub-device a4c138669e188bb2 with data {'1': 'pir'}
2023-01-25 21:35:04.953 DEBUG (SyncWorker_1) [custom_components.localtuya.common] [a4c...bb2] Received event event_status_updated from gateway with data {'1': 'pir'}
2023-01-25 21:35:04.964 DEBUG (MainThread) [custom_components.localtuya.sensor] [a4c...bb2] Entity Local Motion Sensor Bedroom Battery - Additional attributes: {'raw_state': 100}
2023-01-25 21:35:04.964 DEBUG (MainThread) [custom_components.localtuya.sensor] [a4c...bb2] Entity Local Motion Sensor Bedroom Timeout - Additional attributes: {'raw_state': '30s'}
2023-01-25 21:35:04.965 DEBUG (MainThread) [custom_components.localtuya.binary_sensor] [a4c...bb2] Entity Local Motion Sensor Bedroom - Additional attributes: {'raw_state': 'pir'}
leeyuentuen commented 1 year ago

this is a first step to see if the gateway work correctly. afterwards i will reload the sub device, but need to be sure that the gateway is working correctly

atm the sub device could be unavailable, but after the refresh time of the device, you should get the value from the device. but later, after gateway reconnect, i can maybe force them to get the value of the subdevice

Anycubic commented 1 year ago

very good! I'll test tomorrow and will report back

Anycubic commented 1 year ago

this is a first step to see if the gateway work correctly. afterwards i will reload the sub device, but need to be sure that the gateway is working correctly

atm the sub device could be unavailable, but after the refresh time of the device, you should get the value from the device. but later, after gateway reconnect, i can maybe force them to get the value of the subdevice

3.6.5 beta 1 is working as intended! I switched of my ZIgbee gateway, TRV valves reconnected by themselves

Anycubic commented 1 year ago

@leeyuentuen unfortunately it seems there is still a problem with 1.6.5 beta. Indeed devices come back after switching off/on the gateway, but when they came back are in zombie state. Restarting HA or the plugin doesn't work to fix the issue. The only thing which works is doing anything from Smart Life app (i.e. switch off/on the devices) they will get back to life also on HA

leeyuentuen commented 1 year ago

let me later try to fix reconnect subdevices and see if this help. but it seems gateway already works here

leeyuentuen commented 1 year ago

@leeyuentuen unfortunately it seems there is still a problem with 1.6.5 beta. Indeed devices come back after switching off/on the gateway, but when they came back are in zombie state. Restarting HA or the plugin doesn't work to fix the issue. The only thing which works is doing anything from Smart Life app (i.e. switch off/on the devices) they will get back to life also on HA

but if you wait for a long time (1-2 hours) should it recover the value? i know for my sensor. it will not instantly send update of the value of the temperature. maybe after 30 min or after 1 hour.

but same like previous post, i can try to force to update

Anycubic commented 1 year ago

@leeyuentuen unfortunately it seems there is still a problem with 1.6.5 beta. Indeed devices come back after switching off/on the gateway, but when they came back are in zombie state. Restarting HA or the plugin doesn't work to fix the issue. The only thing which works is doing anything from Smart Life app (i.e. switch off/on the devices) they will get back to life also on HA

but if you wait for a long time (1-2 hours) should it recover the value? i know for my sensor. it will not instantly send update of the value of the temperature. maybe after 30 min or after 1 hour.

but same like previous post, i can try to force to update

But I see a big issue in this scenario: I could not be aware that the gateway went off line and on line for any reason, giving commands to valves and being not aware at all that those commands were not executed. I mean, everything seems working fine except that it doesn't. I myself wasn't aware of this issue, and I think that more than hour had passed after I power cycled the gateway

leeyuentuen commented 1 year ago

At the moment, the problem is that the 'gateway is offline' when it is back online we don't have the data in the gateway, we need to wait that the subdevice (in this case the trv) to let us know what the data is. for my motion sensor i've got here an example afbeelding

and i got this data in my debug:

2023-01-28 19:39:03.364 DEBUG (SyncWorker_2) [custom_components.localtuya.common] [a4c...bb2] Received event event_status_updated from gateway with data {'1': 'pir'}
2023-01-28 19:39:03.377 DEBUG (MainThread) [custom_components.localtuya.binary_sensor] [a4c...bb2] Entity Local Motion Sensor Bedroom - Additional attributes: {'raw_state': 'pir'}

so I got only the PIR state (motion detection) but didn't get the battery state or the timeout value. I need to wait for it.

The other solution could be using caching. so if we don't restart home assistant, the last know value will be showing them.

Anycubic commented 1 year ago

@Anycubic , here's the automation YAML

Automation code Interesting behavior with 3.6.4 - i haven't done the actual update, but it sounds very strange, like the config entries get corrupted. I'll give it a try hopefully later today.

@leeyuentuen @alexualbu this issue is still there in 3.6.5 beta 2. DPS ID are populated only after they have been "touched" at least once from Smart Life app, otherwise they will not appear in the config flow.

alexualbu commented 1 year ago

@anycubic - i updated to 3.6.5. sub-devices worked normally after that. the issue you mention about DPs not appearing in some sub devices was there earlier - i am not sure how DP detection works, but some of them (inputs) have to be touched from smartlife to ensure they appear.

@leeyuentuen , regarding the reconnection issue, on my side i couldn't confirm yet if the sub-devices actually get reloaded on their own - ran without the automation for a few hours and they didn't. i'll try to test on the dev instance to confirm. however there is a new issue after 3.6.5 that sometimes even a reload of the sub-device will not bring it back to life (also need to investigate more here)

Anycubic commented 1 year ago

@alexualbu I confirm after gateway off/on cycle devices will never get back by themselves, which is really dangerous since I have automation using them. Also the 2nd gateway bug is really a big one (devices not working if plugged to a 2nd gateway).

leeyuentuen commented 1 year ago

@alexualbu I confirm after gateway off/on cycle devices will never get back by themselves, which is really dangerous since I have automation using them. Also the 2nd gateway bug is really a big one (devices not working if plugged to a 2nd gateway).

@Anycubic for the second gateway, have you try the beta version 3.7? because during the change of the protocol to 3.4 i found something that could maybe give issue with second gateway. i've reply on this issue: https://github.com/leeyuentuen/localtuya/issues/36