rospogrigio / localtuya

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

Errors while setting up localtuya platform #1007

Open donburch888 opened 1 year ago

donburch888 commented 1 year ago

The problem

I have noticed several error messages which appear in the System > Logs immediately on any Home Assistant restart.

Normally these don't seem to have a noticable effect for me; however sometimes devices become temporarily unavailable, and I have lately been getting thousands of the following message - so wanting to eliminate possible causes.

ERROR (MainThread) [homeassistant.components.websocket_api.http.connection] [548267640480] Client exceeded max pending messages [2]: 2048

Environment

Steps to reproduce

  1. Restart of Home Assistant
  2. check System > Logs

Configuration configuration.yaml or config_flow

# Loads default set of integrations. Do not remove.
default_config:

# Text to speech
tts:
  - platform: google_translate

automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml

# Example configuration.yaml entry with all entry types (delete/comment out as necessary)
sensor:
  - platform: systemmonitor
    resources:
      - type: processor_use
      - type: processor_temperature
      - type: last_boot
      - type: disk_use_percent
      - type: memory_use_percent
      - type: swap_use_percent
      - type: load_1m

#
# Broadlink RM4 universal remote control
#   Since there are lots of commands they have been placed in a separate file.
switch RM4: !include Broadlink_RM4.yaml

#
# current petrol prices from NSW FuelCheck app
#
sensor fuelcheck_enhance_russel_vale_u91:
  - platform: nsw_fuel_station
    fuel_types: "U91"
    station_id: 18620       # Independent Russel Vale, Bellambi
sensor fuelcheck_independent_towradgi_u91:
  - platform: nsw_fuel_station
    fuel_types: "U91"
    station_id: 1114        # Independent Towradgi

DP dump

Procedure from https://github.com/rospogrigio/localtuya/wiki/HOWTO-get-a-DPs-dump gives

don@muscle:~$ python3 tuyadebug/test.py bfe74c868b1c942a54andf 192.168.1.105 83183d58514694b3
INFO:localtuya:localtuya version 1.0.0
INFO:localtuya:Python 3.10.4 (main, Jun 29 2022, 12:14:53) [GCC 11.2.0] on linux
INFO:localtuya:Using pytuya version '8.1.0'
INFO:localtuya:Detecting list of available DPS of device bfe74c868b1c942a54andf [192.168.1.105], protocol 3.3.
DEBUG:localtuya.pytuya:Sending command status (device type: type_0a)
DEBUG:localtuya.pytuya:paylod=b'{"gwId":"bfe74c868b1c942a54andf","devId":"bfe74c868b1c942a54andf"}'
DEBUG:localtuya.pytuya:DATA RECEIVED!
DEBUG:localtuya.pytuya:decode payload=b'\xc2\xdc\xaa\x9e\x10v\xa5Q\xcc\x90\x19\xad18^\xa8\x0e\x16\xb4\x8d\xb7\x88{GE\x08\xe0o\x87\xc1\xbb\xa6'
DEBUG:localtuya.pytuya:Failed to connect to 192.168.1.105. Raising Exception.
WARNING:localtuya.pytuya:Failed to get status: 'utf-8' codec can't decode byte 0x89 in position 0: invalid start byte
INFO:localtuya:Detecting list of available DPS of device bfe74c868b1c942a54andf [192.168.1.105], protocol 3.3.
DEBUG:localtuya.pytuya:Sending command status (device type: type_0a)
DEBUG:localtuya.pytuya:paylod=b'{"gwId":"bfe74c868b1c942a54andf","devId":"bfe74c868b1c942a54andf"}'
DEBUG:localtuya.pytuya:DATA RECEIVED!
DEBUG:localtuya.pytuya:decode payload=b'\xc2\xdc\xaa\x9e\x10v\xa5Q\xcc\x90\x19\xad18^\xa8\x0e\x16\xb4\x8d\xb7\x88{GE\x08\xe0o\x87\xc1\xbb\xa6'
DEBUG:localtuya.pytuya:Failed to connect to 192.168.1.105. Raising Exception.
WARNING:localtuya.pytuya:Failed to get status: 'utf-8' codec can't decode byte 0x89 in position 0: invalid start byte
INFO:localtuya:Detecting list of available DPS of device bfe74c868b1c942a54andf [192.168.1.105], protocol 3.3.
DEBUG:localtuya.pytuya:Sending command status (device type: type_0a)
DEBUG:localtuya.pytuya:paylod=b'{"gwId":"bfe74c868b1c942a54andf","devId":"bfe74c868b1c942a54andf"}'
DEBUG:localtuya.pytuya:DATA RECEIVED!
DEBUG:localtuya.pytuya:decode payload=b'\xc2\xdc\xaa\x9e\x10v\xa5Q\xcc\x90\x19\xad18^\xa8\x0e\x16\xb4\x8d\xb7\x88{GE\x08\xe0o\x87\xc1\xbb\xa6'
DEBUG:localtuya.pytuya:Failed to connect to 192.168.1.105. Raising Exception.
WARNING:localtuya.pytuya:Failed to get status: 'utf-8' codec can't decode byte 0x89 in position 0: invalid start byte
INFO:localtuya:TIMEOUT: No response from device bfe74c868b1c942a54andf [192.168.1.105] after 2 attempts.
don@muscle:~$ 
I have 7 working devices. 5 are Arlec PC191HA smart power sockets with DP_id's: dp_id code type values
1 switch_1 Boolean {}
9 countdown_1 Integer Unit:s, min:0, max:86400, scale:0, step:1
17 add_ele Integer unit:kW·h, min:0, max:50000, scale:3, step:100
18 cur_current Integer unit:mA, min:0, max:30000, scale:0, step:1
19 cur_power Integer Unit:W, min:0, max:80000, scale:1, step:1
20 cur_voltage Integer Unit:V, min:0, max:5000, scale:1, step:1
38 relay_status Enum Range: power_off, power_on, last actual values: on, off, memory

Curiously, only 2 of the actual deices seem to expose DP_id 17 - but I think that is a different issue.

I have a Zemismart Tuya blind motor, model M515EGWT V2

dp_id code type values Status
1 control Enum open,stop,close stop
2 percent_control Integer 0-100, step 1 39
5 control_back_mode Enum forward,back false
7 work_state Enum opening,closing opening
12 fault Bitmap Label: motor_fault 0
16 border Enum up,down, up_delete,down_delete, remove_top_bottom down
19 position_best Integer 0-100, step 1 0

and a Powertech 4-way smart Wi-fi mains powerboard.

dp_id code type values
1 switch_1 Boolean  
2 switch_2    
3 switch_3    
4 switch_4    
5 switch_5    
9 countdown_1 Integer unit:s, min:0, max:86400, scale:0, step:1
10 countdown_2 Integer unit:s, min:0, max:86400, scale:0, step:1
11 countdown_3 Integer unit:s, min:0, max:86400, scale:0, step:1
12 countdown_4 Integer unit:s, min:0, max:86400, scale:0, step:1
13 countdown_5 Integer unit:s, min:0, max:86400, scale:0, step:1

Provide Home Assistant taceback/logs

2022-09-01 11:44:40.316 ERROR (MainThread) [homeassistant.components.number] Error adding entities for domain number with platform localtuya
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 428, in async_add_entities
await asyncio.gather(*tasks)
File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 571, in _async_add_entity
capabilities=entity.capability_attributes,
File "/usr/src/homeassistant/homeassistant/components/number/__init__.py", line 253, in capability_attributes
ATTR_STEP: self.step,
File "/usr/src/homeassistant/homeassistant/components/number/__init__.py", line 339, in step
value_range = abs(self.max_value - self.min_value)
TypeError: unsupported operand type(s) for -: 'NoneType' and 'int'
2022-09-01 11:44:40.354 ERROR (MainThread) [homeassistant.components.number] Error while setting up localtuya platform for number
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 289, in _async_setup_platform
await asyncio.gather(*pending)
File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 428, in async_add_entities
await asyncio.gather(*tasks)
File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 571, in _async_add_entity
capabilities=entity.capability_attributes,
File "/usr/src/homeassistant/homeassistant/components/number/__init__.py", line 253, in capability_attributes
ATTR_STEP: self.step,
File "/usr/src/homeassistant/homeassistant/components/number/__init__.py", line 339, in step
value_range = abs(self.max_value - self.min_value)
TypeError: unsupported operand type(s) for -: 'NoneType' and 'int'
2022-09-01 11:44:44.411 ERROR (MainThread) [homeassistant.components.sensor] Error adding entities for domain sensor with platform mobile_app
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 428, in async_add_entities
await asyncio.gather(*tasks)
File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 673, in _async_add_entity
await entity.add_to_platform_finish()
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 776, in add_to_platform_finish
self.async_write_ha_state()
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 532, in async_write_ha_state
self._async_write_ha_state()
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 570, in _async_write_ha_state
state = self._stringify_state(available)
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 538, in _stringify_state
if (state := self.state) is None:
File "/usr/src/homeassistant/homeassistant/components/sensor/__init__.py", line 388, in state
value = self.native_value
File "/usr/src/homeassistant/homeassistant/components/mobile_app/sensor.py", line 113, in native_value
and (timestamp := dt_util.parse_datetime(state)) is not None
File "/usr/src/homeassistant/homeassistant/util/dt.py", line 185, in parse_datetime
return ciso8601.parse_datetime(dt_str)
TypeError: argument 1 must be str, not datetime.datetime
2022-09-01 11:44:44.441 ERROR (MainThread) [homeassistant.components.sensor] Error while setting up mobile_app platform for sensor
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 289, in _async_setup_platform
await asyncio.gather(*pending)
File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 428, in async_add_entities
await asyncio.gather(*tasks)
File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 673, in _async_add_entity
await entity.add_to_platform_finish()
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 776, in add_to_platform_finish
self.async_write_ha_state()
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 532, in async_write_ha_state
self._async_write_ha_state()
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 570, in _async_write_ha_state
state = self._stringify_state(available)
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 538, in _stringify_state
if (state := self.state) is None:
File "/usr/src/homeassistant/homeassistant/components/sensor/__init__.py", line 388, in state
value = self.native_value
File "/usr/src/homeassistant/homeassistant/components/mobile_app/sensor.py", line 113, in native_value
and (timestamp := dt_util.parse_datetime(state)) is not None
File "/usr/src/homeassistant/homeassistant/util/dt.py", line 185, in parse_datetime
return ciso8601.parse_datetime(dt_str)
TypeError: argument 1 must be str, not datetime.datetime

Additional information

henkkakay commented 1 year ago

@donburch888 I spotted your comment above about DP_id 17 - there is a separate issue explicitly on that: https://github.com/rospogrigio/localtuya/issues/932