Open TommisGR opened 1 year ago
The quirk before the last one works once I restart the full raspberry. Something was broken without restarting.
https://github.com/Koenkk/zigbee2mqtt/issues/13097 looks like same device has some info on additional DP
What follows ids from that post
DP 17 Alarm set ( if Alarm 2 not 'null') Alarm 1 - OverVoltage, 261V, Control On Alarm 2 - OverCurrent, 40A, Control On DP 11 Frozen set - day if month 22, hour of day - 15
2022-07-23T11:30:25 0xa4c1383a1774b16b (seq: 256, value: #0) [DP 6 Phase A] => raw: [ 8 194 0 0 0 0 0 0 ]
2022-07-23T11:30:26 0xa4c1383a1774b16b (seq: 512, value: #0) [DP 1 Forward energy total ] => int: 59
2022-07-23T11:30:26 0xa4c1383a1774b16b (seq: 768, value: #0) [DP 3 month energy] => raw: [ 22 7 22 7 0 0 0 0 ]
2022-07-23T11:30:26 0xa4c1383a1774b16b (seq: 1024, value: #0) [DP 4 daily energy] => raw: [ 7 23 7 23 0 0 0 0 ]
2022-07-23T11:30:26 0xa4c1383a1774b16b (seq: 1280, value: #0) [DP 11 Frozen set] => raw: [ 22 15 ]
2022-07-23T11:30:26 0xa4c1383a1774b16b (seq: 1536, value: #0) [DP 17 Alarm set] => raw: [ 3 1 1 5 1 1 0 40 ]
2022-07-23T11:30:26 0xa4c1383a1774b16b (seq: 1792, value: #0) [DP 16 switch ] => bool: True
2022-07-23T11:30:26 0xa4c1383a1774b16b (seq: 1792, value: #1) [DP 18 Meter ID ] => string: 22062315
2022-07-26T21:12:35 0xa4c1383a1774b16b (seq: 6400, value: #0) [DP 10 Fault ] => bitmap: 00000000 00000000 000000
Maybe we can update the quirk to get all the values...
i wouldnt know where to start maybe if someone held our hands for a bit :) like javicalle did.
As far as I know we must configure the DP numbers as attributes as we made with 11, 6 and 4 to match the typical smart energy cluster device. I can try some test after I don't have time right now.
I made a mod to AC_VOLTAGE_MULTIPLIER to get the right value... I defined the constant and then assigned a value of 2.
Now I see the correct Voltage in HA. I know is not much but I'm making slowly progress understanding how all this works.
@TommisGR if you want to update your quirk there's mine with the correct voltage.
How I made it: Multiply the voltage "value" twice didn't work for me. I have to touch the constant voltage modifier.
Defined the multiplier:
AC_VOLTAGE_MULTIPLIER = 0x0600
And then passed it to cluster with value of "2"
_CONSTANT_ATTRIBUTES = {AC_CURRENT_MULTIPLIER: 1, AC_CURRENT_DIVISOR: 1000, AC_VOLTAGE_MULTIPLIER: 2}
Full quirk:
"""Tuya Din Power Meter."""
from zigpy.profiles import zha
import zigpy.types as t
from zigpy.zcl.clusters.general import Basic, Groups, Ota, Scenes, Time, GreenPowerProxy
from zigpy.zcl.clusters.homeautomation import ElectricalMeasurement
from zigpy.zcl.clusters.smartenergy import Metering
from zhaquirks import Bus, LocalDataCluster
from zhaquirks.const import (
DEVICE_TYPE,
ENDPOINTS,
INPUT_CLUSTERS,
MODELS_INFO,
OUTPUT_CLUSTERS,
PROFILE_ID,
)
from zhaquirks.tuya import TuyaManufClusterAttributes, TuyaOnOff, TuyaSwitch
TUYA_TOTAL_ENERGY_ATTR = 0x0201 #total energy /100 0x0211
TUYA_CURRENT_ATTR = 0x0011 #0x0212
TUYA_POWER_ATTR = 0x0006 #0x0213
TUYA_VOLTAGE_ATTR = 0x0004 #0x0214
TUYA_DIN_SWITCH_ATTR = 0x000b #0x0101
SWITCH_EVENT = "switch_event"
class TuyaManufClusterDinPower(TuyaManufClusterAttributes):
"""Manufacturer Specific Cluster of the Tuya Power Meter device."""
attributes = {
TUYA_TOTAL_ENERGY_ATTR: ("energy", t.uint16_t, True),
TUYA_CURRENT_ATTR: ("current", t.int16s, True), #t.int16s
TUYA_POWER_ATTR: ("power", t.uint16_t, True), #t.uint16_t
TUYA_VOLTAGE_ATTR: ("voltage", t.uint16_t, True),
TUYA_DIN_SWITCH_ATTR: ("switch", t.uint8_t, True),
}
def _update_attribute(self, attrid, value):
super()._update_attribute(attrid, value)
if attrid == TUYA_TOTAL_ENERGY_ATTR:
self.endpoint.smartenergy_metering.energy_reported(value / 100)
elif attrid == TUYA_CURRENT_ATTR:
self.endpoint.electrical_measurement.current_reported(value)
elif attrid == TUYA_POWER_ATTR:
self.endpoint.electrical_measurement.power_reported(value) # / 10
elif attrid == TUYA_VOLTAGE_ATTR:
self.endpoint.electrical_measurement.voltage_reported(value / 10 )
elif attrid == TUYA_DIN_SWITCH_ATTR:
self.endpoint.device.switch_bus.listener_event(
SWITCH_EVENT, self.endpoint.endpoint_id, value
)
class TuyaPowerMeasurement(LocalDataCluster, ElectricalMeasurement):
"""Custom class for power, voltage and current measurement."""
cluster_id = ElectricalMeasurement.cluster_id
POWER_ID = 0x050b #0x050B
VOLTAGE_ID = 0x0505
CURRENT_ID = 0x0508
AC_CURRENT_MULTIPLIER = 0x0602
AC_CURRENT_DIVISOR = 0x0603
AC_VOLTAGE_MULTIPLIER = 0x0600
_CONSTANT_ATTRIBUTES = {AC_CURRENT_MULTIPLIER: 1, AC_CURRENT_DIVISOR: 1000, AC_VOLTAGE_MULTIPLIER: 2}
def voltage_reported(self, value):
"""Voltage reported."""
self._update_attribute(self.VOLTAGE_ID, value)
def power_reported(self, value):
"""Power reported."""
self._update_attribute(self.POWER_ID, value)
def current_reported(self, value):
"""Ampers reported."""
self._update_attribute(self.CURRENT_ID, value)
class TuyaElectricalMeasurement(LocalDataCluster, Metering):
"""Custom class for total energy measurement."""
cluster_id = Metering.cluster_id
CURRENT_ID = 0x0000
POWER_WATT = 0x0000
"""Setting unit of measurement."""
_CONSTANT_ATTRIBUTES = {0x0300: POWER_WATT}
def energy_reported(self, value):
"""Summation Energy reported."""
self._update_attribute(self.CURRENT_ID, value)
class TuyaPowerMeter(TuyaSwitch):
"""Tuya power meter device."""
def __init__(self, *args, **kwargs):
"""Init device."""
self.switch_bus = Bus()
super().__init__(*args, **kwargs)
signature = {
# "node_descriptor": "<NodeDescriptor byte1=1 byte2=64 mac_capability_flags=142 manufacturer_code=4098
# maximum_buffer_size=82 maximum_incoming_transfer_size=82 server_mask=11264
# maximum_outgoing_transfer_size=82 descriptor_capability_field=0>",
# device_version=1
# input_clusters=[0x0000, 0x0004, 0x0005, 0xef00]
# output_clusters=[0x000a, 0x0019]
MODELS_INFO: [
("_TZE200_byzdayie", "TS0601"),
("_TZE200_ewxhg6o9", "TS0601"),
],
ENDPOINTS: {
# <SimpleDescriptor endpoint=1 profile=260 device_type=51
# device_version=1
# input_clusters=[0, 4, 5, 61184]
# output_clusters=[10, 25]>
1: {
PROFILE_ID: zha.PROFILE_ID,
DEVICE_TYPE: zha.DeviceType.SMART_PLUG,
INPUT_CLUSTERS: [
Basic.cluster_id,
Groups.cluster_id,
Scenes.cluster_id,
TuyaManufClusterAttributes.cluster_id,
],
OUTPUT_CLUSTERS: [Time.cluster_id, Ota.cluster_id],
}
},
}
replacement = {
ENDPOINTS: {
1: {
PROFILE_ID: zha.PROFILE_ID,
DEVICE_TYPE: zha.DeviceType.SMART_PLUG,
INPUT_CLUSTERS: [
Basic.cluster_id,
Groups.cluster_id,
Scenes.cluster_id,
TuyaManufClusterDinPower,
TuyaPowerMeasurement,
TuyaElectricalMeasurement,
TuyaOnOff,
],
OUTPUT_CLUSTERS: [Time.cluster_id, Ota.cluster_id],
}
}
}
class TuyaPowerMeter_GPP(TuyaSwitch):
"""Tuya power meter device."""
def __init__(self, *args, **kwargs):
"""Init device."""
self.switch_bus = Bus()
super().__init__(*args, **kwargs)
signature = {
# "node_descriptor": "<NodeDescriptor byte1=1 byte2=64 mac_capability_flags=142 manufacturer_code=4417
# maximum_buffer_size=66 maximum_incoming_transfer_size=66 server_mask=10752
# maximum_outgoing_transfer_size=66 descriptor_capability_field=0>",
# device_version=1
# input_clusters=[0x0000, 0x0004, 0x0005, 0xef00]
# output_clusters=[0x000a, 0x0019]
MODELS_INFO: [
("_TZE200_lsanae15", "TS0601"),
],
ENDPOINTS: {
# <SimpleDescriptor endpoint=1 profile=260 device_type=51
# device_version=1
# input_clusters=[0, 4, 5, 61184]
# output_clusters=[10, 25]>
1: {
PROFILE_ID: zha.PROFILE_ID,
DEVICE_TYPE: zha.DeviceType.SMART_PLUG,
INPUT_CLUSTERS: [
Basic.cluster_id,
Groups.cluster_id,
Scenes.cluster_id,
TuyaManufClusterAttributes.cluster_id,
],
OUTPUT_CLUSTERS: [Time.cluster_id, Ota.cluster_id],
},
242: {
# <SimpleDescriptor endpoint=242 profile=41440 device_type=61
# input_clusters=[]
# output_clusters=[21]
PROFILE_ID: 41440,
DEVICE_TYPE: 97,
INPUT_CLUSTERS: [],
OUTPUT_CLUSTERS: [GreenPowerProxy.cluster_id],
},
},
}
replacement = {
ENDPOINTS: {
1: {
PROFILE_ID: zha.PROFILE_ID,
DEVICE_TYPE: zha.DeviceType.SMART_PLUG,
INPUT_CLUSTERS: [
Basic.cluster_id,
Groups.cluster_id,
Scenes.cluster_id,
TuyaManufClusterDinPower,
TuyaPowerMeasurement,
TuyaElectricalMeasurement,
TuyaOnOff,
],
OUTPUT_CLUSTERS: [Time.cluster_id, Ota.cluster_id],
},
242: {
# <SimpleDescriptor endpoint=242 profile=41440 device_type=61
# input_clusters=[]
# output_clusters=[21]
PROFILE_ID: 41440,
DEVICE_TYPE: 97,
INPUT_CLUSTERS: [],
OUTPUT_CLUSTERS: [GreenPowerProxy.cluster_id],
},
}
}
Hello, thank you all for the support and support the integration of this device into zha. in my case I have copied the last of the codes and it seems that the Switch button : on/off does not work
here log received after press on/off switch:
Did someone made progress on this quirk? Got the device today. Tried above, active powers seems only thing to be reading right. in my case. Switch control still does not work.
Thanks!
The switch works for me.
How did you fix it?
I just posted the quirk in the correct place and rejoined. Sometimes if you put the quirk after join some functions are invisible. Unlink, put the quirk, restart the HA and the force the join again. You can see the switch control there:
So is there a chance we'll get this into a release so it's usable for everyone?
Is the quirk from this comment the latest quirk that works? If so, would you mind creating a PR for this (or should I create a PR to make this usable for everyone)?
As per bsj17, I only see a switch which doesn't appear to work, (not metered it out yet) and power factor unknown using [RealKanashii]'s quirk above.
2023-01-06 23:02:44.911 DEBUG (MainThread) [zigpy_deconz.api] Received command aps_data_indication[35, <DeviceState.APSDE_DATA_REQUEST_SLOTS_AVAILABLE|2: 34>,
Is your feature request related to a problem? Please describe. tuya Din Rail Power Meter recognized as TS0601 by _TZE200_lsanae15 Only entities created are LQI and RSSI
Describe the solution you'd like To be able to report Power usage
Device signature
``` { "node_descriptor": "NodeDescriptor(logical_type=Diagnostic information
```yaml { "home_assistant": { "installation_type": "Home Assistant OS", "version": "2022.8.7", "dev": false, "hassio": true, "virtualenv": false, "python_version": "3.10.5", "docker": true, "arch": "aarch64", "timezone": "Europe/Athens", "os_name": "Linux", "os_version": "5.15.32-v8", "supervisor": "2022.08.6", "host_os": "Home Assistant OS 8.5", "docker_version": "20.10.14", "chassis": "embedded", "run_as_root": true }, "custom_components": { "hacs": { "version": "1.27.2", "requirements": [ "aiogithubapi>=22.2.4" ] }, "watchman": { "version": "0.5.1", "requirements": [ "prettytable==3.0.0" ] }, "ble_monitor": { "version": "10.0.0", "requirements": [ "pycryptodomex>=3.14.1", "janus>=1.0.0", "aioblescan>=0.2.13", "btsocket>=0.2.0", "pyric>=0.1.6.3" ] }, "mopidy": { "version": "1.4.6", "requirements": [ "mopidyapi==1.0.0" ] }, "androidtv_custom": { "version": "0.1.0", "requirements": [ "adb-shell[async]==0.4.2", "androidtv[async]==0.0.67", "pure-python-adb[async]==0.3.0.dev0" ] }, "tapo": { "version": "1.2.15", "requirements": [ "plugp100==2.1.18" ] }, "sonoff": { "version": "3.2.0", "requirements": [ "pycryptodome>=3.6.6" ] } }, "integration_manifest": { "domain": "zha", "name": "Zigbee Home Automation", "config_flow": true, "documentation": "https://www.home-assistant.io/integrations/zha", "requirements": [ "bellows==0.33.1", "pyserial==3.5", "pyserial-asyncio==0.6", "zha-quirks==0.0.78", "zigpy-deconz==0.18.0", "zigpy==0.50.2", "zigpy-xbee==0.15.0", "zigpy-zigate==0.9.2", "zigpy-znp==0.8.2" ], "usb": [ { "vid": "10C4", "pid": "EA60", "description": "*2652*", "known_devices": [ "slae.sh cc2652rb stick" ] }, { "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": "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" ] } ], "codeowners": [ "@dmulcahey", "@adminiuga", "@puddly" ], "zeroconf": [ { "type": "_esphomelib._tcp.local.", "name": "tube*" }, { "type": "_zigate-zigbee-gateway._tcp.local.", "name": "*zigate*" } ], "after_dependencies": [ "onboarding", "usb", "zeroconf" ], "iot_class": "local_polling", "loggers": [ "aiosqlite", "bellows", "crccheck", "pure_pcapy3", "zhaquirks", "zigpy", "zigpy_deconz", "zigpy_xbee", "zigpy_zigate", "zigpy_znp" ], "is_built_in": true }, "data": { "ieee": "**REDACTED**", "nwk": 56904, "manufacturer": "_TZE200_lsanae15", "model": "TS0601", "name": "_TZE200_lsanae15 TS0601", "quirk_applied": false, "quirk_class": "zigpy.device.Device", "manufacturer_code": 4417, "power_source": "Mains", "lqi": 100, "rssi": -75, "last_seen": "2022-09-18T15:51:59", "available": true, "device_type": "Router", "signature": { "node_descriptor": "NodeDescriptor(logical_type=Additional logs
``` Paste any additional debug logs here. Don't remove the extra line breaks outside the ``` marks. ```Additional context Add any other context or screenshots about the feature request here. https://www.aliexpress.com/item/1005004399475951.html