plasticrake / homebridge-tplink-smarthome

TP-Link Smarthome Plugin for Homebridge
MIT License
467 stars 69 forks source link

TCP Timeout for devices that are turned off #70

Open aantono opened 5 years ago

aantono commented 5 years ago

Expected Behavior

I have a couple of TP Link LB130 Smart Bulbs that are frequently being turned off using a wall switch (an expected and supported behavior by the bulb). I expect that when they are powered off using a wall switch, the Homebridge would just ignore them, and continues to function.

Current Behavior

Currently, when the bulbs are powered off, the entire Homebridge integration is glitching, causing all devices to stay in "No Response" or "Updated" status.

The logs show:

[10/25/2018, 1:18:08 PM] [TplinkSmarthome.API] TCP Timeout                                                                                                                                                              
[10/25/2018, 1:18:08 PM] [TplinkSmarthome.API] TCP Timeout                                                                                                                                                              
[10/25/2018, 1:18:08 PM] [TplinkSmarthome.API] [Jacuzzi] device.send() Error: TCP Timeout                                                                                                                               
[10/25/2018, 1:18:08 PM] [TplinkSmarthome.API] [Jacuzzi] device.send() Error: TCP Timeout                                                                                                                               
[10/25/2018, 1:18:08 PM] [TplinkSmarthome] [Jacuzzi] getLightState                                                                                                                                                      
[10/25/2018, 1:18:08 PM] [TplinkSmarthome] Error: TCP Timeout                                                                                                                                                           
    at Timeout._onTimeout (/usr/local/lib/node_modules/homebridge-tplink-smarthome/node_modules/tplink-smarthome-api/lib/client.js:249:20)                                                                              
    at ontimeout (timers.js:425:11)                                                                                                                                                                                     
    at tryOnTimeout (timers.js:289:5)                                                                                                                                                                                   
    at listOnTimeout (timers.js:252:5)                                                                                                                                                                                  
    at Timer.processTimers (timers.js:212:10)                                                                                                                                                                           
(node:86) UnhandledPromiseRejectionWarning: Error: TCP Timeout                                                                                                                                                          
    at Timeout._onTimeout (/usr/local/lib/node_modules/homebridge-tplink-smarthome/node_modules/tplink-smarthome-api/lib/client.js:249:20)                                                                              
    at ontimeout (timers.js:425:11)                                                                                                                                                                                     
    at tryOnTimeout (timers.js:289:5)                                                                                                                                                                                   
    at listOnTimeout (timers.js:252:5)                                                                                                                                                                                  
    at Timer.processTimers (timers.js:212:10)                                                                                                                                                                           
(node:86) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 16)                 

Steps to Reproduce (for bugs)

Installed Homebridge on QNAP NAS using a Docker Container: marcoraddatz/homebridge:latest Configured all the plugins (see config section below) Powered off LB130 bulbs Opened iOS Home app, and see all components stuck in "No Response" state. (When the light bulbs are powered, everything works as expected)

Versions

Configuration

{
  "bridge": {
    "name": "Homebridge",
    "username": "XXXXXXX",
    "port": 51826,
    "pin": "XXX-XX-XXX"
  },
  "description": "This file configures support for Nest, TP-Link Devices.",
  "platforms": [
    {
      "platform": "TplinkSmarthome",
      "name": "TplinkSmarthome"
    }
  ],
  "accessories": [

  ]
}

Homebridge Log / Command Output

/root/.homebridge/.env not found.                                                                                                                                                                                       
Default env variables will be used.                                                                                                                                                                                     
/root/.homebridge/package.json not found.                                                                                                                                                                               
Installing plugins from /root/.homebridge/install.sh.                                                                                                                                                                   
+ homebridge-tplink-smarthome@3.11.0                                                                                                                                                                                    
updated 1 package in 4.708s                                                                                                                                                                                             
+ homebridge-nest@2.1.4                                                                                                                                                                                                 
updated 1 package in 22.934s                                                                                                                                                                                            
+ homebridge-people@0.6.2                                                                                                                                                                                               
updated 1 package in 7.275s                                                                                                                                                                                             
[10/25/2018, 1:37:45 PM] Loaded config.json with 0 accessories and 3 platforms.                                                                                                                                         
[10/25/2018, 1:37:45 PM] ---                                                                                                                                                                                            
[10/25/2018, 1:37:47 PM] Loaded plugin: homebridge-nest                                                                                                                                                                 
[10/25/2018, 1:37:47 PM] Registering platform 'homebridge-nest.Nest'                                                                                                                                                    
[10/25/2018, 1:37:47 PM] ---                                                                                                                                                                                            
[10/25/2018, 1:37:48 PM] Loaded plugin: homebridge-people
[10/25/2018, 1:37:48 PM] Registering platform 'homebridge-people.People'                                                                                                                                                
[10/25/2018, 1:37:48 PM] Registering accessory 'homebridge-people.PeopleAccessory'                                                                                                                                      
[10/25/2018, 1:37:48 PM] Registering accessory 'homebridge-people.PeopleAllAccessory'                                                                                                                                   
[10/25/2018, 1:37:48 PM] ---                                                                                                                                                                                            
[10/25/2018, 1:37:49 PM] Loaded plugin: homebridge-tplink-smarthome                                                                                                                                                     
[10/25/2018, 1:37:49 PM] Registering platform 'homebridge-tplink-smarthome.TplinkSmarthome'                                                                                                                             
[10/25/2018, 1:37:49 PM] ---                                                                                                                                                                                            
[10/25/2018, 1:37:49 PM] Loading 3 platforms...                                                                                                                                                                         
[10/25/2018, 1:37:49 PM] [Nest] Initializing Nest platform...                                                                                                                                                           
[10/25/2018, 1:37:49 PM] [Nest] Fetching Nest devices.                                                                                                                                                                  
[10/25/2018, 1:37:49 PM] [TplinkSmarthome] Initializing TplinkSmarthome platform...                                                                                                                                     
[10/25/2018, 1:37:49 PM] [TplinkSmarthome] homebridge-tplink-smarthome v3.11.0, node v10.11.0, homebridge v0.4.45                                                                                                       
[10/25/2018, 1:37:49 PM] [People] Initializing People platform...                                                                                                                                                       
[10/25/2018, 1:37:49 PM] [People] Initializing platform accessory 'Alla'...                                                                                                                                             
[10/25/2018, 1:37:49 PM] [People] Initializing platform accessory 'Nina'...                                                                                                                                             
[10/25/2018, 1:37:49 PM] [People] Initializing platform accessory 'Alex'...                                                                                                                                             
[10/25/2018, 1:37:49 PM] [People] Initializing platform accessory 'Anyone'...                                                                                                                                           
[10/25/2018, 1:37:49 PM] [People] WebHook: Started server on port '51828'.                                                                                                                                              
[10/25/2018, 1:37:49 PM] Loading 0 accessories...        
[10/25/2018, 1:37:49 PM] [TplinkSmarthome] Configuring cached accessory: [Garage Door Power] REDACTED                                              
[10/25/2018, 1:37:49 PM] [TplinkSmarthome] Configuring cached accessory: [Master Room Light] REDACTED                                              
[10/25/2018, 1:37:49 PM] [TplinkSmarthome] Configuring cached accessory: [Master Shower] REDACTED                                                  
[10/25/2018, 1:37:49 PM] [TplinkSmarthome] Configuring cached accessory: [Jaquizee] undefined REDACTED                                                                                      
[10/25/2018, 1:37:52 PM] [Nest] initing thermostat "Dining Room Thermostat": REDACTED                             
[10/25/2018, 1:37:52 PM] [Nest] initing thermostat "Master Bedroom Thermostat": REDACTED                          
[10/25/2018, 1:37:52 PM] [Nest] Initializing platform accessory 'Dining Room Thermostat'...                                                                                                                             
[10/25/2018, 1:37:52 PM] [Nest] Initializing platform accessory 'Master Bedroom Thermostat'... 
...
[10/25/2018, 1:39:35 PM] [TplinkSmarthome.API] [Master Shower] device.send() Error: connect EHOSTUNREACH <IP:9999>                                                                                              
[10/25/2018, 1:39:35 PM] [TplinkSmarthome] [Master Shower] getLightState                                                                                                                                                
[10/25/2018, 1:39:35 PM] [TplinkSmarthome] { Error: connect EHOSTUNREACH <IP:9999>                                                                                                                              
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1113:14)                                                                                                                                                     
  errno: 'EHOSTUNREACH',                                                                                                                                                                                                
  code: 'EHOSTUNREACH',                                                                                                                                                                                                 
  syscall: 'connect',                                                                                                                                                                                                   
  address: '<IP>',                                                                                                                                                                                              
  port: 9999 }                                                                                                                                                                                                          
[10/25/2018, 1:39:35 PM] [TplinkSmarthome.API] [Master Shower] device.send() Error: connect EHOSTUNREACH <IP:9999>                                                                                              
(node:86) UnhandledPromiseRejectionWarning: Error: connect EHOSTUNREACH <IP:9999>                                                                                                                               
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1113:14)                                                                                                                                                     
(node:86) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled wit
h .catch(). (rejection id: 24)
aantono commented 5 years ago

Linking #44 as it has some similar traits!

VitaliyR commented 5 years ago

Happened to me as well. The device (HS110) is not offline and available while homebridge says that device isn't available.

yenoromm commented 5 years ago

Had the same issue with homebridge in docker on my qnap. Went back to a pi a couple of days ago and no issues since. Plugin doesn’t seem at fault as both this and EWeLink we’re having issue in same docket setup as you.

mrblack7 commented 5 years ago

This happens when the device is offline or unreachable (or unreliable) on the network.

I have a HS100 and can replicate the issue by turning off the device physically.

plasticrake commented 5 years ago

I guess I'm not understanding what you expect for behavior. If the device is offline, the network connection is going to error. The UnhandledPromiseRejectionWarning is concerning, but I don't see that in my testing. If you see that warning please provide your environment details/versions and exactly how to reproduce so I can research.

There used to be a way to set a device as unreachable in homebridge but it was deprecated (Some details here: nfarina/homebridge#2078).

If i unscrew the bulb, and try to query or change a setting I get the error below. As soon as I screw the bulb back in, it resumes working in homekit.

[1/23/2019, 11:07:52 AM] [TPLink.API] TCP Timeout
[1/23/2019, 11:07:52 AM] [TPLink.API] [Lamp] device.send() Error: TCP Timeout
[1/23/2019, 11:07:52 AM] [TPLink] [Lamp] getColorTemperature
[1/23/2019, 11:07:52 AM] [TPLink] Error: TCP Timeout
    at Timeout.setTimeout [as _onTimeout] (/Users/plasticrake/Code/homebridge-tplink-smarthome/node_modules/tplink-smarthome-api/lib/client.js:228:20)
    at ontimeout (timers.js:436:11)
    at tryOnTimeout (timers.js:300:5)
    at listOnTimeout (timers.js:263:5)
    at Timer.processTimers (timers.js:223:10)
petedavey commented 4 months ago

Same problem here. Lightbulbs with WiFi also connected to wall switch so if I kill power to the bulbs then we should be able to specify these as devices that may lose connection and to stop filling the screen logs with this kind of information. It may be useful to devices that are meant to be on 24/7 but sometimes they aren't (wifi lightbulbs, for example). Maybe different debug levels to defeat them?