Open centershock opened 2 years ago
Can you try with this formula?
converter=lambda x: 10000 * math.log10(x + 1)
Can you try with this formula?
converter=lambda x: 10000 * math.log10(x + 1)
Sorry... I should have updated the thread, but I finished this yesterday too late... I managed to solve it/workaround it by using this (I got it from another issue): converter=lambda x: (10000.0 * math.log10(x) + 1.0 if x != 0 else 0),
not sure which one would be better. The problem is that in fact the sensor returns 0 in dark conditions. And math.log10(0) raises an error. So I'm sure your suggestion would work. Which one would be better? I was doing some tests and apparently the range of values I get are not between 1-1000 (max I've seen was 960).
Thank you!
I was doing some tests and apparently the range of values I get are not between 1-1000 (max I've seen was 960).
Thank you!
Sorry... (again). I meant that the values I get ARE between 1-1000 which sound reasonable...
I was doing some tests and apparently the range of values I get are not between 1-1000 (max I've seen was 960). Thank you!
Sorry... (again). I meant that the values I get ARE between 1-1000 which sound reasonable...
But you are getting 0 values, if not this wouldn't be needed:
if x != 0 else 0
I was doing some tests and apparently the range of values I get are not between 1-1000 (max I've seen was 960). Thank you!
Sorry... (again). I meant that the values I get ARE between 1-1000 which sound reasonable...
But you are getting 0 values, if not this wouldn't be needed:
if x != 0 else 0
I'm not making myself clear... what I intended to say was that yes, the "x" receives 0 (I assume this is the value returned by the sensor). And math.log10(0) raises an error. But with the formula:
converter=lambda x: (10000.0 * math.log10(x) + 1.0 if x != 0 else 0),
what I get in HA when I check the entity are values between 1 and ~1000 (if I point a mobile phone flash light I get for example 960 or 980). And it responds to different light conditions with values somewhere inside this range. I was wondering which formula you would think it would be better (I'd say they would give ver similar values) and also if you think this range of values is reasonable.
Thanks for your support.
also if you think this range of values is reasonable
I can't say it because these are not familiar to me. I'm sure that both formulas would give a similar values/behavior. But the one I suggest wouldn't give negative values for illumination when 0<x<1 🤷🏻♂️
Anyone can create the PR with the proposed quirk and I'm sure that would be accepted as is.
https://github.com/zigpy/zha-device-handlers/issues/1502#issuecomment-1378743535 Cette solution fonctionne avec un _TZE200_pay2byax Merci de votre travail
https://github.com/zigpy/zha-device-handlers/issues/1502#issuecomment-1378743535 This solution works with a _TZE200_pay2byax Thank you for your work
Hello, after last update HA to 2023.3 this quirks generate error and all Zigbee Integration cannot load. i have to remove from custom_zha_quirks any solution?
Hello, after last update HA to 2023.3 this quirks generate error and all Zigbee Integration cannot load. i have to remove from custom_zha_quirks any solution?
I had issues with the quirk also and then some errors in some automations based on Zigbee buttons. I didn't try to remove the quirk to understand if the other issues were related.... I just restored the backup... meanwhile I see version 2023.3.1 but HA insists that the latest one is 2023.3.0.... I'll get back to this when 3.1 is possible to install... The error complains about an import of some Tuya classes....
I cleaned up some of the examples above and made sure to include illuminance. Battery percentage is still always 0%, though.
Check the logs for any No 'handle_set_data_response' tuya handler found...
error.
Battery can get some time to report.
You can enable the debug logs and trigger the contact sensor (open/close) to see what is reporting.
Hello where i can download the definitve editions of this quirk?
Bonjour, où puis-je télécharger les éditions définitives de cette bizarrerie ?
il faut corriger comme ceci , en tous cas pour moi ca fonctionne ! https://github.com/zigpy/zha-device-handlers/issues/2241#issuecomment-1453079929
Guys I don't have battery readout with this quirk.
I've recklessly replaced DoublingPowerConfigurationCluster
with TuyaPowerConfigurationCluster
in the code of this quirk and now I'm having 100% but no idea if this is correct (of course if % changes I'll report back.
Guys I don't have battery readout with this quirk. I've recklessly replaced
DoublingPowerConfigurationCluster
withTuyaPowerConfigurationCluster
in the code of this quirk and now I'm having 100% but no idea if this is correct (of course if % changes I'll report back.
@elmystico any update on your battery reading modification ? thanks.
@elmystico any update on your battery reading modification ? thanks. @schnudeldudel Unfortunately I had a crash in HA recently so i removed all additional code, historical data got lost, no idea if % changed
Still not getting it to work.
{ "node_descriptor": "NodeDescriptor(logical_type=<LogicalType.EndDevice: 2>, complex_descriptor_available=0, user_descriptor_available=0, reserved=0, aps_flags=0, frequency_band=<FrequencyBand.Freq2400MHz: 8>, mac_capability_flags=<MACCapabilityFlags.AllocateAddress: 128>, manufacturer_code=4417, maximum_buffer_size=66, maximum_incoming_transfer_size=66, server_mask=10752, maximum_outgoing_transfer_size=66, descriptor_capability_field=<DescriptorCapability.NONE: 0>, *allocate_address=True, *is_alternate_pan_coordinator=False, *is_coordinator=False, *is_end_device=True, *is_full_function_device=False, *is_mains_powered=False, *is_receiver_on_when_idle=False, *is_router=False, *is_security_capable=False)", "endpoints": { "1": { "profile_id": "0x0104", "device_type": "0x0402", "input_clusters": [ "0x0000", "0x0001", "0x0003", "0x0400", "0x0500", "0xe002", "0xef00" ], "output_clusters": [] } }, "manufacturer": "_TZE200_pay2byax", "model": "TS0601", "class": "zigpy.device.Device" }
It dont update at all. I've try all the custom quirk's in this topic but no working device.
@schnudeldudel hello again. i've got this back and running. Battery state uncofirmed unfortunatelly. I can tell that it gets reported 100% but no change. Contact switch and luminance works flawlessly thou. Heres the quirk
"""Tuya contact sensor device."""
import math
from typing import Dict
from zigpy.profiles import zha
from zigpy.quirks import CustomDevice
from zigpy.zcl.clusters.general import Basic, Groups, Ota, PowerConfiguration, Time
from zigpy.zcl.clusters.measurement import IlluminanceMeasurement
from zigpy.zcl.clusters.security import IasZone
#from zhaquirks import DoublingPowerConfigurationCluster
from zhaquirks.const import (
DEVICE_TYPE,
ENDPOINTS,
INPUT_CLUSTERS,
MODELS_INFO,
OUTPUT_CLUSTERS,
PROFILE_ID,
ZONE_TYPE,
)
from zhaquirks.tuya import TuyaLocalCluster
from zhaquirks.tuya.mcu import (
DPToAttributeMapping,
TuyaMCUCluster,
TuyaPowerConfigurationCluster,
)
IASZONE_ZONE_STATUS_ATTR = 0x0002
class ContactSwitchCluster(TuyaLocalCluster, IasZone):
"""Tuya ContactSwitch Sensor."""
_CONSTANT_ATTRIBUTES = {ZONE_TYPE: IasZone.ZoneType.Contact_Switch}
def _update_attribute(self, attrid, value):
self.debug("_update_attribute '%s': %s", attrid, value)
super()._update_attribute(attrid, value)
class TuyaIlluminanceMeasurement(IlluminanceMeasurement, TuyaLocalCluster):
"""Tuya local IlluminanceMeasurement cluster."""
class ContactSwitchManufCluster(TuyaMCUCluster):
"""Tuya Manufacturer Cluster with ContactSwitch Sensor data points."""
dp_to_attribute: Dict[int, DPToAttributeMapping] = {
1: DPToAttributeMapping(
ContactSwitchCluster.ep_attribute,
"zone_status",
converter=lambda x: IasZone.ZoneStatus.Alarm_1 if x else 0,
),
2: DPToAttributeMapping(
TuyaPowerConfigurationCluster.ep_attribute,
"battery_percentage_remaining", # 0x0021
),
101: DPToAttributeMapping(
TuyaIlluminanceMeasurement.ep_attribute,
"measured_value",
#converter=lambda x: 10000.0 * math.log10(x + 1.0),
converter=lambda x: (10000.0 * math.log10(x) + 1.0 if x != 0 else 0),
),
}
data_point_handlers = {
1: "_dp_2_attr_update",
2: "_dp_2_attr_update",
101: "_dp_2_attr_update",
}
class TuyaContactSensor(CustomDevice):
"""Tuya contact sensor device."""
signature = {
# NodeDescriptor(logical_type=<LogicalType.EndDevice: 2>, complex_descriptor_available=0, user_descriptor_available=0, reserved=0, aps_flags=0, frequency_band=<FrequencyBand.Freq2400MHz: 8>, mac_capability_flags=<MACCapabilityFlags.AllocateAddress: 128>, manufacturer_code=4417, maximum_buffer_size=66, maximum_incoming_transfer_size=66, server_mask=10752, maximum_outgoing_transfer_size=66, descriptor_capability_field=<DescriptorCapability.NONE: 0>, *allocate_address=True, *is_alternate_pan_coordinator=False, *is_coordinator=False, *is_end_device=True, *is_full_function_device=False, *is_mains_powered=False, *is_receiver_on_when_idle=False, *is_router=False, *is_security_capable=False)]
# device_version=1
# SizePrefixedSimpleDescriptor(endpoint=1, profile=260, device_type=1026, device_version=1,
# input_clusters=[0, 1, 1280],
# output_clusters=[10, 25])
MODELS_INFO: [("_TZE200_pay2byax", "TS0601")],
ENDPOINTS: {
1: {
PROFILE_ID: zha.PROFILE_ID,
DEVICE_TYPE: zha.DeviceType.IAS_ZONE,
INPUT_CLUSTERS: [
Basic.cluster_id,
PowerConfiguration.cluster_id,
IasZone.cluster_id,
],
OUTPUT_CLUSTERS: [Time.cluster_id, Ota.cluster_id],
}
},
}
replacement = {
ENDPOINTS: {
1: {
INPUT_CLUSTERS: [
Basic.cluster_id,
Groups.cluster_id,
# DoublingPowerConfigurationCluster,
TuyaPowerConfigurationCluster,
ContactSwitchCluster,
ContactSwitchManufCluster,
TuyaIlluminanceMeasurement,
],
OUTPUT_CLUSTERS: [Time.cluster_id, Ota.cluster_id],
}
}
}
@schnudeldudel battery indicator started to change but this is just 100/500% values only. Something is not right
@schnudeldudel hello again. i've got this back and running. Battery state uncofirmed unfortunatelly. I can tell that it gets reported 100% but no change. Contact switch and luminance works flawlessly thou. Heres the quirk
"""Tuya contact sensor device.""" import math from typing import Dict from zigpy.profiles import zha from zigpy.quirks import CustomDevice from zigpy.zcl.clusters.general import Basic, Groups, Ota, PowerConfiguration, Time from zigpy.zcl.clusters.measurement import IlluminanceMeasurement from zigpy.zcl.clusters.security import IasZone #from zhaquirks import DoublingPowerConfigurationCluster from zhaquirks.const import ( DEVICE_TYPE, ENDPOINTS, INPUT_CLUSTERS, MODELS_INFO, OUTPUT_CLUSTERS, PROFILE_ID, ZONE_TYPE, ) from zhaquirks.tuya import TuyaLocalCluster from zhaquirks.tuya.mcu import ( DPToAttributeMapping, TuyaMCUCluster, TuyaPowerConfigurationCluster, ) IASZONE_ZONE_STATUS_ATTR = 0x0002 class ContactSwitchCluster(TuyaLocalCluster, IasZone): """Tuya ContactSwitch Sensor.""" _CONSTANT_ATTRIBUTES = {ZONE_TYPE: IasZone.ZoneType.Contact_Switch} def _update_attribute(self, attrid, value): self.debug("_update_attribute '%s': %s", attrid, value) super()._update_attribute(attrid, value) class TuyaIlluminanceMeasurement(IlluminanceMeasurement, TuyaLocalCluster): """Tuya local IlluminanceMeasurement cluster.""" class ContactSwitchManufCluster(TuyaMCUCluster): """Tuya Manufacturer Cluster with ContactSwitch Sensor data points.""" dp_to_attribute: Dict[int, DPToAttributeMapping] = { 1: DPToAttributeMapping( ContactSwitchCluster.ep_attribute, "zone_status", converter=lambda x: IasZone.ZoneStatus.Alarm_1 if x else 0, ), 2: DPToAttributeMapping( TuyaPowerConfigurationCluster.ep_attribute, "battery_percentage_remaining", # 0x0021 ), 101: DPToAttributeMapping( TuyaIlluminanceMeasurement.ep_attribute, "measured_value", #converter=lambda x: 10000.0 * math.log10(x + 1.0), converter=lambda x: (10000.0 * math.log10(x) + 1.0 if x != 0 else 0), ), } data_point_handlers = { 1: "_dp_2_attr_update", 2: "_dp_2_attr_update", 101: "_dp_2_attr_update", } class TuyaContactSensor(CustomDevice): """Tuya contact sensor device.""" signature = { # NodeDescriptor(logical_type=<LogicalType.EndDevice: 2>, complex_descriptor_available=0, user_descriptor_available=0, reserved=0, aps_flags=0, frequency_band=<FrequencyBand.Freq2400MHz: 8>, mac_capability_flags=<MACCapabilityFlags.AllocateAddress: 128>, manufacturer_code=4417, maximum_buffer_size=66, maximum_incoming_transfer_size=66, server_mask=10752, maximum_outgoing_transfer_size=66, descriptor_capability_field=<DescriptorCapability.NONE: 0>, *allocate_address=True, *is_alternate_pan_coordinator=False, *is_coordinator=False, *is_end_device=True, *is_full_function_device=False, *is_mains_powered=False, *is_receiver_on_when_idle=False, *is_router=False, *is_security_capable=False)] # device_version=1 # SizePrefixedSimpleDescriptor(endpoint=1, profile=260, device_type=1026, device_version=1, # input_clusters=[0, 1, 1280], # output_clusters=[10, 25]) MODELS_INFO: [("_TZE200_pay2byax", "TS0601")], ENDPOINTS: { 1: { PROFILE_ID: zha.PROFILE_ID, DEVICE_TYPE: zha.DeviceType.IAS_ZONE, INPUT_CLUSTERS: [ Basic.cluster_id, PowerConfiguration.cluster_id, IasZone.cluster_id, ], OUTPUT_CLUSTERS: [Time.cluster_id, Ota.cluster_id], } }, } replacement = { ENDPOINTS: { 1: { INPUT_CLUSTERS: [ Basic.cluster_id, Groups.cluster_id, # DoublingPowerConfigurationCluster, TuyaPowerConfigurationCluster, ContactSwitchCluster, ContactSwitchManufCluster, TuyaIlluminanceMeasurement, ], OUTPUT_CLUSTERS: [Time.cluster_id, Ota.cluster_id], } } }
Hello with this quirks battery working for me
This quirk works perfectly with a TZE200_fwoorn8y TS0601 door and window sensor.
Is your feature request related to a problem? Please describe. The device is not supported, I request a full support of this device.
Describe the solution you'd like Full support for the device, primarily to check "open" and "close" of a window / door.
Device signature - this can be acquired by removing the device from ZHA and pairing it again from the add devices screen. Be sure to add the entire content of the log panel after pairing the device to a code block below this line.
Join logs:
Additional context Add any other context or screenshots about the feature request here.