smarthomej / addons

SmartHome/J addons for openHAB
Eclipse Public License 2.0
59 stars 23 forks source link

Tuya Device is discovered, but not coming online #366

Closed Linzm99 closed 2 years ago

Linzm99 commented 2 years ago

Hi I used your Tuya binding and my project did come online and the discovery also finds my airconditioner and its channels. The problem is that the device isnt coming online. I can see the offline indicator flickering every few seconds. I guess this happens when the device broadcasts its IP address. Any idea why this isnt working? How can I debug this issue properly?

Thanks in advance!

BigGeorgeTx commented 2 years ago

In troubleshootinng devices, I found it helpful to check the version (3.1 vs 3.3). I had a few that were 3.1 and they didn't come online until I switched them to 3.1. Also with some I had to manually enter the IP address. (I'm not a developer, just another user who has made good use of this binding).

J-N-K commented 2 years ago

I would suggest you set the log level to trace and show what is send and received to the device. And please let me know what the productId of the device is.

owl770 commented 2 years ago

This is very similar to #358 - the issue is happening again (daily). I manage to get the tuyaDevice Thing to go online (by disabling it in OH and leaving it that way for many hours and then re-enabling it). It stays online and works normally until about 08:53AM (+/- a few minutes). FYI - I am located in the Australia/Sydney timezone.

My tuyaDevice Thing was discovered automatically and is configured as follows:

UID: tuya:tuyaDevice:81446666c82b96cac30d
label: Pool pumps
thingTypeUID: tuya:tuyaDevice
configuration:
  protocol: "3.3"
  productId: 3yj6z55c052okmi5
  deviceId: 81446666xxxxxxxac30d (partially redacted)
  localKey: xxxxxxxxxxxxxxxx (redacted)
channels:
  - id: switch_1
    channelTypeUID: tuya:switch
    label: switch_1
    description: null
    configuration:
      dp: 1
  - id: countdown_1
    channelTypeUID: tuya:number
    label: countdown_1
    description: null
    configuration:
      dp: 9
      max: 86400
      min: 0

I am running version 3.2.12 of the tuya binding on openhabian 3.2.0.

Something to note is that in this environment, internet access is disabled at 23:00 and re-enabled at 07:00. There are also other smart switches in the environment that are not yet incorporated into the openHAB environment (the intention is that once I get the first one working reliably, I will add the rest). As of today, I have changed the settings so that the internet is on 24/7 to see if that has a positive effect.

Things to note from the event log (shown below) are:

My latest event log with TRACE level logging is: https://www.dropbox.com/s/m0w1wr0sv90lddw/events-trimmed.log?dl=0

My latest openHAB log is: https://www.dropbox.com/s/hmg5n8lfxzjwwcl/openhab-trimmed.log?dl=0

Not sure if this is useful, but this is the two logs combined in chronological order: https://www.dropbox.com/s/sqf7vii8hos0qnn/combined-trimmed.log?dl=0

Once the tuyaDevice is ONLINE and stays ONLINE, it works as expected.

Any assistance is greatly appreciated. If you need more diagnostics, please let me know because it seems quite reproducible (every 24 hours).

owl770 commented 2 years ago

@J-N-K This may be relevant...it appears the switch changed its IP address???

At 08:53:23.261 it sent a pong as 192.168.68.114 but at 08:53:33.086 it sent a packet that contained an IP address of 192.168.68.113

2022-05-19 08:53:23.261 [TRACE] [rnal.local.handlers.HeartbeatHandler] - 81446666c82b96cac30d/192.168.68.114:6668: Received pong
.
.
.
2022-05-19 08:53:33.086 [TRACE] [.internal.local.handlers.TuyaDecoder] - udpListener/: Decoded raw payload: {"ip":"192.168.68.113","gwId":"81446666c82b96cac30d","active":2,"ability":0,"mode":0,"encrypt":true,"productKey":"keyqhqmt59kctur3","version":"3.3"}

I don't know if it actually did change its IP address - I'm not onsite at the moment. I'll try and find that out. The router uses DHCP. I might try assigning its IP address in the router (by MAC address) so that it can't change.

EDIT: I have assigned the switch an IP address of 192.168.68.203 that now should not change. The tuyaDevice Thing is online. Let's see how this goes.

J-N-K commented 2 years ago

A switching IP address could indeed cause issues. I'll check if the code that processes the local discovery is not correctly handling IP address changes. If the internal device is not updated, it'll still send to the old address, fail and the device will go offline. With the next discovery it comes back online and we start again. So that would explain your observation of the "flickering state".

owl770 commented 2 years ago

Thanks. With the fixed IP address, so far so good. It has not gone OFFLINE yet. Fingers crossed.