rospogrigio / localtuya

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

Doesn't add Plug with energy monitor #193

Open Frans1960 opened 4 years ago

Frans1960 commented 4 years ago

I'm trying to add 3 plugs and the second one want add the switch (DP1)

After start HA with the LocalTuya in the config file and It generates all sensors of plug_2, but not the switch! I get this error: Logger: custom_components.localtuya.switch Source: custom_components/localtuya/pytuya/init.py:132 Integration: LocalTuya integration (documentation, issues) First occurred: 16:49:23 (3 occurrences) Last logged: 18:37:08 [061...87d] Entity switch.plug_2 is requesting unknown DPS index 1

LocalTya Config:

When I do it with the LocalTuya configurator it generates this error: Logboekdetails (ERROR) Logger: custom_components.localtuya.configflow Source: customcomponents/localtuya/pytuya/init.py:140 Integration: LocalTuya integration (documentation, issues) First occurred: 19:18:01 (1 occurrences) Last logged: 19:18:01

Unexpected exception Traceback (most recent call last): File "/config/custom_components/localtuya/pytuya/init.py", line 499, in detect_available_dps data = await self.status() File "/config/custom_components/localtuya/pytuya/init.py", line 461, in status status = await self.exchange(STATUS) File "/config/custom_components/localtuya/pytuya/init.py", line 446, in exchange payload = self._decode_payload(msg.payload) File "/config/custom_components/localtuya/pytuya/init.py", line 546, in _decode_payload payload = payload.decode() UnicodeDecodeError: 'utf-8' codec can't decode byte 0x84 in position 1: invalid start byte

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/config/custom_components/localtuya/config_flow.py", line 254, in async_step_basic_info self.dps_strings = await validate_input(self.hass, user_input) File "/config/custom_components/localtuya/config_flow.py", line 172, in validate_input detected_dps = await interface.detect_available_dps() File "/config/custom_components/localtuya/pytuya/init.py", line 501, in detect_available_dps self.exception("Failed to get status: %s", e) File "/config/custom_components/localtuya/pytuya/init.py", line 140, in exception return self._logger.log(logging.EXCEPTION, msg, *args) AttributeError: module 'logging' has no attribute 'EXCEPTION'.

postlund commented 4 years ago

Please enable debug logs and attach them here. At a glance it looks like decryption failed, but that could be the case of another error, something seen in #185 as well. It's the same scenario in that issue basically. Multiple devices added (of same type) but one fails.

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

Vaszago commented 4 years ago

I also have a similar problem since the update. Add 2 sockets with energy monitor with protocol 3.1. Are put on properly and work. After about 2-3 minutes you lose the connection and have no function. Can no longer be switched and the energy monitor shows the last values. With a reload they work again for a few minutes and then the same error again. I don't have these problems with the two GS112 with protocol 3.3.

postlund commented 4 years ago

@Vaszago Would be great if you attached debug logs as well. Can't do anything without them.

Vaszago commented 4 years ago

Is that the right log

Debug Tuya.txt

Vaszago commented 4 years ago

two more logs Debug Tuya 1.txt Debug Tuya 2.txt

postlund commented 4 years ago

Looks correct. Please note the id for the device that is malfunctioning, it will help me a lot.

Vaszago commented 4 years ago

20528441500291285df2. Work gs112 205284415002912a6705 Work gs112 [604...0e9]. Not working 604...48c. Not working

postlund commented 4 years ago

@Vaszago Can you try #177 for a while and see if it works better?

Frans1960 commented 4 years ago

I installed the latest LocalTuya version, but the same result. I attached the LocalTuya config and Homeassistant Log file home-assistant.log LocalTuya.txt

Frans1960 commented 4 years ago

I also deleted the device and used the config flow to add the device, which results also in an error message.

Frans1960 commented 4 years ago

I'm also setting up another HA system and the the same behaviour and problems. I attached the config and log files. LocalTuya.txt home-assistant.log

Frans1960 commented 4 years ago

The

Looks correct. Please note the id for the device that is malfunctioning, it will help me a lot.

the id for the device that is malfunctioning: device_id: 061.....487d local_key: b278.....b04

Vaszago commented 4 years ago

I'm back to V3.03 and everything works again

Frans1960 commented 4 years ago

It seems that the device is still in HA, but where? I cant find it in the UI, even if I delete it in the LocalTuya UI. The IP address of the device is 10.0.10.202!

Log 2020-11-30 09:18:58 ERROR (MainThread) [homeassistant.config_entries] Error setting up entry WasmachineDroger (YAML) for sensor Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/config_entries.py", line 236, in async_setup result = await component.async_setup_entry(hass, self) # type: ignore File "/usr/src/homeassistant/homeassistant/components/sensor/init.py", line 67, in async_setup_entry return await hass.data[DOMAIN].async_setup_entry(entry) File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 155, in async_setup_entry raise ValueError("Config entry has already been setup!") ValueError: Config entry has already been setup! 2020-11-30 09:18:58 ERROR (MainThread) [homeassistant.config_entries] Error setting up entry WasmachineDroger (YAML) for sensor Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/config_entries.py", line 236, in async_setup result = await component.async_setup_entry(hass, self) # type: ignore File "/usr/src/homeassistant/homeassistant/components/sensor/init.py", line 67, in async_setup_entry return await hass.data[DOMAIN].async_setup_entry(entry) File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 155, in async_setup_entry raise ValueError("Config entry has already been setup!") ValueError: Config entry has already been setup! 2020-11-30 09:18:58 DEBUG (MainThread) [custom_components.localtuya.common] Connecting to 10.0.10.202 (061......87d) 2020-11-30 09:18:58 DEBUG (MainThread) [custom_components.localtuya.common] Waiting 0 seconds before connecting 2020-11-30 09:18:58 DEBUG (MainThread) [custom_components.localtuya.common] Connecting to 10.0.10.202

Frans1960 commented 4 years ago

When I delete the device in the LocalTuya user interface I see a strange error in the HA Logging: 2020-12-01 13:55:59 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/components/tasmota/init.py", line 78, in async_device_removed device = device_registry.deleted_devices[event.data["device_id"]] KeyError: 'f6ec62164cb8544b0053e78a306f580b'

Frans1960 commented 4 years ago

This is the logging when I try to add the device again by the LocalTuya user interface: 2020-12-01 14:02:58 DEBUG (MainThread) [custom_components.localtuya.pytuya] [061...87d] Started heartbeat loop 2020-12-01 14:02:58 DEBUG (MainThread) [custom_components.localtuya.pytuya] [061...87d] Sending command heartbeat (device type: type_0a) 2020-12-01 14:02:58 DEBUG (MainThread) [custom_components.localtuya.pytuya] [061...87d] Send payload: b'{}' 2020-12-01 14:02:58 DEBUG (MainThread) [custom_components.localtuya.pytuya] [061...87d] Waiting for sequence number -100 2020-12-01 14:02:58 DEBUG (MainThread) [custom_components.localtuya.pytuya] [061...87d] Connection lost: [Errno 104] Connection reset by peer 2020-12-01 14:02:58 DEBUG (MainThread) [custom_components.localtuya.pytuya] [061...87d] Closing connection 2020-12-01 14:02:58 DEBUG (MainThread) [custom_components.localtuya.pytuya] [061...87d] Wait was aborted for seqno -100 2020-12-01 14:02:58 DEBUG (MainThread) [custom_components.localtuya.pytuya] [061...87d] Sending command status (device type: type_0a) 2020-12-01 14:02:58 DEBUG (MainThread) [custom_components.localtuya.pytuya] [061...87d] Send payload: b'{"gwId":"061...87d","devId":"061...87d"}' 2020-12-01 14:02:58 ERROR (MainThread) [custom_components.localtuya.pytuya] [061...87d] Failed to get status: 'NoneType' object has no attribute 'write' Traceback (most recent call last): File "/config/custom_components/localtuya/pytuya/init.py", line 499, in detect_available_dps data = await self.status() File "/config/custom_components/localtuya/pytuya/init.py", line 461, in status status = await self.exchange(STATUS) File "/config/custom_components/localtuya/pytuya/init.py", line 439, in exchange self.transport.write(payload) AttributeError: 'NoneType' object has no attribute 'write' 2020-12-01 14:02:58 DEBUG (MainThread) [custom_components.localtuya.pytuya] [061...87d] Closing connection 2020-12-01 14:02:58 ERROR (MainThread) [custom_components.localtuya.config_flow] Unexpected exception Traceback (most recent call last): File "/config/custom_components/localtuya/config_flow.py", line 260, in async_step_basic_info self.dps_strings = await validate_input(self.hass, user_input) File "/config/custom_components/localtuya/config_flow.py", line 173, in validate_input detected_dps = await interface.detect_available_dps() File "/config/custom_components/localtuya/pytuya/init.py", line 499, in detect_available_dps data = await self.status() File "/config/custom_components/localtuya/pytuya/init.py", line 461, in status status = await self.exchange(STATUS) File "/config/custom_components/localtuya/pytuya/init.py", line 439, in exchange self.transport.write(payload) AttributeError: 'NoneType' object has no attribute 'write'