zigpy / zha-device-handlers

ZHA device handlers bridge the functionality gap created when manufacturers deviate from the ZCL specification, handling deviations and exceptions by parsing custom messages to and from Zigbee devices.
Apache License 2.0
685 stars 638 forks source link

[Device Support Request] Tuya Smart Zigbee Power Meter ATMS1603 TS011F _TZ3000_9ni6xxld #2364

Closed saintfrater closed 3 months ago

saintfrater commented 1 year ago

Problem description

The device has no quirks in ZHA. ZHA add control (switch) that doesn't exist, it's also report sensors (temperature) that maybe doesn't exist, and wrong values (RMS Current are 1000x too high) also summation delivered is wrong. I've also doubt about the "active power" that could be too low (calculated with 110V instead of 230V)

Solution description

The device has no "quirks" and is not correctly handled.

can you add support for this device ?

Screenshots/Video

Screenshots/Video this is the device in "normal" mode (switch off) ![image](https://user-images.githubusercontent.com/13979047/235101868-f183c029-fcc3-478d-a3ce-5767b0ec81c7.png) when the device is "activate" (switch on) ![image](https://user-images.githubusercontent.com/13979047/235102426-a3037512-e665-4404-99c6-1d0656685624.png)

Device signature

Device signature ```json { "node_descriptor": "NodeDescriptor(logical_type=, complex_descriptor_available=0, user_descriptor_available=0, reserved=0, aps_flags=0, frequency_band=, mac_capability_flags=, manufacturer_code=4098, maximum_buffer_size=82, maximum_incoming_transfer_size=82, server_mask=11264, maximum_outgoing_transfer_size=82, descriptor_capability_field=, *allocate_address=True, *is_alternate_pan_coordinator=False, *is_coordinator=False, *is_end_device=False, *is_full_function_device=True, *is_mains_powered=True, *is_receiver_on_when_idle=True, *is_router=True, *is_security_capable=False)", "endpoints": { "1": { "profile_id": 260, "device_type": "0x010a", "in_clusters": [ "0x0000", "0x0003", "0x0004", "0x0005", "0x0006", "0x0402", "0x0702", "0x0b04", "0xe000", "0xe001" ], "out_clusters": [ "0x000a", "0x0019" ] }, "242": { "profile_id": 41440, "device_type": "0x0061", "in_clusters": [], "out_clusters": [ "0x0021" ] } }, "manufacturer": "_TZ3000_9ni6xxld", "model": "TS011F", "class": "zigpy.device.Device" } ```

Diagnostic information

Diagnostic information ```json { "home_assistant": { "installation_type": "Home Assistant Core", "version": "2023.4.6", "dev": false, "hassio": false, "virtualenv": true, "python_version": "3.10.8", "docker": false, "arch": "x86_64", "timezone": "Europe/Brussels", "os_name": "Linux", "os_version": "5.10.0-21-amd64", "run_as_root": false }, "custom_components": { "hacs": { "version": "1.32.1", "requirements": [ "aiogithubapi>=22.10.1" ] }, "toyota": { "version": "1.2.11", "requirements": [ "mytoyota==0.7.8", "arrow" ] } }, "integration_manifest": { "domain": "zha", "name": "Zigbee Home Automation", "after_dependencies": [ "onboarding", "usb" ], "codeowners": [ "@dmulcahey", "@adminiuga", "@puddly" ], "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" ], "requirements": [ "bellows==0.35.1", "pyserial==3.5", "pyserial-asyncio==0.6", "zha-quirks==0.0.97", "zigpy-deconz==0.20.0", "zigpy==0.54.1", "zigpy-xbee==0.17.0", "zigpy-zigate==0.10.3", "zigpy-znp==0.10.0" ], "usb": [ { "vid": "10C4", "pid": "EA60", "description": "*2652*", "known_devices": [ "slae.sh cc2652rb stick" ] }, { "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": "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": "_slzb-06._tcp.local.", "name": "slzb-06*" } ], "is_built_in": true }, "data": { "ieee": "**REDACTED**", "nwk": 9470, "manufacturer": "_TZ3000_9ni6xxld", "model": "TS011F", "name": "_TZ3000_9ni6xxld TS011F", "quirk_applied": false, "quirk_class": "zigpy.device.Device", "manufacturer_code": 4098, "power_source": "Mains", "lqi": 108, "rssi": -73, "last_seen": "2023-04-28T10:56:19", "available": true, "device_type": "Router", "signature": { "node_descriptor": "NodeDescriptor(logical_type=, complex_descriptor_available=0, user_descriptor_available=0, reserved=0, aps_flags=0, frequency_band=, mac_capability_flags=, manufacturer_code=4098, maximum_buffer_size=82, maximum_incoming_transfer_size=82, server_mask=11264, maximum_outgoing_transfer_size=82, descriptor_capability_field=, *allocate_address=True, *is_alternate_pan_coordinator=False, *is_coordinator=False, *is_end_device=False, *is_full_function_device=True, *is_mains_powered=True, *is_receiver_on_when_idle=True, *is_router=True, *is_security_capable=False)", "endpoints": { "1": { "profile_id": 260, "device_type": "0x010a", "in_clusters": [ "0x0000", "0x0003", "0x0004", "0x0005", "0x0006", "0x0402", "0x0702", "0x0b04", "0xe000", "0xe001" ], "out_clusters": [ "0x000a", "0x0019" ] }, "242": { "profile_id": 41440, "device_type": "0x0061", "in_clusters": [], "out_clusters": [ "0x0021" ] } } }, "active_coordinator": false, "entities": [ { "entity_id": "sensor.pmtr_ac_avant_active_power_2", "name": "_TZ3000_9ni6xxld TS011F" }, { "entity_id": "sensor.pmtr_ac_avant_rms_current_2", "name": "_TZ3000_9ni6xxld TS011F" }, { "entity_id": "sensor.pmtr_ac_avant_rms_voltage_2", "name": "_TZ3000_9ni6xxld TS011F" }, { "entity_id": "sensor.pmtr_ac_avant_power_factor_2", "name": "_TZ3000_9ni6xxld TS011F" }, { "entity_id": "sensor.pmtr_ac_avant_temperature_2", "name": "_TZ3000_9ni6xxld TS011F" }, { "entity_id": "sensor.pmtr_ac_avant_summation_delivered_2", "name": "_TZ3000_9ni6xxld TS011F" }, { "entity_id": "switch.pmtr_ac_avant_switch_2", "name": "_TZ3000_9ni6xxld TS011F" }, { "entity_id": "button.pmtr_ac_avant_identify_2", "name": "_TZ3000_9ni6xxld TS011F" } ], "neighbors": [ { "device_type": "Coordinator", "rx_on_when_idle": "On", "relationship": "Sibling", "extended_pan_id": "**REDACTED**", "ieee": "**REDACTED**", "nwk": "0x0000", "permit_joining": "Unknown", "depth": "0", "lqi": "129" }, { "device_type": "Router", "rx_on_when_idle": "On", "relationship": "Sibling", "extended_pan_id": "**REDACTED**", "ieee": "**REDACTED**", "nwk": "0x197D", "permit_joining": "Unknown", "depth": "15", "lqi": "37" }, { "device_type": "Router", "rx_on_when_idle": "On", "relationship": "Sibling", "extended_pan_id": "**REDACTED**", "ieee": "**REDACTED**", "nwk": "0x9E67", "permit_joining": "Unknown", "depth": "15", "lqi": "191" }, { "device_type": "Router", "rx_on_when_idle": "On", "relationship": "Parent", "extended_pan_id": "**REDACTED**", "ieee": "**REDACTED**", "nwk": "0xC3F6", "permit_joining": "Unknown", "depth": "15", "lqi": "255" } ], "routes": [ { "dest_nwk": "0x0000", "route_status": "Active", "memory_constrained": false, "many_to_one": true, "route_record_required": false, "next_hop": "0x0000" }, { "dest_nwk": "0xC3F6", "route_status": "Active", "memory_constrained": false, "many_to_one": false, "route_record_required": false, "next_hop": "0xC3F6" }, { "dest_nwk": "0x9E67", "route_status": "Active", "memory_constrained": false, "many_to_one": false, "route_record_required": false, "next_hop": "0x9E67" }, { "dest_nwk": "0xA987", "route_status": "Active", "memory_constrained": false, "many_to_one": false, "route_record_required": false, "next_hop": "0xA987" } ], "endpoint_names": [ { "name": "ON_OFF_PLUG_IN_UNIT" }, { "name": "unknown 97 device_type of 0xa1e0 profile id" } ], "user_given_name": "PMtr_AC_Avant", "device_reg_id": "86228a46849f5f4c703ec778c6a1950a", "area_id": "zone_avant", "cluster_details": { "1": { "device_type": { "name": "ON_OFF_PLUG_IN_UNIT", "id": 266 }, "profile_id": 260, "in_clusters": { "0x0000": { "endpoint_attribute": "basic", "attributes": { "0x0004": { "attribute_name": "manufacturer", "value": "_TZ3000_9ni6xxld" }, "0x0005": { "attribute_name": "model", "value": "TS011F" } }, "unsupported_attributes": {} }, "0x0003": { "endpoint_attribute": "identify", "attributes": {}, "unsupported_attributes": {} }, "0x0004": { "endpoint_attribute": "groups", "attributes": {}, "unsupported_attributes": {} }, "0x0005": { "endpoint_attribute": "scenes", "attributes": {}, "unsupported_attributes": {} }, "0x0006": { "endpoint_attribute": "on_off", "attributes": { "0x0000": { "attribute_name": "on_off", "value": 0 } }, "unsupported_attributes": {} }, "0x0702": { "endpoint_attribute": "smartenergy_metering", "attributes": { "0x0000": { "attribute_name": "current_summ_delivered", "value": 12 }, "0x0200": { "attribute_name": "status", "value": 0 }, "0x0300": { "attribute_name": "unit_of_measure", "value": 0 }, "0x0303": { "attribute_name": "summation_formatting", "value": 0 }, "0x0306": { "attribute_name": "metering_device_type", "value": 0 } }, "unsupported_attributes": { "0x0400": { "attribute_name": "instantaneous_demand" }, "0x0100": { "attribute_name": "current_tier1_summ_delivered" }, "0x0102": { "attribute_name": "current_tier2_summ_delivered" }, "0x0302": { "attribute_name": "divisor" }, "0x0104": { "attribute_name": "current_tier3_summ_delivered" }, "0x0304": { "attribute_name": "demand_formatting" }, "0x0106": { "attribute_name": "current_tier4_summ_delivered" }, "0x0301": { "attribute_name": "multiplier" }, "0x0108": { "attribute_name": "current_tier5_summ_delivered" }, "0x010a": { "attribute_name": "current_tier6_summ_delivered" }, "0x030c": { "attribute_name": "temperature_unit_of_measure" } } }, "0x0b04": { "endpoint_attribute": "electrical_measurement", "attributes": { "0x0505": { "attribute_name": "rms_voltage", "value": 231 }, "0x0508": { "attribute_name": "rms_current", "value": 0 }, "0x050b": { "attribute_name": "active_power", "value": 0 } }, "unsupported_attributes": { "0x0300": { "attribute_name": "ac_frequency" }, "0x0601": { "attribute_name": "ac_voltage_divisor" }, "0x0302": { "attribute_name": "ac_frequency_max" }, "0x0603": { "attribute_name": "ac_current_divisor" }, "0x0602": { "attribute_name": "ac_current_multiplier" }, "0x0605": { "attribute_name": "ac_power_divisor" }, "0x0604": { "attribute_name": "ac_power_multiplier" }, "0x0507": { "attribute_name": "rms_voltage_max" }, "0x0600": { "attribute_name": "ac_voltage_multiplier" }, "0x0401": { "attribute_name": "ac_frequency_divisor" }, "0x050a": { "attribute_name": "rms_current_max" }, "0x0000": { "attribute_name": "measurement_type" }, "0x050d": { "attribute_name": "active_power_max" }, "0x050f": { "attribute_name": "apparent_power" }, "0x0400": { "attribute_name": "ac_frequency_multiplier" }, "0x0402": { "attribute_name": "power_multiplier" }, "0x0403": { "attribute_name": "power_divisor" }, "0x0803": { "attribute_name": "ac_active_power_overload" } } }, "0x0402": { "endpoint_attribute": "temperature", "attributes": { "0x0000": { "attribute_name": "measured_value", "value": 5733 } }, "unsupported_attributes": {} }, "0xe000": { "endpoint_attribute": null, "attributes": {}, "unsupported_attributes": {} }, "0xe001": { "endpoint_attribute": null, "attributes": {}, "unsupported_attributes": {} } }, "out_clusters": { "0x0019": { "endpoint_attribute": "ota", "attributes": {}, "unsupported_attributes": {} }, "0x000a": { "endpoint_attribute": "time", "attributes": {}, "unsupported_attributes": {} } } }, "242": { "device_type": { "name": "unknown", "id": 97 }, "profile_id": 41440, "in_clusters": {}, "out_clusters": { "0x0021": { "endpoint_attribute": "green_power", "attributes": {}, "unsupported_attributes": {} } } } } } } ```

Logs

None

Custom quirk

None

Additional information

No response

knipknap commented 1 year ago

I have the same meter, and put another meter in series to collect some more info. Here are the values shown on the ATMS1603:

image

And here is the known working meter at the same time:

image

(Don't be confused by the naming, they both measure the same things.)

knipknap commented 1 year ago

And here another snapshot with higher power consumption: ATMS1603:

image

Control:

image

So it looks like the Active Power is actually correct (just the device doesn't have the best precision), the current is off by a factor of 1000, and about the summation I can only guess - probably also factor 1000.

No idea what the temp is showing. I don't think this thing has a temperature sensor.

saintfrater commented 1 year ago

Since you're also in a 230V area, active power should be more twice the display around 210W OR the current (A) is displayed value 2x.

According to the Ohm's law P = U x I 110W ~= 0.9A 120V 210W ~= 0.9A 230V

115W ~= 0.5A * 230V

Event the "working" right is somehow "displaying craps" :D

To determine which value (current or power) is accurate, can you check the specification of the load to define which fit better the measurement (current (A) or power (W)) ?

knipknap commented 1 year ago

Oh, I missed that, true. So looks like my control is actually also wrong. That is a tz3000_w0qqde0g... I suspect the factor is off by 2. Since the load is a CNC, I was surprised by how low the power consumption seems to be.

I have a third meter (tz3000_gjnozsaz_ts011f), I'll try that one, too :D.

knipknap commented 1 year ago

Wow, the third one (tz3000_gjnozsaz_ts011f) reports the same values: image

Seems like these have the same firmware with the same issues? I'm now out of options, I don't have any more meters.

MattWestb commented 1 year ago

I think tuya is calculating with 110V and not the real one measured. We need some of this devices in 110V and looks if its OK or calculating it with 55V = 1/2. If its 1/2 its only making one device class in the quirk that is doing the with n = N * 0.5 recalculating but if its not then its little more trickey getting it right for all voltage readings.

PM: Ohms law is R = V / I and the P = U x I is the power law then i was leaned it in the school ;-) https://modwiggler.com/forum/viewtopic.php?t=72133

knipknap commented 1 year ago

See also: https://github.com/Koenkk/zigbee2mqtt/issues/9797#issuecomment-1527625980 (This is the issue where my "control device" was apparently "fixed", but with an error that nobody noticed.)

MattWestb commented 1 year ago

@knipknap The best is you is having one passive load you is knowing like one 75W old light ball then you can calculating the reading and see what is true and not. You can also using active load but then its not so sure its being right like one wackleaner if not running at 100% power.

knipknap commented 1 year ago

Good idea! I had a USB soldering iron + a USB meter, and was able to check my control device: At 50W USB input power, the control device shows this:

Screenshot from 2023-04-28 16-18-53

So that means the Active Power value is correct, and the RMS current is the one that's off.

MattWestb commented 1 year ago

Then is still 2 questions: Is some user having one of this devices and can testing them with 110V so we can see how its working ??

And is it some user here that can implementing it in one new device class in the quirk ?

For the last i thing @javicalle can helping if hi is having time digging in the python spaghetti :-))

saintfrater commented 1 year ago

PM: Ohms law is R = V / I and the P = U x I is the power law then i was leaned it in the school ;-) https://modwiggler.com/forum/viewtopic.php?t=72133

you're right, as so "low level" those two laws are, I use to "store" them in my brain under the same "codename". :D

MattWestb commented 1 year ago

I have doing that 2 but my brain is now in FIFO mode so the old not used things is going out first and soon is start using the LIFO in parallel ;-)))

They is simple but logic and all electric is build on them so very good to knowing doing doing DC calculating and not AC advance with phase and frequencies things.

TheJulianJES commented 1 year ago

If Tuya is calculating the RMS current (wrongly), the entity should just be disabled. I'm pretty sure that just using Ohm's doesn't work in this case, as the power factor likely isn't 1 (so real power and apparent power "differs").

MattWestb commented 1 year ago

I dis agree the power factor is normally very near 1 then having restive load but then its AC its can being very different if the load is not. Devices in those segment cant doing real advanced like measuring one wacumcleanier running at 50% power. If disabling the current you is losing 1/4 of the interesting information from the device. If recalculating it is not 100% true but is not being used in the energy statistic so shall not being any problem. Also the device is very simple made and only having one measuring over one resistor and not one real resistor bridge that is needed for doing good calculating and all other is made by calculating in the device firmware. Also i think is not likely tuya have implanting correction for the power factor and advance power calculating in this devices so better doing one not so bad fix then disabling one or the core functions in the device.

saintfrater commented 1 year ago

in Z2M, with a modified TS011F DIN smart plug with monitoring , the value are correct.

I do believe that the magic line are :

endpoint.saveClusterAttributeKeyValue('haElectricalMeasurement', {acCurrentDivisor: 1000, acCurrentMultiplier: 1});
endpoint.saveClusterAttributeKeyValue('seMetering', {divisor: 100, multiplier: 1});

Find bellow my modified Z2M import.

const exposes = require('zigbee-herdsman-converters/lib/exposes');
const fz = {...require('zigbee-herdsman-converters/converters/fromZigbee'), legacy: require('zigbee-herdsman-converters/lib/legacy').fromZigbee};
const tz = require('zigbee-herdsman-converters/converters/toZigbee');
const ota = require('zigbee-herdsman-converters/lib/ota');
const tuya = require('zigbee-herdsman-converters/lib/tuya');
const reporting = require('zigbee-herdsman-converters/lib/reporting');
const extend = require('zigbee-herdsman-converters/lib/extend');
const e = exposes.presets;
const ea = exposes.access;
const libColor = require('zigbee-herdsman-converters/lib/color');
const utils = require('zigbee-herdsman-converters/lib/utils');
const globalStore = require('zigbee-herdsman-converters/lib/store');
const {ColorMode, colorModeLookup} = require('zigbee-herdsman-converters/lib/constants');
const definition = {
    // Since a lot of TuYa devices use the same modelID, but use different datapoints
    // it's necessary to provide a fingerprint instead of a zigbeeModel
    fingerprint: [
        {
            // The model ID from: Device with modelID 'TS011F' is not supported
            // You may need to add \u0000 at the end of the name in some cases
            modelID: 'TS011F',
            // The manufacturer name from: Device with modelID 'TS011F' is not supported.
            manufacturerName: '_TZ3000_9ni6xxld',
        },
    ],
    model: 'TS011F_din_smart_monitor',
    vendor: 'TuYa',
    description: 'ATMS1603 DIN Smart monitor',
    fromZigbee: [ fz.electrical_measurement, fz.metering, fz.ignore_basic_report, tuya.fz.power_outage_memory],
    toZigbee: [tuya.tz.power_on_behavior_1],
    whiteLabel: [{vendor: 'EARU Electric', model: 'ATSM1603Z'}],
    ota: ota.zigbeeOTA,
    configure: async (device, coordinatorEndpoint, logger) => {
            const endpoint = device.getEndpoint(1);
            await reporting.bind(endpoint, coordinatorEndpoint, ['haElectricalMeasurement', 'seMetering']);
            await reporting.rmsVoltage(endpoint, {change: 5});
            await reporting.rmsCurrent(endpoint, {change: 50});
            await reporting.activePower(endpoint, {change: 10});
            await reporting.currentSummDelivered(endpoint);
            endpoint.saveClusterAttributeKeyValue('haElectricalMeasurement', {acCurrentDivisor: 1000, acCurrentMultiplier: 1});
            endpoint.saveClusterAttributeKeyValue('seMetering', {divisor: 100, multiplier: 1});
            device.save();
    },
    exposes: [e.power(), e.current(), e.voltage(), e.energy()],
};

module.exports = definition;
saintfrater commented 1 year ago

I've made some evolution with a "custom quirks", find below my current customization:

"""TS011F DIN."""
from zigpy.profiles import zha
from zigpy.quirks import CustomDevice
from zigpy.zcl.clusters.general import (
    Basic,
    GreenPowerProxy,
    Groups,
    Identify,
    OnOff,
    Ota,
    Scenes,
    Time,
)
from zigpy.zcl.clusters.homeautomation import ElectricalMeasurement
from zigpy.zcl.clusters.measurement import TemperatureMeasurement
from zigpy.zcl.clusters.smartenergy import Metering

from zhaquirks.const import (
    DEVICE_TYPE,
    ENDPOINTS,
    INPUT_CLUSTERS,
    MODEL,
    MODELS_INFO,
    OUTPUT_CLUSTERS,
    PROFILE_ID,
)
from zhaquirks.tuya import (
    TuyaNewManufCluster,
    TuyaZBE000Cluster,
    TuyaZBElectricalMeasurement,
    TuyaZBExternalSwitchTypeCluster,
    TuyaZBMeteringCluster,
    TuyaZBMeteringClusterWithUnit,
    TuyaZBOnOffAttributeCluster,
)
from zhaquirks.tuya.mcu import EnchantedDevice

class Plug_CM(EnchantedDevice):
    """Circuit monitoring, e.g.  EARU Electric ATSM1603GZ. First one using this definition was _TZ3000_9ni6xxld."""
    signature = {
        MODEL: "TS011F",
        MODELS_INFO: [("_TZ3000_9ni6xxld", "TS011F")],
        ENDPOINTS: {
            # <SimpleDescriptor endpoint=1 profile=260 device_type=266
            # device_version=1
            # input_clusters=[0, 3, 4, 5, 6, 1026, 1794, 2820, 57344, 57345]
            # output_clusters=[10, 25]>
            1: {
                PROFILE_ID: zha.PROFILE_ID,
                DEVICE_TYPE: zha.DeviceType.ON_OFF_PLUG_IN_UNIT,
                INPUT_CLUSTERS: [
                    Basic.cluster_id,
                    Identify.cluster_id,
                    Groups.cluster_id,
                    Scenes.cluster_id,
                    OnOff.cluster_id,
                    TemperatureMeasurement.cluster_id,  # Note: no temperature sensor claimed in manual and it's constant -6.3C
                    Metering.cluster_id,
                    ElectricalMeasurement.cluster_id,
                    TuyaZBE000Cluster.cluster_id,
                    TuyaZBExternalSwitchTypeCluster.cluster_id,
                ],
                OUTPUT_CLUSTERS: [Time.cluster_id, Ota.cluster_id],
            },
            # <SimpleDescriptor endpoint=242 profile=41440 device_type=97
            # device_version=1
            # input_clusters=[]
            # output_clusters=[33]>
            242: {
                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.METER_INTERFACE,
                INPUT_CLUSTERS: [
                    Basic.cluster_id,
                    Identify.cluster_id,
                    Groups.cluster_id,
                    Scenes.cluster_id,
                    # TuyaZBOnOffAttributeCluster,
                    TuyaZBMeteringCluster,
                    TuyaZBElectricalMeasurement,
                    TuyaZBE000Cluster,
                    # TuyaZBExternalSwitchTypeCluster,
                ],
                OUTPUT_CLUSTERS: [Time.cluster_id, Ota.cluster_id],
            },
            242: {
                PROFILE_ID: 41440,
                DEVICE_TYPE: 97,
                INPUT_CLUSTERS: [],
                OUTPUT_CLUSTERS: [GreenPowerProxy.cluster_id],
            },
        },
    }
knipknap commented 1 year ago

Cool, I tested with this quirk installed and it seems to improve the situation:

image

So the total power consumption looks "more plausible". The amperage may still be wrong though, by a factor of two as it seems.

Note that I only installed your Python quirk and not what you commented earlier - frankly not sure what to do with that part.

knipknap commented 1 year ago

I repeated the same with higher power consumption:

image

I would arrive at the same conclusion, the amperage is off by a factor of 2.

saintfrater commented 1 year ago

I've seen the abnormal current... I'm wonder if the Circuit breaker (which is the base of the custom quirks) has the same "issue" with the current...

BTW, you can "delete" the temperature by clicking on the "indisponievel" line then in the "settings" (wheel on right top corner) and click on "Delete" :D

cydia2020 commented 10 months ago

I took one apart today, and it seems like there are two places on the board to put NTC thermistors. However, the manufacturer has neglected to do so. Instead, they replaced one with a normal resistor and left another one unpopulated.

The measurement chip in question is a BL0942, and the product uses the Tuya ZSU Zigbee chip. 20230914_130404 20230914_130820

MattWestb commented 10 months ago

The Zigbee module is one of the good ones = Sirlabs and not the new Telink ones. I was looking for data chests for one reference design of the BL0942 but was not finding it so i cant saying if its needed NTC for getting good data readings or is tuya correcting it in the SOC that is also possible to do if have doing good calibrating and one design that is stable.

PS: tuya MCU is normal one STM32 that is doing its thing and using one RF module (WiFi,BLE or Zigbee) for tunneling the data its suing and its not the Zigbee module in this case then its doing all the data handling and Zigbee things.

cydia2020 commented 10 months ago

Back of PCB: 20230914_130413 Ref design: https://www.belling.com.cn/media/file_object/bel_product_en/BL0942/guide/BL0942%20App%20Note_V1.0.pdf

On this particular board, voltage measurement happens directly without a PT, voltage divider resistors are 390K x5 and 0.51K x1, just like the reference design.

As for the CT, everything else is similar to the reference design besides the loading resistor for the CT, which is 0.5Ω.

BTW the CT included with my particular unit has a ratio of 1000:1

MattWestb commented 10 months ago

I was translating it with google translate online service and can reading the text so understanding more. The good is no NTC is in the reference design so all shall working OK (perhaps needed if having high power and much heating in the box but not for normal use). The load resistor is easy only calculating the reading and i think way tuya have doing that is having the same components for 220 V and other with lover voltages and using the same components for all.

PS if you need one coordinator you can using the Zigbee module only compiling one NCP firmware for it and its working great also with RCP firmware (I have doing it with LIDL LED stripe controller).

github-actions[bot] commented 4 months ago

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates. Please make sure to update to the latest version and check if that solves the issue. Let us know if that works for you by adding a comment 👍 This issue has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.

liouma commented 3 months ago

I've made some evolution with a "custom quirks", find below my current customization:

@saintfrater Thanks for this custom quirck. Is this version your last one ? Are you satisfied with the result ?? THanks a lot

saintfrater commented 3 months ago

I've made some evolution with a "custom quirks", find below my current customization:

@saintfrater Thanks for this custom quirck. Is this version your last one ? Are you satisfied with the result ?? THanks a lot

The last one yes Am I satisfied, not entirely (due to the 2x factor value) but I've no time to deep dive and found the root issue...

liouma commented 3 months ago

The last one yes Am I satisfied, not entirely (due to the 2x factor value) but I've no time to deep dive and found the root issue...

I just did some testing, comparing the value measured using your custom quirk with the value of an external AC clamp meter (simple tool, not connected). The value I get for current (A) is correct: 9.4A vs 9.8A The Tension seem coherent (235V) P=UI -> Power = 2176W is ok All those values seem correct (I did not verify Summation delivered).

-> Where is the 2x factor you are talking about? Is it in the summation delivered?