-
Notifications
You must be signed in to change notification settings - Fork 915
Labels
device support requestThis requests support for a new deviceThis requests support for a new device
Description
Problem description
The device work. But it work as a PIR sensor since i don't have all the option to calibrate mmwave.
Solution description
I try tu use de zigbee2mqtt code and make a custom quirk but it never applied and at this point i'm not good enought
You can still check my code :
from __future__ import annotations
from typing import Any, Final
import zigpy.types as t
from zigpy.profiles import zha
from zigpy.quirks import CustomDevice
from zigpy.zcl import foundation
from zigpy.zcl.clusters.general import (
Basic,
Identify,
PowerConfiguration,
)
from zigpy.zcl.clusters.measurement import (
IlluminanceMeasurement,
RelativeHumidity,
TemperatureMeasurement,
)
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 import (
TuyaManufClusterAttributes,
TuyaPowerConfigurationCluster,
TuyaZBE000Cluster,
)
from zhaquirks.tuya.mcu import DPToAttributeMapping, TuyaMCUCluster
TUYA_CLUSTER_ID: Final = 0xEF00
class TuyaHobeianMotionManufCluster(TuyaMCUCluster):
dp_to_attribute: dict[int, DPToAttributeMapping] = {
1: DPToAttributeMapping(
TuyaZBE000Cluster.ep_attribute,
"occupancy",
dp_type=t.Bool,
),
2: DPToAttributeMapping(
TuyaZBE000Cluster.ep_attribute,
"motion_sensitivity",
dp_type=t.uint32,
),
101: DPToAttributeMapping(
RelativeHumidity.ep_attribute,
"measured_value",
dp_type=t.uint32,
converter=lambda x: x * 100, # Convert to ZCL format (0.01% units)
),
102: DPToAttributeMapping(
TuyaZBE000Cluster.ep_attribute,
"fading_time",
dp_type=t.uint32,
),
104: DPToAttributeMapping(
TuyaZBE000Cluster.ep_attribute,
"humidity_calibration",
dp_type=t.int32,
),
105: DPToAttributeMapping(
TuyaZBE000Cluster.ep_attribute,
"temperature_calibration",
dp_type=t.int32,
converter=lambda x: x * 10, # Convert from 0.1°C to 0.01°C
),
106: DPToAttributeMapping(
IlluminanceMeasurement.ep_attribute,
"measured_value",
dp_type=t.uint32,
),
107: DPToAttributeMapping(
TuyaZBE000Cluster.ep_attribute,
"illuminance_interval",
dp_type=t.uint32,
),
108: DPToAttributeMapping(
TuyaZBE000Cluster.ep_attribute,
"indicator_mode",
dp_type=t.Bool,
),
109: DPToAttributeMapping(
TuyaZBE000Cluster.ep_attribute,
"temperature_unit",
dp_type=t.enum8,
),
110: DPToAttributeMapping(
PowerConfiguration.ep_attribute,
"battery_percentage_remaining",
dp_type=t.uint32,
converter=lambda x: x * 2, # Convert to ZCL format (0-200, where 200=100%)
),
111: DPToAttributeMapping(
TemperatureMeasurement.ep_attribute,
"measured_value",
dp_type=t.int32,
converter=lambda x: x * 10, # Convert from 0.1°C to 0.01°C (ZCL format)
),
}
data_point_handlers = {
1: "_dp_2_attr_update",
2: "_dp_2_attr_update",
101: "_dp_2_attr_update",
102: "_dp_2_attr_update",
104: "_dp_2_attr_update",
105: "_dp_2_attr_update",
106: "_dp_2_attr_update",
107: "_dp_2_attr_update",
108: "_dp_2_attr_update",
109: "_dp_2_attr_update",
110: "_dp_2_attr_update",
111: "_dp_2_attr_update",
}
class TuyaHobeianMotionCluster(TuyaZBE000Cluster):
class AttributeDefs(TuyaZBE000Cluster.AttributeDefs):
occupancy: foundation.ZCLAttributeDef = foundation.ZCLAttributeDef(
id=0x0000, type=t.Bool, access="rp", mandatory=False
)
motion_sensitivity: foundation.ZCLAttributeDef = foundation.ZCLAttributeDef(
id=0x0001, type=t.uint16, access="rw", mandatory=False
)
fading_time: foundation.ZCLAttributeDef = foundation.ZCLAttributeDef(
id=0x0002, type=t.uint32, access="rw", mandatory=False
)
indicator_mode: foundation.ZCLAttributeDef = foundation.ZCLAttributeDef(
id=0x0003, type=t.Bool, access="rw", mandatory=False
)
illuminance_interval: foundation.ZCLAttributeDef = foundation.ZCLAttributeDef(
id=0x0004, type=t.uint16, access="rw", mandatory=False
)
temperature_calibration: foundation.ZCLAttributeDef = foundation.ZCLAttributeDef(
id=0x0005, type=t.int16, access="rw", mandatory=False
)
humidity_calibration: foundation.ZCLAttributeDef = foundation.ZCLAttributeDef(
id=0x0006, type=t.int16, access="rw", mandatory=False
)
temperature_unit: foundation.ZCLAttributeDef = foundation.ZCLAttributeDef(
id=0x0007, type=t.enum8, access="rw", mandatory=False
)
def _update_attribute(self, attrid: int, value: Any) -> None:
super()._update_attribute(attrid, value)
if attrid == self.AttributeDefs.occupancy.id:
ias_cluster = self.endpoint.ias_zone
if ias_cluster:
# Convert presence to IAS Zone status
zone_status = 1 if value else 0 # 1 = alarm, 0 = normal
ias_cluster._update_attribute(
ias_cluster.AttributeDefs.zone_status.id, zone_status
)
class HobeianZG204ZV(CustomDevice):
signature = {
MODELS_INFO: [("HOBEIAN", "ZG-204ZV")],
ENDPOINTS: {
1: {
PROFILE_ID: zha.PROFILE_ID,
DEVICE_TYPE: zha.DeviceType.IAS_ZONE,
INPUT_CLUSTERS: [
Basic.cluster_id, # 0x0000
PowerConfiguration.cluster_id, # 0x0001
Identify.cluster_id, # 0x0003
IlluminanceMeasurement.cluster_id, # 0x0400
TemperatureMeasurement.cluster_id, # 0x0402
RelativeHumidity.cluster_id, # 0x0405
IasZone.cluster_id, # 0x0500
TUYA_CLUSTER_ID, # 0xEF00
],
OUTPUT_CLUSTERS: [Identify.cluster_id],
}
},
}
replacement = {
ENDPOINTS: {
1: {
PROFILE_ID: zha.PROFILE_ID,
DEVICE_TYPE: zha.DeviceType.IAS_ZONE,
INPUT_CLUSTERS: [
Basic.cluster_id,
TuyaPowerConfigurationCluster,
Identify.cluster_id,
IlluminanceMeasurement.cluster_id,
TemperatureMeasurement.cluster_id,
RelativeHumidity.cluster_id,
IasZone.cluster_id,
TuyaHobeianMotionCluster,
TuyaHobeianMotionManufCluster,
],
OUTPUT_CLUSTERS: [Identify.cluster_id],
}
}
}
device_automation_triggers = {
("occupancy", "on"): {
"device_automation_type": "occupancy",
"trigger_type": "motion",
},
("occupancy", "off"): {
"device_automation_type": "occupancy",
"trigger_type": "no_motion",
},
}
Screenshots/Video
Screenshots/Video
[Paste/upload your media here]
Diagnostics information
Paramètres HomeAssistant (3).json
Device signature
Device signature
[Paste the device signature here]
Logs
Logs
[Paste the logs here]Custom quirk
Custom quirk
[Paste your custom quirk here]Additional information
No response
seatsea, EnderBow and zutto
Metadata
Metadata
Assignees
Labels
device support requestThis requests support for a new deviceThis requests support for a new device