Open Shintaro000000 opened 3 months ago
Good morning,
Based on what I found online and in the original TS0601_sensor file, I tried creating my own file specifically for the sensor that was giving me issues. I made a few modifications to the original file to better fit this model. Since I'm not very skilled in these things, I'm not sure if the changes I made actually helped, but I know that with my modifications, it has been working without problems for about 4 hours now. I'm sharing the code in case it might be useful.
If my modifications are useless or incorrect, I would like to know so that I can resolve these issues more easily in case I encounter similar problems with other devices.
Thank you very much, and have a great day.
from typing import Any
from zigpy.profiles import zha
from zigpy.quirks import CustomDevice
from zigpy.zcl.clusters.general import Basic, Groups, Ota, Scenes, Time, Identify
from zigpy.zcl.clusters.measurement import (
RelativeHumidity,
SoilMoisture,
TemperatureMeasurement,
)
from zhaquirks.const import (
DEVICE_TYPE,
ENDPOINTS,
INPUT_CLUSTERS,
MODELS_INFO,
OUTPUT_CLUSTERS,
PROFILE_ID,
SKIP_CONFIGURATION,
)
from zhaquirks.tuya import TuyaLocalCluster, TuyaPowerConfigurationCluster2AAA
from zhaquirks.tuya.mcu import DPToAttributeMapping, TuyaMCUCluster
class TuyaTemperatureMeasurement(TemperatureMeasurement, TuyaLocalCluster):
"""Tuya local TemperatureMeasurement cluster."""
class TuyaSoilMoisture(SoilMoisture, TuyaLocalCluster):
"""Tuya local SoilMoisture cluster with a device RH_MULTIPLIER factor if required."""
class TuyaRelativeHumidity(RelativeHumidity, TuyaLocalCluster):
"""Tuya local RelativeHumidity cluster with a device RH_MULTIPLIER factor."""
def update_attribute(self, attr_name: str, value: Any) -> None:
"""Apply a correction factor to value."""
if attr_name == "measured_value":
value = value * (
self.endpoint.device.RH_MULTIPLIER
if hasattr(self.endpoint.device, "RH_MULTIPLIER")
else 100
)
return super().update_attribute(attr_name, value)
class TemperatureHumidityManufCluster(TuyaMCUCluster):
"""Tuya Manufacturer Cluster with Temperature and Humidity data points."""
dp_to_attribute: dict[int, DPToAttributeMapping] = {
1: DPToAttributeMapping(
TuyaTemperatureMeasurement.ep_attribute,
"measured_value",
converter=lambda x: x * 10, # decidegree to centidegree
),
2: DPToAttributeMapping(
TuyaRelativeHumidity.ep_attribute,
"measured_value",
# converter=lambda x: x * 10, --> move conversion to TuyaRelativeHumidity cluster
),
4: DPToAttributeMapping(
TuyaPowerConfigurationCluster2AAA.ep_attribute,
"battery_percentage_remaining",
converter=lambda x: x * 2, # double reported percentage
),
}
data_point_handlers = {
1: "_dp_2_attr_update",
2: "_dp_2_attr_update",
4: "_dp_2_attr_update",
} # Aggiunta la chiusura della parentesi graffa
class TuyaTempHumiditySensor_Square(CustomDevice):
"""Custom device representing tuya temp and humidity sensor with e-ink screen."""
# RelativeHumidity multiplier
# RH_MULTIPLIER = 100
signature = {
MODELS_INFO: [
("_TZE200_a8sdabtg", "TS0601"), # Variant without screen, round
],
ENDPOINTS: {
1: {
# "profile_id": 260, "device_type": "0x0302",
# "in_clusters": ["0x0000","0x0003","0x0001","0x0402","0x0405"],
# "out_clusters": ["0x0003"]
PROFILE_ID: zha.PROFILE_ID,
DEVICE_TYPE: zha.DeviceType.TEMPERATURE_SENSOR,
INPUT_CLUSTERS: [
Basic.cluster_id,
Identify.cluster_id,
TuyaPowerConfigurationCluster2AAA.cluster_id,
TemperatureMeasurement.cluster_id,
RelativeHumidity.cluster_id,
],
OUTPUT_CLUSTERS: [Identify.cluster_id],
}
},
}
replacement = {
SKIP_CONFIGURATION: True,
ENDPOINTS: {
1: {
PROFILE_ID: zha.PROFILE_ID,
DEVICE_TYPE: zha.DeviceType.TEMPERATURE_SENSOR,
INPUT_CLUSTERS: [
Basic.cluster_id,
TuyaPowerConfigurationCluster2AAA,
TemperatureHumidityManufCluster,
TuyaTemperatureMeasurement,
TuyaRelativeHumidity,
],
OUTPUT_CLUSTERS: [Identify.cluster_id],
}
},
}
Hi @Shintaro000000, would you consider re-opening this issue? I have the same sensor and observed the same behaviour. I tried your custom ZHA quirk and I confirm that it works for me. However, I would love to see this addressed upstream so that I can stop having to carry a custom quirk file with my own Home Assistant installation.
@lvillani I'm glad it's working for you. I reopened it as requested. Have a good day :)
Hi I have the same issue and saw it posted in several places, it will be great if this can be fixed.
Thanks for the great work.
Another upvote - tested working with https://www.aliexpress.com/item/1005006128690857.html
reports as TZE200_a8sdabtg
Hi @myromeo,
How did you make it to work? Did you add the script or program from this comment in HomeAssistant? or maybe just point me to the documentation.
Thanks!
I have the same issue. I have 4 of these sensors. 2 of them work correctly, 2 of them have this issue as described above. Where do I need to place the python script file above?
@chrisism I followed the guides I found (though I might have made a mistake or forgotten a step). I created a folder called zha_quirks in /homeassistant, and I placed the script inside it. Then, in the configuration.yaml, I added the following:
zha: database_path: /config/zigbee.db enable_quirks: true custom_quirks_path: /config/zha_quirks
After restarting the device, it recognized the quirk, and it shows up in the device's description. Of course, the device you have must have the exact code TZE200_a8sdabtg, otherwise, it won't work.
Since I made the post, it's been working without any issues for me.
I hope this helps you. Have a great day!
Thanks, got the quirk working. I have exactly the same sensor. Still two of my sensors show -0.0. Other two work fine just as before. Lets see if it starts picking it up.
@chrisism You can also try removing and re-adding the devices after adding the quirk.
@Shintaro000000 that did the trick. Looks like it works. Only restarted the service before but that isnt enough.
@Shintaro000000 many thanks for the code, I put it in my HA and now it's working good since Saturday.
@Shintaro000000 thank you so much! This fixed it. What a frustration. ZigBee2MQTT had no issues with this device and I found endless threads with folks having this problem (and similar ones) with ZHA for a long time. I'm amazed they either don't work together or share some kind of database of ZigBee devices. Really bad user experience with ZHA, almost went back to Z2M but I stuck it out because I wanted to use something that was out of the box supported. Z2M also has some strange issues of its own, but I have yet to find a device it can't handle, ZHA has improved slightly over the last 6 months with device support, but the developers completely ignore the forums (where all of these reports are) and only focus on GitHub repo which I (and many others) did not know about. Anyways, thanks again for sharing!
Bug description
I bought two temperature sensors on Aliexpress. Once the zigbee devices are associated with ZHA, they start working correctly for the first 15/20 minutes, then they always report 0 and only give the temperature once an hour. The same goes for humidity. The batteries are new and the sensor is next to the coordinator I am using (ZBdongle-E). I have tried reconfiguring them multiple times without success.
Steps to reproduce
Simply adding the device, the problem appears shortly after.
Expected behavior
It should give the correct temperature without showing -0
Screenshots/Video
Device signature
Device signature
```json { "node_descriptor": "NodeDescriptor(logical_type=Diagnostic information
Diagnostic information
```json "home_assistant": { "installation_type": "Home Assistant OS", "version": "2024.6.4", "dev": false, "hassio": true, "virtualenv": false, "python_version": "3.12.2", "docker": true, "arch": "x86_64", "timezone": "Europe/Rome", "os_name": "Linux", "os_version": "6.6.33-haos", "supervisor": "2024.06.2", "host_os": "Home Assistant OS 12.4", "docker_version": "26.1.4", "chassis": "vm", "run_as_root": true }, "custom_components": { "pyscript": { "documentation": "https://github.com/custom-components/pyscript", "version": "1.5.0", "requirements": [ "croniter==1.3.8", "watchdog==2.3.1" ] }, "dpc": { "documentation": "https://github.com/caiosweet/Home-Assistant-custom-components-DPC-Alert", "version": "2023.10.0", "requirements": [] }, "dwains_dashboard": { "documentation": "https://dwainscheeren.github.io/dwains-lovelace-dashboard/", "version": "3.7.1", "requirements": [] }, "multiscrape": { "documentation": "https://github.com/danieldotnl/ha-multiscrape", "version": "7.0.0", "requirements": [ "lxml>=4.9.1", "beautifulsoup4>=4.12.2" ] }, "cloudflare_tunnel_monitor": { "documentation": "https://github.com/deadbeef3137/ha-cloudflare-tunnel-monitor/blob/master/README.md", "version": "0.0.1", "requirements": [ "aiohttp", "async_timeout" ] }, "zha_toolkit": { "documentation": "https://github.com/mdeweerd/zha-toolkit", "version": "v1.1.10", "requirements": [ "pytz" ] }, "sonoff": { "documentation": "https://github.com/AlexxIT/SonoffLAN", "version": "3.7.3", "requirements": [ "pycryptodome>=3.6.6" ] }, "hacs": { "documentation": "https://hacs.xyz/docs/configuration/start", "version": "1.34.0", "requirements": [ "aiogithubapi>=22.10.1" ] }, "alexa_media": { "documentation": "https://github.com/alandtse/alexa_media_player/wiki", "version": "4.10.2", "requirements": [ "alexapy==1.27.10", "packaging>=20.3", "wrapt>=1.14.0" ] }, "toyota": { "documentation": "https://github.com/DurgNomis-drol/ha_toyota", "version": "2.0.3", "requirements": [ "mytoyota==2.1.1", "arrow" ] } }, "integration_manifest": { "domain": "zha", "name": "Zigbee Home Automation", "after_dependencies": [ "onboarding", "usb" ], "codeowners": [ "dmulcahey", "adminiuga", "puddly", "TheJulianJES" ], "config_flow": true, "dependencies": [ "file_upload" ], "documentation": "https://www.home-assistant.io/integrations/zha", "iot_class": "local_polling", "loggers": [ "aiosqlite", "bellows", "crccheck", "pure_pcapy3", "zhaquirks", "zigpy", "zigpy_deconz", "zigpy_xbee", "zigpy_zigate", "zigpy_znp", "universal_silabs_flasher" ], "requirements": [ "bellows==0.39.1", "pyserial==3.5", "zha-quirks==0.0.116", "zigpy-deconz==0.23.1", "zigpy==0.64.1", "zigpy-xbee==0.20.1", "zigpy-zigate==0.12.0", "zigpy-znp==0.12.1", "universal-silabs-flasher==0.0.20", "pyserial-asyncio-fast==0.11" ], "usb": [ { "vid": "10C4", "pid": "EA60", "description": "*2652*", "known_devices": [ "slae.sh cc2652rb stick" ] }, { "vid": "10C4", "pid": "EA60", "description": "*slzb-07*", "known_devices": [ "smlight slzb-07" ] }, { "vid": "1A86", "pid": "55D4", "description": "*sonoff*plus*", "known_devices": [ "sonoff zigbee dongle plus v2" ] }, { "vid": "10C4", "pid": "EA60", "description": "*sonoff*plus*", "known_devices": [ "sonoff zigbee dongle plus" ] }, { "vid": "10C4", "pid": "EA60", "description": "*tubeszb*", "known_devices": [ "TubesZB Coordinator" ] }, { "vid": "1A86", "pid": "7523", "description": "*tubeszb*", "known_devices": [ "TubesZB Coordinator" ] }, { "vid": "1A86", "pid": "7523", "description": "*zigstar*", "known_devices": [ "ZigStar Coordinators" ] }, { "vid": "1CF1", "pid": "0030", "description": "*conbee*", "known_devices": [ "Conbee II" ] }, { "vid": "0403", "pid": "6015", "description": "*conbee*", "known_devices": [ "Conbee III" ] }, { "vid": "10C4", "pid": "8A2A", "description": "*zigbee*", "known_devices": [ "Nortek HUSBZB-1" ] }, { "vid": "0403", "pid": "6015", "description": "*zigate*", "known_devices": [ "ZiGate+" ] }, { "vid": "10C4", "pid": "EA60", "description": "*zigate*", "known_devices": [ "ZiGate" ] }, { "vid": "10C4", "pid": "8B34", "description": "*bv 2010/10*", "known_devices": [ "Bitron Video AV2010/10" ] } ], "zeroconf": [ { "type": "_esphomelib._tcp.local.", "name": "tube*" }, { "type": "_zigate-zigbee-gateway._tcp.local.", "name": "*zigate*" }, { "type": "_zigstar_gw._tcp.local.", "name": "*zigstar*" }, { "type": "_uzg-01._tcp.local.", "name": "uzg-01*" }, { "type": "_slzb-06._tcp.local.", "name": "slzb-06*" } ], "is_built_in": true }, "setup_times": { "null": { "setup": 9.1562993475236e-05 }, "a68a2d34f8320be80bf23422c0f9de8b": { "wait_import_platforms": -0.000161513002240099, "wait_base_component": -0.0004109229921596125, "config_entry_setup": 10.080363132001366 } }, "data": { "ieee": "**REDACTED**", "nwk": 59314, "manufacturer": "_TZE200_a8sdabtg", "model": "TS0601", "name": "_TZE200_a8sdabtg TS0601", "quirk_applied": false, "quirk_class": "zigpy.device.Device", "quirk_id": null, "manufacturer_code": 4742, "power_source": "Battery or Unknown", "lqi": 148, "rssi": -63, "last_seen": "2024-06-26T01:43:39", "available": true, "device_type": "EndDevice", "signature": { "node_descriptor": "NodeDescriptor(logical_type=Logs
Logs
```python 2024-06-26 01:44:06.341 DEBUG (MainThread) [homeassistant.components.zha.core.device] [0xD234](TS0601): Device seen - marking the device available and resetting counter 2024-06-26 01:44:06.342 DEBUG (MainThread) [homeassistant.components.zha.core.device] [0xD234](TS0601): Update device availability - device available: True - new availability: True - changed: False 2024-06-26 01:44:12.330 DEBUG (MainThread) [homeassistant.components.zha.core.device] [0xE7B2](TS0601): Device seen - marking the device available and resetting counter 2024-06-26 01:44:12.330 DEBUG (MainThread) [homeassistant.components.zha.core.device] [0xE7B2](TS0601): Update device availability - device available: True - new availability: True - changed: False 2024-06-26 01:44:15.836 DEBUG (MainThread) [zigpy.application] Feeding watchdog 2024-06-26 01:44:15.837 DEBUG (MainThread) [bellows.ezsp.protocol] Sending command readCounters: () 2024-06-26 01:44:15.838 DEBUG (bellows.thread_0) [bellows.ash] Sending frame DataFrame(frm_num=4, re_tx=False, ack_num=4, ezsp_frame=b'\xbb\x00\x01\xf1\x00') + FLAG 2024-06-26 01:44:15.838 DEBUG (bellows.thread_0) [bellows.ash] Sending data 44f921a9a52af0df7e 2024-06-26 01:44:15.854 DEBUG (bellows.thread_0) [bellows.ash] Received data 45f9a1a9a52a78b266947425b25593499c4e27abedce738bfcc66389fb7d5e3ca7ebcdde6f8fffc7dbd5d2698c4623a9ec763ba5ea758241984c267d33b1e070381c0e07bbe5ca658a459a4d9e4f9ff7c3d9d46a35a2519048245cae7e 2024-06-26 01:44:15.854 DEBUG (bellows.thread_0) [bellows.ash] Received frame DataFrame(frm_num=4, re_tx=0, ack_num=5, ezsp_frame=b'\xbb\x80\x01\xf1\x00m\x00?\x00>\x00\x18\x00\x01\x00\x00\x00\x00\x00\x00\x00\x14\x00\x01\x00\x00\x00\x07\x00\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00') 2024-06-26 01:44:15.854 DEBUG (bellows.thread_0) [bellows.ash] Sending frame AckFrame(res=0, ncp_ready=0, ack_num=5) + FLAG 2024-06-26 01:44:15.854 DEBUG (bellows.thread_0) [bellows.ash] Sending data 8520dd7e 2024-06-26 01:44:15.855 DEBUG (MainThread) [bellows.ezsp.protocol] Received command readCounters: [[109, 63, 62, 24, 1, 0, 0, 0, 20, 1, 0, 7, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]] 2024-06-26 01:44:15.857 DEBUG (MainThread) [bellows.ezsp.protocol] Sending command getValue: (Additional information
I don't know if it helps, but I saw that this model is present in the quirks, yet it doesn't seem to recognize the sensor correctly or there might be another problem. Maybe I made a mistake. I also tried to manually add ts0601__sensor as per the guide, but nothing changed.