-
Notifications
You must be signed in to change notification settings - Fork 716
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Device Support Request] Tuya rainsensor TS0207_TZ3210_tgvtvdoc #3249
Comments
I would be interested in this too |
const fz = require('zigbee-herdsman-converters/converters/fromZigbee');
const tz = require('zigbee-herdsman-converters/converters/toZigbee');
const exposes = require('zigbee-herdsman-converters/lib/exposes');
const reporting = require('zigbee-herdsman-converters/lib/reporting');
const modernExtend = require('zigbee-herdsman-converters/lib/modernExtend');
const e = exposes.presets;
const ea = exposes.access;
const tuya = require('zigbee-herdsman-converters/lib/tuya');
const definition = {
fingerprint: [
{
modelID: 'TS0207',
manufacturerName: '_TZ3210_tgvtvdoc',
},
],
model: 'TS0207_rain_sensor',
vendor: 'Tuya',
description: 'TUYA TS0207 Rain Sensor RB-SRAN01',
fromZigbee: [tuya.fz.datapoints, fz.battery],
toZigbee: [],
onEvent: tuya.onEventSetTime, // Add this if you are getting no converter for 'commandMcuSyncTime'
configure: tuya.configureMagicPacket,
exposes: [
// Here you should put all functionality that your device exposes
e.water_leak(), e.battery_low(), e.battery(),
exposes.numeric('illuminance', ea.STATE).withDescription('Raw measured illuminance').withUnit('mV'),
exposes.numeric('rainIntensity', ea.STATE).withDescription('Raw measured rain intensity').withUnit('mV')
],
meta: {
// All datapoints go in here
tuyaDatapoints: [
[101, 'illuminance', tuya.valueConverter.raw],
[105, 'rainIntensity', tuya.valueConverter.raw]
],
},
};
module.exports = definition; |
Please excuse my ignorance but I'm very new to HA, but where does this code go? |
This is the integration of the sensor for Zigbee2Mqtt. |
Oops, told you I was a newbie. |
I tried asking ChatGPT to port the Z2M converter to a ZHA quirk. I added it as a custom quirk, fixed the errors, but it doesn't work (no surprises there).
|
There are more datapoints: Has anyone began the work on the quirk file? |
Here's a quirk that works, but does not expose the secondary measurement values to HA yet. If anyone wants to tackle that it would be great. Pretty much all DP values are DC voltages measured in mV, except for the cleaning reminder.
|
Thanks for that @hadeshimself. |
@pbutterworth, could you please try this one and let me know? """Quirk for TS0207 rain sensors."""
import zigpy.types as t
from typing import Any, Type
from zigpy.profiles import zha
from zigpy.quirks import CustomDevice, CustomCluster
from zigpy.zcl.clusters.general import (
Basic,
Groups,
Identify,
OnOff,
Ota,
PowerConfiguration,
Scenes,
Time,
)
from zigpy.zcl.clusters.lightlink import LightLink
from zigpy.zcl.clusters.security import IasZone
from zhaquirks.const import (
DEVICE_TYPE,
ENDPOINTS,
INPUT_CLUSTERS,
MODELS_INFO,
OUTPUT_CLUSTERS,
PROFILE_ID,
)
from zhaquirks.tuya.mcu import TuyaMCUCluster
from zhaquirks.tuya import (
TuyaManufCluster,
DPToAttributeMapping,
EnchantedDevice,
TuyaNoBindPowerConfigurationCluster,
)
ZONE_TYPE = 0x0001
class TuyaSolarRainSensorCluster(TuyaMCUCluster):
"""Tuya manufacturer cluster."""
attributes = TuyaMCUCluster.attributes.copy()
attributes.update(
{
0xEF65: ("light_intensity", t.uint32_t, True),
0xEF66: ("average_light_intensity_20mins", t.uint32_t, True),
0xEF67: ("todays_max_light_intensity", t.uint32_t, True),
0xEF68: ("cleaning_reminder", t.Bool, True),
0xEF69: ("rain_sensor_voltage", t.uint32_t, True),
}
)
dp_to_attribute: dict[int, DPToAttributeMapping] = {
101: DPToAttributeMapping(
TuyaMCUCluster.ep_attribute,
"light_intensity",
),
102: DPToAttributeMapping(
TuyaMCUCluster.ep_attribute,
"average_light_intensity_20mins",
),
103: DPToAttributeMapping(
TuyaMCUCluster.ep_attribute,
"todays_max_light_intensity",
),
104: DPToAttributeMapping(
TuyaMCUCluster.ep_attribute,
"cleaning_reminder",
),
105: DPToAttributeMapping(
TuyaMCUCluster.ep_attribute,
"rain_sensor_voltage",
),
}
data_point_handlers = {
101: "_dp_2_attr_update",
102: "_dp_2_attr_update",
103: "_dp_2_attr_update",
104: "_dp_2_attr_update",
105: "_dp_2_attr_update",
}
class TuyaIasZone(CustomCluster, IasZone):
"""IAS Zone for rain sensors."""
_CONSTANT_ATTRIBUTES = {ZONE_TYPE: IasZone.ZoneType.Water_Sensor}
class TuyaSolarRainSensor(EnchantedDevice):
"""TS0207 Rain sensor quirk."""
signature = {
MODELS_INFO: [("_TZ3210_tgvtvdoc", "TS0207")],
ENDPOINTS: {
1: {
PROFILE_ID: zha.PROFILE_ID,
DEVICE_TYPE: zha.DeviceType.IAS_ZONE,
INPUT_CLUSTERS: [
Basic.cluster_id,
PowerConfiguration.cluster_id,
Groups.cluster_id,
Scenes.cluster_id,
IasZone.cluster_id,
TuyaMCUCluster.cluster_id,
],
OUTPUT_CLUSTERS: [
Identify.cluster_id,
Groups.cluster_id,
OnOff.cluster_id,
Time.cluster_id,
Ota.cluster_id,
LightLink.cluster_id,
],
},
},
}
replacement = {
ENDPOINTS: {
1: {
PROFILE_ID: zha.PROFILE_ID,
DEVICE_TYPE: zha.DeviceType.IAS_ZONE,
INPUT_CLUSTERS: [
Basic.cluster_id,
Groups.cluster_id,
Scenes.cluster_id,
TuyaNoBindPowerConfigurationCluster,
TuyaIasZone,
TuyaSolarRainSensorCluster,
],
OUTPUT_CLUSTERS: [
Time.cluster_id,
Ota.cluster_id,
],
},
},
} |
@hadeshimself same symptoms. Once the unit stops flashing, there are no further updates. |
Just to make sure you replaced the file and reloaded everything before adding the device again. You should see a TuyaNoBindPowerConfigurationCluster entry in the device clusters. Did you add this device previously to any other Zigbee hub? Tuya or zigbee2mqtt? |
@hadeshimself, ah yes, excuse me; my mistake. Failed to save the file (I think) 🤦♂️.
Outcome: sensor does not update at all, even when the device is in pairing mode (green flashing light). PS: this device has not been added to any other hub. Tuya: don't have one. Z2M: I'm only using ZHA. |
Hey @hadeshimself , first of all thank you for that quirk and I guess it is almost the solution (at least for me...). For me it looks different after adding the quirk, removing the device, restarting HA an re-adding the device it is working quite well. But I do not see all the other attributes. The diagnostics shows them as "unsupported attributes". "data": { |
Quick update: |
@pbutterworth did you use the code you received by email or did you copy it from the GitHub page? Because I edited the post with some updated code a few minutes later. @frankfrommelt yeah, I don’t know how to expose those other attributes. There’s no standard to represent that kind of data, except from some energy related stuff. You would get 4 sensors for Voltage. How to tell them apart? If I had to pick one I would use the rain sensor voltage as it may indicate the intensity of the rain (?). |
@frankfrommelt when you paired the device, did you notice whether the green light stopped flashing once the ZHA handshake was complete? Or, did the green light keep flashing for another couple of minutes? |
@pbutterworth, make sure you are using that last code I posted, which includes the enchanted device code (it will have a TuyaNoBindPowerConfigurationCluster cluster shown on the UI). When you trigger your rain sensor do you see a red LED blink on the back? Also, make sure you reload everything and even clear the pycache directory where you have your custom quirk files before adding the device again. @frankfrommelt, you could try https://github.com/mdeweerd/zha-toolkit meanwhile to read the other values. Setup an action every minute or so to feed a sensor, something like: action: zha_toolkit.attr_read
data:
ieee: binary_sensor.rain_sensor_moisture
cluster: 61184
attribute: light_intensity
state_id: sensor.rain_sensor_light_intensity
allow_create: true
use_cache: true Replace "rain_sensor" accordingly. |
OK, another round of this. BTW @hadeshimself, feel free to step away from this; you've helped a lot already! Re: red light on moisture detection: yes, once pairing mode has timed out, the red light flashes once when moisture is detected.
Here's a log file that covers (sorry very noisy log file):
|
@pbutterworth, also check if you have the latest coordinator firmware. At one point when debuging I couldn't pair it anymore and it only got back to normal after I updated the firmware. I'm using the Sonoff 3.0 dongle. |
@hadeshimself nailed it! silabs firmware was 6.10, updated to 7.4, problem solved. 🤜🤛 |
That is a good workaround. And this is how I create statistics from the States. As soon as I have a min/max value I will add some calculations to the state.
|
@frankfrommelt yes, please let me know the max value you can get. I topped at around 5500. |
@frankfrommelt, my peak was 5880. But it's really not a good light measurement device. I've also compared it to a real light sensor and it's not even close to the same precision. |
@hadeshimself thanx a lot! |
I struggle with the same problem for a water leak sensor (Model) which also uses the TS0207 chip. Same behavior: Works great with generic Tuya hub, connects smoothly with ZHA (through SkyConnect; water leak is correctly showing the first minutes after initial setup), but then never updates again. The water leak sensor is explicitly mentioned here as compatible with ZHA, which makes the whole thing a bit odd. |
Updating the zigbee radio firmware solved these symptoms for me. |
Not sure what radio you are using, but I have HA Yellow and I couldn't make it pair with Zigbee2MQTT, so I rolled back my HA backup and bought a Sonoff ZBDongle-E. Now I have ZHA with the embedded radio and Sonoff as with MQTT. It was a very different behavior. Couple of things I had to do:
|
I updated the above quirk so that it exposes the Note the """Quirk for TS0207 rain sensors."""
import zigpy.types as t
from zigpy.profiles import zha
from zigpy.quirks import CustomCluster
from zigpy.zcl.clusters.general import (
Basic,
Groups,
Identify,
OnOff,
Ota,
PowerConfiguration,
Scenes,
Time,
)
from zigpy.zcl.clusters.lightlink import LightLink
from zigpy.zcl.clusters.measurement import IlluminanceMeasurement
from zigpy.zcl.clusters.security import IasZone
from zhaquirks.const import (
DEVICE_TYPE,
ENDPOINTS,
INPUT_CLUSTERS,
MODELS_INFO,
OUTPUT_CLUSTERS,
PROFILE_ID,
)
from zhaquirks.tuya.mcu import TuyaMCUCluster
from zhaquirks.tuya import (
TuyaLocalCluster,
DPToAttributeMapping,
EnchantedDevice,
TuyaNoBindPowerConfigurationCluster,
)
from zhaquirks import Bus
import logging
ZONE_TYPE = 0x0001
LOGGER = logging.getLogger(__name__)
class TuyaSolarRainSensorCluster(TuyaMCUCluster, CustomCluster):
"""Tuya manufacturer cluster."""
attributes = TuyaMCUCluster.attributes.copy()
attributes.update(
{
0xEF65: ("light_intensity", t.uint32_t, True),
0xEF66: ("average_light_intensity_20mins", t.uint32_t, True),
0xEF67: ("todays_max_light_intensity", t.uint32_t, True),
0xEF68: ("cleaning_reminder", t.Bool, True),
0xEF69: ("rain_sensor_voltage", t.uint32_t, True),
}
)
dp_to_attribute: dict[int, DPToAttributeMapping] = {
101: DPToAttributeMapping(
TuyaMCUCluster.ep_attribute,
"light_intensity",
),
102: DPToAttributeMapping(
TuyaMCUCluster.ep_attribute,
"average_light_intensity_20mins",
),
103: DPToAttributeMapping(
TuyaMCUCluster.ep_attribute,
"todays_max_light_intensity",
),
104: DPToAttributeMapping(
TuyaMCUCluster.ep_attribute,
"cleaning_reminder",
),
105: DPToAttributeMapping(
TuyaMCUCluster.ep_attribute,
"rain_sensor_voltage",
),
}
data_point_handlers = {
101: "_dp_2_attr_update",
102: "_dp_2_attr_update",
103: "_dp_2_attr_update",
104: "_dp_2_attr_update",
105: "_dp_2_attr_update",
}
def _update_attribute(self, attrid, value):
super()._update_attribute(attrid, value)
LOGGER.debug(f"Updating attr {hex(attrid)}...")
if attrid == 0xEF65 and value is not None and value >= 0:
LOGGER.debug(
f"Creating illuminance_reported event on illuminance_bus with attrid {hex(attrid)}..."
)
try:
self.endpoint.device.illuminance_bus.listener_event(
"illuminance_reported", value
)
except:
LOGGER.exception("Failed to create illuminance_reported event...")
pass
class TuyaIlluminanceCluster(CustomCluster, IlluminanceMeasurement):
"""Tuya Illuminance cluster."""
cluster_id = IlluminanceMeasurement.cluster_id
MEASURED_VALUE_ATTR_ID = 0x0000
MIN_MEASURED_VALUE_ATTR_ID = 0x0001
MAX_MEASURED_VALUE_ATTR_ID = 0x0001
# The value gets passed through `round(pow(10, ((value - 1) / 10000)))` by ZHA
# https://github.com/zigpy/zha/blob/927e249134c87bd7805139c8fb61e048593ec155/zha/application/platforms/sensor/__init__.py#L782C9-L782C53
CALIBRATION_FACTOR = 7 # dervied from a single comparison against a BH1750 sensor, likely not accurate at all
def __init__(self, *args, **kwargs):
"""Init."""
super().__init__(*args, **kwargs)
LOGGER.debug("Attaching TuyaIlluminanceCluster to listener...")
try:
self.endpoint.device.illuminance_bus.add_listener(self)
LOGGER.debug("TuyaIlluminanceCluster attached to listener.")
except:
LOGGER.exception("Failed to add listener.")
pass
def illuminance_reported(self, value):
"""Illuminance reported."""
calibrated_value = value * self.CALIBRATION_FACTOR
LOGGER.debug(
f"Received illuminance_reported event with value {value}, updating attribute with calibrated value {calibrated_value}..."
)
self._update_attribute(self.MEASURED_VALUE_ATTR_ID, calibrated_value)
LOGGER.debug(f"measured_value attribute updated.")
class TuyaIasZone(CustomCluster, IasZone):
"""IAS Zone for rain sensors."""
_CONSTANT_ATTRIBUTES = {ZONE_TYPE: IasZone.ZoneType.Water_Sensor}
class TuyaSolarRainSensor(EnchantedDevice):
"""TS0207 Rain sensor quirk."""
def __init__(self, *args, **kwargs) -> None:
"""Init."""
self.illuminance_bus = Bus()
LOGGER.debug(f"Bus created.")
super().__init__(*args, **kwargs)
signature = {
MODELS_INFO: [("_TZ3210_tgvtvdoc", "TS0207")],
ENDPOINTS: {
1: {
PROFILE_ID: zha.PROFILE_ID,
DEVICE_TYPE: zha.DeviceType.IAS_ZONE,
INPUT_CLUSTERS: [
Basic.cluster_id,
PowerConfiguration.cluster_id,
Groups.cluster_id,
Scenes.cluster_id,
IasZone.cluster_id,
TuyaMCUCluster.cluster_id,
],
OUTPUT_CLUSTERS: [
Identify.cluster_id,
Groups.cluster_id,
OnOff.cluster_id,
Time.cluster_id,
Ota.cluster_id,
LightLink.cluster_id,
],
},
},
}
replacement = {
ENDPOINTS: {
1: {
PROFILE_ID: zha.PROFILE_ID,
DEVICE_TYPE: zha.DeviceType.IAS_ZONE,
INPUT_CLUSTERS: [
Basic.cluster_id,
Groups.cluster_id,
Scenes.cluster_id,
TuyaNoBindPowerConfigurationCluster,
TuyaIasZone,
TuyaSolarRainSensorCluster,
TuyaIlluminanceCluster,
],
OUTPUT_CLUSTERS: [
Time.cluster_id,
Ota.cluster_id,
],
},
},
} |
And this quirk will be available in next zha uodates, or I need to install manually? |
It'll be available when someone submits a PR for it and it's accepted. Thus far no one has. That said, I like the newly posted quirk, though I have no idea how accurate its light sensor is. Still, that's the fault of the device, not the quirk. |
Light sensor is pretty useless as it depends on mostly direct sunlight to
trigger a seasonable value. There’s no linear behavior as it gets in the
shade, for example.
Rain intensity as well. I could not correlate values with different
patterns of rainfall.
…On Sat, 26 Oct 2024 at 21:21 Sanaki ***@***.***> wrote:
It'll be available when someone submits a PR for it and it's accepted.
Thus far no one has. That said, I like the newly posted quirk, though I
have no idea how accurate its light sensor is. Still, that's the fault of
the device, not the quirk.
—
Reply to this email directly, view it on GitHub
<#3249 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AA5YFMUVJ6LVRMLNBPNORVTZ5QW2PAVCNFSM6AAAAABKY3CGOSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDIMZZG43TQMRZHA>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Solved by sonoff dongle-e firmware update. |
Did you reboot HA? |
Yes after changing the file, I rebooted the whole device. |
@tasomaniac, I had similar symptom with the first reading being stuck. The solution for me was to update the zigbee firmware. YMMV |
Did you get this fixed? If not, could be interesting to see if you're getting any values from Manage Zigbee device > Clusters > TuyaSolarRainSensorCluster > light_intensity |
I got it fixed. Upgrading the zigbee firmware fixed it. After the upgrade, the light sensor value also came back. This may be because of a restart, I'm not sure. But it all works well now. Btw, I do have a "calculated" virtual Illuminance sensor based on the weather forecast. So far the values match. I will report more after observing it more. |
@tasomaniac How did you upgrade the firmware of this sensor? |
Sorry for the confusion. Update is necessary for the zigbee firmware. Not the sensor. |
@tasomaniac Thank you. I have the Conbee 3 from deconz with the newest firmware installed. Sadly the sensor does not work. |
Adds a quirk that fixes this device by changing the "moving" and "closed" sensors to the rain and illuminance sensors that the device actually has. Most of the credit for this code goes to @hadeshimself from [this](zigpy#3249 (comment)) comment.
Adds a quirk that fixes this device by changing the "moving" and "closed" sensors to the rain and illuminance sensors that the device actually has. Most of the credit for this code goes to @hadeshimself from [this](zigpy#3249 (comment)) comment. Fixes zigpy#3249.
Anyone knows when someone submits a PR for this? Can I do anything to get this quirk in zha? Thanks, |
Adds a quirk that fixes this device by changing the "moving" and "closed" sensors to the rain and illuminance sensors that the device actually has. Most of the credit for this code goes to @hadeshimself from [this](zigpy#3249 (comment)) comment. Fixes zigpy#3249.
Now 🙂 |
Ah ok, I understand. You commited the new file to repository and now someone needs to accept. |
Well, maybe you live in a place where it’s always sunny and near the
equator.
…On Wed, 30 Oct 2024 at 17:39 Said Tahsin Dane ***@***.***> wrote:
Here is the chart for today. The illumination sensor is surprisingly
similar to the calculated value from weather forecast.
Screenshot_20241030-213718.png (view on web)
<https://github.com/user-attachments/assets/9d5b965c-e8be-44ef-bf84-c5141f20a49e>
—
Reply to this email directly, view it on GitHub
<#3249 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AA5YFMSVN3J7JG3KL7UMCG3Z6E7XLAVCNFSM6AAAAABKY3CGOSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDINBYGMZDSMBXGY>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Actually it is the contrary. The values were not so high but still accurate. I live in Berlin and it was super cloudy and rainy today |
It seems that there is an error on pull request, no? Is easy to fix it? Thanks for your work. |
To whoever did this: thank you, I just copied and pasted the code, added quircks, and boom! (sorry to add noise to the thread, but I felt the need to thank) |
Yess, now it seems to work like a motion sensor, but pull request is not done, not? |
Any updates to pull request this quirk to zha base quirks? Thanks! |
Problem description
I have a TS0207 battery powered outdoor rain and light intensity sensor:
https://a.aliexpress.com/_EjJGdz9
The sensors are reported as a motion and open/close sensor. It seems like the movement sensor is triggered when rain is detected, but it seems like it is rarely updated.
Solution description
Correctly mapped sensor output so a action can be created.
Screenshots/Video
Screenshots/Video
Device signature
Device signature
Diagnostic information
Diagnostic information
Logs
Logs
Custom quirk
Custom quirk
Additional information
No response
The text was updated successfully, but these errors were encountered: