Is this mean that we should not connect using tuya mobile apps?
Hi,
carrying out further tests and I saw that when using the smartlife app the light TuyaLocal sensor is no longer manageable, but when the smartlife app is closed, a few seconds later the light TuyaLocal sensor becomes available again and can be managed from Home Assistant without restarting! Good news
The sensor state takes very little time to understand the actual state of the bulb.
I like TuyaLocal!
Maybe or maybe not. I don’t think we are sure right now, as @rospogrigio seems to have it working ok with both. Guess we will have to see.
That sounds a lot like it’s using the local API. Since we poll/connect every 30s, the state will update at that rate. So when you close the app it should recover within 30s.
If you feel brave and have some time, you could test this PR as well:
It will give you instant updates. Would be interesting to know how it works with you and the app. Since it’s a big change, it would be great with some additional testing before we merge.
Sure, I try!
In the meantime I was trying to take inspiration from TuyaConvert’s light.py to import the correct brightness management parameters for my bulbs:
example:
PARALLEL_UPDATES = 0
SCAN_INTERVAL = timedelta (seconds = 15)
TUYA_BRIGHTNESS_RANGE0 = (10, 1000)
TUYA_BRIGHTNESS_RANGE1 = (1, 255)
TUYA_DEF_MAX_COL_TEMP = 10000
BRIGHTNESS_MODES = {
0: TUYA_BRIGHTNESS_RANGE0,
1: TUYA_BRIGHTNESS_RANGE1,
}
Hi,
I tried localtuya-homeassistant-pytuya_asyncio, but it no longer recognizes sockets and light.
Maybe I had to leave the localtuya-homeassistant-light_dps component and just integrate the different files?
Let me know so I try again
It should be a drop-in replacement, so if you replace all files it should work. You should look at the error log to see what’s happening.
Surely there were mistakes on
brightness: 22
color_temp: 23
that were not recognized
Maybe we need to update localtuya-homeassistant-pytuya_asyncio with parameters to monitor brightness and color temperature?
After I try again to put the localtuya-homeassistant-pytuya_asyncio and enable the debug, so I report the errors.
Thanks for the great work
@Alloc186 I would like to start implementing the climate platform, in some spare time. Just to have a start, can you give us some info about how your device works? The output from tuyadebug.tgz together with screenshots of your Tuya app that operates the device should be a good starting point.
Let us know!
Ah, right. I rebased that branch to get those changes in. So if you try now it should work.
WONDERFUL!!!
The change of status is immediate for both the lights and the sockets as well as the update of the consumption sensors. They work at the same speed and in real time as the smartlife app. GREAT
Just for info, the sockets do not conflict when the smartlife app is launched, they also continue to monitor consumption, while the lights are unavailable if the smartlife app is opened.
PS
I tried to combine light.py tuyacustom with light.py localtuya, but I couldn’t improve the situation. When you have time, can you see if you can adjust the brightness range for the bulbs?
As for the RGB management, is there any possibility to implement it?
In my opinion we need to start by forcing the supported_features and raise them from 3 to 19
How about tuya sirens?
Hi @postlund and @rospogrigio
i was trying to integrate a switch similar to sonoff, but which works with smartlife.
I have the deviceID, LocalKey and IP address.
The device is also recognized in the flow, but it cannot find the ID to assign.
Is it possible to integrate this type of switch?
This is the reported error (localtuya-homeassistant-pytuya_asyncio):
2020-10-06 17:44:33 DEBUG (MainThread) [custom_components.localtuya.pytuya] [MyDeviceID] Sending command heartbeat (device type: type_0a)
2020-10-06 17:44:33 DEBUG (MainThread) [custom_components.localtuya.pytuya] [MyDeviceID] Paylod: b’{}’
2020-10-06 17:44:33 DEBUG (MainThread) [custom_components.localtuya.pytuya] [MyDeviceID] Waiting for sequence number -100
2020-10-06 17:44:33 DEBUG (MainThread) [custom_components.localtuya.pytuya] [MyDeviceID] Sending command status (device type: type_0a)
2020-10-06 17:44:33 DEBUG (MainThread) [custom_components.localtuya.pytuya] [MyDeviceID] Paylod: b’{“gwId”:“MyDeviceID”,“devId”:“MyDeviceID”}’
2020-10-06 17:44:33 DEBUG (MainThread) [custom_components.localtuya.pytuya] [MyDeviceID] Waiting for sequence number 1
2020-10-06 17:44:33 DEBUG (MainThread) [custom_components.localtuya.pytuya] [MyDeviceID] Got heartbeat response
2020-10-06 17:44:33 DEBUG (MainThread) [custom_components.localtuya.pytuya] [MyDeviceID] Decode payload: b’’
2020-10-06 17:44:33 DEBUG (MainThread) [custom_components.localtuya.pytuya] [MyDeviceID] Decrypted payload: {}
2020-10-06 17:44:33 DEBUG (MainThread) [custom_components.localtuya.pytuya] [MyDeviceID] Dispatching sequence number 1
2020-10-06 17:44:33 DEBUG (MainThread) [custom_components.localtuya.pytuya] [MyDeviceID] Decode payload: b’…xxxx…xxxx…xxxx…xxxx’
2020-10-06 17:44:33 DEBUG (MainThread) [custom_components.localtuya.pytuya] [MyDeviceID] switching to dev_type type_0d
2020-10-06 17:44:33 DEBUG (MainThread) [custom_components.localtuya.pytuya] [MyDeviceID] Re-send status due to device type change (type_0a -> type_0d)
2020-10-06 17:44:33 DEBUG (MainThread) [custom_components.localtuya.pytuya] [MyDeviceID] Sending command status (device type: type_0d)
2020-10-06 17:44:33 DEBUG (MainThread) [custom_components.localtuya.pytuya] [MyDeviceID] Paylod: b’{“devId”:“MyDeviceID”,“uid”:“MyDeviceID”,“t”:“16xxxxx073”,“dps”:{“1”:null,“2”:null,“3”:null,“4”:null,“5”:null,“6”:null,“7”:null,“8”:null,“9”:null,“10”:null}}’
2020-10-06 17:44:33 DEBUG (MainThread) [custom_components.localtuya.pytuya] [MyDeviceID] Waiting for sequence number 2
2020-10-06 17:44:33 DEBUG (MainThread) [custom_components.localtuya.pytuya] [MyDeviceID] Dispatching sequence number 2
2020-10-06 17:44:33 DEBUG (MainThread) [custom_components.localtuya.pytuya] [MyDeviceID] Decode payload: b’’
2020-10-06 17:44:33 DEBUG (MainThread) [custom_components.localtuya.pytuya] [MyDeviceID] Decrypted payload: {}
2020-10-06 17:44:33 ERROR (MainThread) [custom_components.localtuya.config_flow] Unexpected exception
Traceback (most recent call last):
File “/config/custom_components/localtuya/config_flow.py”, line 236, 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 439, in detect_available_dps
detected_dps.update(data[“dps”])
KeyError: ‘dps’
I would like to see what’s in the status response. Can you modify pytuya/__init__.py
and add this at line 439 (so that what is currently at 439 ends up at 440):
self.log.debug("Data: %s", data)
And then try again?
Hello,
I added the code in pytuya/init.py:
except Exception as e:
self.log.warning("Failed to get status: %s", e)
raise
self.log.debug ("Dati:% s", dati)
detected_dps.update(data["dps"])
and trying to add the socket I have this error:
Traceback (most recent call last):
File “/config/custom_components/localtuya/config_flow.py”, line 236, 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 440, in detect_available_dps
detected_dps.update(data[“dps”])
KeyError: ‘dps’
You need to remove one indent level (four spaces) and data seems to be misspelled (dati).
except Exception as e:
self.log.warning("Failed to get status: %s", e)
raise
self.log.debug ("Data:% s", data)
detected_dps.update(data["dps"])
Traceback (most recent call last):
File “/config/custom_components/localtuya/config_flow.py”, line 236, 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 440, in detect_available_dps
detected_dps.update(data[“dps”])
KeyError: ‘dps’
What’s printed on the line above, with “Data:”?
2020-10-06 19:44:14 DEBUG (MainThread) [custom_components.localtuya.pytuya] [MyID] switching to dev_type type_0d
2020-10-06 19:44:14 DEBUG (MainThread) [custom_components.localtuya.pytuya] [MyID] Re-send status due to device type change (type_0a -> type_0d)
2020-10-06 19:44:14 DEBUG (MainThread) [custom_components.localtuya.pytuya] [MyID] Sending command status (device type: type_0d)
2020-10-06 19:44:14 DEBUG (MainThread) [custom_components.localtuya.pytuya] [MyID] Paylod: b’{“devId”:“MyID”,“uid”:“MyID”,“t”:“1xxx4”,“dps”:{“1”:null,“2”:null,“3”:null,“4”:null,“5”:null,“6”:null,“7”:null,“8”:null,“9”:null,“10”:null}}’
2020-10-06 19:44:14 DEBUG (MainThread) [custom_components.localtuya.pytuya] [MyID] Waiting for sequence number 2
2020-10-06 19:44:14 DEBUG (MainThread) [custom_components.localtuya.pytuya] [MyID] Dispatching sequence number 2
2020-10-06 19:44:14 DEBUG (MainThread) [custom_components.localtuya.pytuya] [MyID] Decode payload: b’’
2020-10-06 19:44:14 DEBUG (MainThread) [custom_components.localtuya.pytuya] [MyID] Decrypted payload: {}
2020-10-06 19:44:14 DEBUG (MainThread) [custom_components.localtuya.pytuya] [MyID] Data:{}
2020-10-06 19:44:14 ERROR (MainThread) [custom_components.localtuya.config_flow] Unexpected exception
Ok, so we get nothing. Last try to see if anything works. Try replacing the entire method with this:
async def detect_available_dps(self):
"""Return which datapoints are supported by the device."""
# type_0d devices need a sort of bruteforce querying in order to detect the
# list of available dps experience shows that the dps available are usually
# in the ranges [1-25] and [100-110] need to split the bruteforcing in
# different steps due to request payload limitation (max. length = 255)
detected_dps = {}
ranges = [(2, 11), (11, 21), (21, 31), (100, 111)]
for dps_range in ranges:
# dps 1 must always be sent, otherwise it might fail in case no dps is found
# in the requested range
self.dps_to_request = {"1": None}
self.add_dps_to_request(range(*dps_range))
try:
data = await self.status()
except Exception as e:
self.log.warning("Failed to get status: %s", e)
raise
if "dps" in data:
detected_dps.update(data["dps"])
if self.dev_type == "type_0a":
return detected_dps
self.log.debug("detected dps: %s", detected_dps)
return detected_dps