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
683 stars 636 forks source link

[BUG] INNR SP 240 "summation delivered" kWh value is 100x expected value #2781

Open rrozema opened 7 months ago

rrozema commented 7 months ago

Bug description

Upon inclusion of the INNR SP 240 in ZHA, among others a "Summation delivered" sensor gets created. The value returned for this sensor is however 100x larger than expected: I ran a filament dryer for 5 hours of the SP 240 and the device measured 17kWh instead of the expected 0,17 kWh as measured using a Fibaro wall plug V2.

When I requested help from INNR support they responded that ZHA probably has incorrectly interpreted the configuration their device returned. My translation of their response: "An attribute "SummationFormatting" on the Metering cluster has the value 0x2A, which designates: 2 digits to the right of the decimal point, 5 digits to the left of the decimal point, don't suppress leading zeroes". Looks like his system (red: my ZHA integration in HA)) doesn't interpret or incorrectly interprets the value of the "SummationFormatting" attribute."

The full mail text I got from INNR support (in Dutch, sorry):

Beste Richard,

(This message is in Dutch because I assume based on your name and e-mail address that you also speak Dutch.)

Ik heb de vraag even bij één van onze engineers gelegd, en dit was zijn reactie:

Wat betreft Watt meting die op 0 decimalen wordt afgerond:

De waarde wordt opgeslagen en gecommuniceerd in een “int16” type, wat een bereik heeft van -32768 tot 32767. Als we op 1 decimaal zouden afronden zou het maximum slechts 3276.7 W zijn, maar de plug kan 3680 W aan dus de keuze was simpel. De afronding dynamisch maken (meer decimalen bij lagere waarden) is geen optie want dat ondersteunen de meeste systemen niet (voor zover ik weet geen enkel systeem).

Wat betreft de kWh formatting: het “SummationFormatting” attribuut van het Metering cluster heeft waarde 0x2A, wat betekent: 2 digits to the right of the decimal point, 5 digits to the left of the decimal point, don’t suppress leading zeroes. Lijkt er dus op dat zijn systeem de waarde van het “SummationFormatting” attribuut van het Metering cluster niet of verkeerd interpreteert.

Hopelijk heb je iets aan deze uitleg.

Met vriendelijke groet,

REDACTED

Innr Servicedesk Innr Lighting | Innr.com 

Innr Lighting BV  |  Catharina van Renneslaan 20  |  1217 CX Hilversum

@TheJulianJES requested me to tag him in here.

Steps to reproduce

Include the INNR SP 240 into the network using ZHA, plug in a filament dryer of 145W, Run the dryer for 5 hours, Watt history graph shows a peak at the beginning, then dropping to roughly 30 Watt. Multiply the measured Watt value with the number of hours: 5 * roughly 30 Watt = roughly 170 Wh, or 0,17 kWh. See how the actual sensor in ZHA however shows 17kWh.

Expected behavior

The summation delivered sensor should have shown a usage of 0,170 kWh

Screenshots/Video

Screenshots/Video ![image](https://github.com/zigpy/zha-device-handlers/assets/1747982/bdca1488-df6e-4c55-91be-b64dbf4e8422) ![image](https://github.com/zigpy/zha-device-handlers/assets/1747982/93985e4a-2c74-4af4-825a-562a472833da) ![image](https://github.com/zigpy/zha-device-handlers/assets/1747982/02eda6be-7639-49e8-9c98-b55792fab7ef)

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=4454, maximum_buffer_size=66, maximum_incoming_transfer_size=66, server_mask=10752, maximum_outgoing_transfer_size=66, 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": "0x0104", "device_type": "0x010a", "input_clusters": [ "0x0000", "0x0003", "0x0004", "0x0005", "0x0006", "0x0008", "0x0702", "0x0b04", "0x1000", "0xe001" ], "output_clusters": [ "0x000a", "0x0019" ] }, "242": { "profile_id": "0xa1e0", "device_type": "0x0061", "input_clusters": [], "output_clusters": [ "0x0021" ] } }, "manufacturer": "innr", "model": "SP 240", "class": "zigpy.device.Device" } ```

Diagnostic information

Diagnostic information ```json { "home_assistant": { "installation_type": "Home Assistant OS", "version": "2023.11.3", "dev": false, "hassio": true, "virtualenv": false, "python_version": "3.11.6", "docker": true, "arch": "x86_64", "timezone": "Europe/Amsterdam", "os_name": "Linux", "os_version": "6.1.59", "supervisor": "2023.11.3", "host_os": "Home Assistant OS 11.1", "docker_version": "24.0.6", "chassis": "embedded", "run_as_root": true }, "custom_components": { "battery_consumption": { "version": "1.0.4", "requirements": [] }, "spook": { "version": "1.3.2", "requirements": [] }, "chime_tts": { "version": "v0.8.0", "requirements": [ "pydub" ] }, "battery_sim": { "version": "1.0", "requirements": [] }, "google_fit": { "version": "v2.1.2", "requirements": [ "oauth2client==4.1.3", "google-api-python-client==2.82.0" ] }, "hacs": { "version": "1.33.0", "requirements": [ "aiogithubapi>=22.10.1" ] }, "energy_meter": { "version": "1.0.1", "requirements": [] }, "adaptive_lighting": { "version": "1.19.0", "requirements": [ "ulid-transform" ] }, "smart_irrigation": { "version": "0.0.81", "requirements": [] }, "hass_agent": { "version": "2022.11.9", "requirements": [] }, "var": { "version": "0.15.0", "requirements": [] }, "presence_simulation": { "version": "3.2", "requirements": [] }, "grad_vol": { "version": "1.0.0", "requirements": [] }, "better_thermostat": { "version": "1.4.0", "requirements": [] }, "xiaomi_cloud_map_extractor": { "version": "v2.2.0", "requirements": [ "pillow", "pybase64", "python-miio", "requests", "pycryptodome" ] }, "powercalc": { "version": "v1.9.7", "requirements": [ "numpy>=1.21.1" ] }, "spook_inverse": { "version": "1.3.2", "requirements": [] } }, "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", "universal_silabs_flasher" ], "requirements": [ "bellows==0.36.8", "pyserial==3.5", "pyserial-asyncio==0.6", "zha-quirks==0.0.106", "zigpy-deconz==0.21.1", "zigpy==0.59.0", "zigpy-xbee==0.19.0", "zigpy-zigate==0.11.0", "zigpy-znp==0.11.6", "universal-silabs-flasher==0.0.14", "pyserial-asyncio-fast==0.11" ], "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": "_uzg-01._tcp.local.", "name": "uzg-01*" }, { "type": "_slzb-06._tcp.local.", "name": "slzb-06*" } ], "is_built_in": true }, "data": { "ieee": "**REDACTED**", "nwk": 12957, "manufacturer": "innr", "model": "SP 240", "name": "innr SP 240", "quirk_applied": false, "quirk_class": "zigpy.device.Device", "quirk_id": null, "manufacturer_code": 4454, "power_source": "Mains", "lqi": 123, "rssi": null, "last_seen": "2023-11-26T21:32:06", "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=4454, maximum_buffer_size=66, maximum_incoming_transfer_size=66, server_mask=10752, maximum_outgoing_transfer_size=66, 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": "0x0104", "device_type": "0x010a", "input_clusters": [ "0x0000", "0x0003", "0x0004", "0x0005", "0x0006", "0x0008", "0x0702", "0x0b04", "0x1000", "0xe001" ], "output_clusters": [ "0x000a", "0x0019" ] }, "242": { "profile_id": "0xa1e0", "device_type": "0x0061", "input_clusters": [], "output_clusters": [ "0x0021" ] } }, "manufacturer": "innr", "model": "SP 240" }, "active_coordinator": false, "entities": [ { "entity_id": "button.woonkamer_innr_sp240_identify", "name": "innr SP 240" }, { "entity_id": "select.woonkamer_innr_sp240_start_up_behavior", "name": "innr SP 240" }, { "entity_id": "sensor.woonkamer_innr_sp240_current", "name": "innr SP 240" }, { "entity_id": "sensor.woonkamer_innr_sp240_voltage", "name": "innr SP 240" }, { "entity_id": "sensor.woonkamer_innr_sp240_electric_consumption_w", "name": "innr SP 240" }, { "entity_id": "sensor.woonkamer_innr_sp240_electric_consumption_kwh", "name": "innr SP 240" }, { "entity_id": "switch.woonkamer_kerstverlichting_3", "name": "innr SP 240" } ], "neighbors": [ { "device_type": "Coordinator", "rx_on_when_idle": "On", "relationship": "Parent", "extended_pan_id": "**REDACTED**", "ieee": "**REDACTED**", "nwk": "0x0000", "permit_joining": "Unknown", "depth": "0", "lqi": "48" }, { "device_type": "Router", "rx_on_when_idle": "On", "relationship": "Sibling", "extended_pan_id": "**REDACTED**", "ieee": "**REDACTED**", "nwk": "0xA795", "permit_joining": "Unknown", "depth": "0", "lqi": "62" }, { "device_type": "Router", "rx_on_when_idle": "On", "relationship": "Sibling", "extended_pan_id": "**REDACTED**", "ieee": "**REDACTED**", "nwk": "0xF80E", "permit_joining": "Unknown", "depth": "0", "lqi": "223" }, { "device_type": "Router", "rx_on_when_idle": "On", "relationship": "Sibling", "extended_pan_id": "**REDACTED**", "ieee": "**REDACTED**", "nwk": "0x0316", "permit_joining": "Unknown", "depth": "0", "lqi": "88" }, { "device_type": "Router", "rx_on_when_idle": "On", "relationship": "Sibling", "extended_pan_id": "**REDACTED**", "ieee": "**REDACTED**", "nwk": "0xFF73", "permit_joining": "Unknown", "depth": "0", "lqi": "80" }, { "device_type": "Router", "rx_on_when_idle": "On", "relationship": "Sibling", "extended_pan_id": "**REDACTED**", "ieee": "**REDACTED**", "nwk": "0x2415", "permit_joining": "Unknown", "depth": "0", "lqi": "45" }, { "device_type": "Router", "rx_on_when_idle": "On", "relationship": "Sibling", "extended_pan_id": "**REDACTED**", "ieee": "**REDACTED**", "nwk": "0xA16F", "permit_joining": "Unknown", "depth": "0", "lqi": "0" }, { "device_type": "Router", "rx_on_when_idle": "On", "relationship": "Sibling", "extended_pan_id": "**REDACTED**", "ieee": "**REDACTED**", "nwk": "0x6D36", "permit_joining": "Unknown", "depth": "0", "lqi": "53" }, { "device_type": "Router", "rx_on_when_idle": "On", "relationship": "Sibling", "extended_pan_id": "**REDACTED**", "ieee": "**REDACTED**", "nwk": "0xF373", "permit_joining": "Unknown", "depth": "0", "lqi": "103" }, { "device_type": "Router", "rx_on_when_idle": "On", "relationship": "Sibling", "extended_pan_id": "**REDACTED**", "ieee": "**REDACTED**", "nwk": "0xF608", "permit_joining": "Unknown", "depth": "0", "lqi": "47" }, { "device_type": "Router", "rx_on_when_idle": "On", "relationship": "Sibling", "extended_pan_id": "**REDACTED**", "ieee": "**REDACTED**", "nwk": "0xC07F", "permit_joining": "Unknown", "depth": "0", "lqi": "118" }, { "device_type": "Router", "rx_on_when_idle": "On", "relationship": "Sibling", "extended_pan_id": "**REDACTED**", "ieee": "**REDACTED**", "nwk": "0xB58E", "permit_joining": "Unknown", "depth": "0", "lqi": "16" }, { "device_type": "Router", "rx_on_when_idle": "On", "relationship": "Sibling", "extended_pan_id": "**REDACTED**", "ieee": "**REDACTED**", "nwk": "0x3242", "permit_joining": "Unknown", "depth": "0", "lqi": "66" }, { "device_type": "Router", "rx_on_when_idle": "On", "relationship": "Sibling", "extended_pan_id": "**REDACTED**", "ieee": "**REDACTED**", "nwk": "0xA1BB", "permit_joining": "Unknown", "depth": "0", "lqi": "29" }, { "device_type": "Router", "rx_on_when_idle": "On", "relationship": "Sibling", "extended_pan_id": "**REDACTED**", "ieee": "**REDACTED**", "nwk": "0x8A77", "permit_joining": "Unknown", "depth": "0", "lqi": "15" } ], "routes": [], "endpoint_names": [ { "name": "ON_OFF_PLUG_IN_UNIT" }, { "name": "PROXY_BASIC" } ], "user_given_name": "Woonkamer: innr sp240", "device_reg_id": "7fa8dcff82a4c9d75905608870c6f7ef", "area_id": "woonkamer", "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": "innr" }, "0x0005": { "attribute_name": "model", "value": "SP 240" } }, "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": 1 }, "0x4003": { "attribute_name": "start_up_on_off", "value": 255 } }, "unsupported_attributes": {} }, "0x0008": { "endpoint_attribute": "level", "attributes": { "0x0000": { "attribute_name": "current_level", "value": 1 } }, "unsupported_attributes": { "0x4000": { "attribute_name": "start_up_current_level" }, "0x0012": { "attribute_name": "on_transition_time" }, "0x0010": { "attribute_name": "on_off_transition_time" }, "0x0011": { "attribute_name": "on_level" }, "0x0013": { "attribute_name": "off_transition_time" }, "0x0014": { "attribute_name": "default_move_rate" } } }, "0x1000": { "endpoint_attribute": "lightlink", "attributes": {}, "unsupported_attributes": {} }, "0x0702": { "endpoint_attribute": "smartenergy_metering", "attributes": { "0x0000": { "attribute_name": "current_summ_delivered", "value": 17 }, "0x0306": { "attribute_name": "metering_device_type", "value": 0 }, "0x0200": { "attribute_name": "status", "value": 0 }, "0x0303": { "attribute_name": "summation_formatting", "value": 42 }, "0x0300": { "attribute_name": "unit_of_measure", "value": 0 } }, "unsupported_attributes": { "0x0400": { "attribute_name": "instantaneous_demand" }, "0x0100": { "attribute_name": "current_tier1_summ_delivered" }, "0x0302": { "attribute_name": "divisor" }, "0x0301": { "attribute_name": "multiplier" }, "0x0304": { "attribute_name": "demand_formatting" }, "0x0102": { "attribute_name": "current_tier2_summ_delivered" }, "0x0104": { "attribute_name": "current_tier3_summ_delivered" }, "0x0106": { "attribute_name": "current_tier4_summ_delivered" }, "0x0108": { "attribute_name": "current_tier5_summ_delivered" }, "0x010a": { "attribute_name": "current_tier6_summ_delivered" } } }, "0x0b04": { "endpoint_attribute": "electrical_measurement", "attributes": { "0x0603": { "attribute_name": "ac_current_divisor", "value": 1000 }, "0x0602": { "attribute_name": "ac_current_multiplier", "value": 1 }, "0x0605": { "attribute_name": "ac_power_divisor", "value": 1 }, "0x0604": { "attribute_name": "ac_power_multiplier", "value": 1 }, "0x0601": { "attribute_name": "ac_voltage_divisor", "value": 1 }, "0x0600": { "attribute_name": "ac_voltage_multiplier", "value": 1 }, "0x050b": { "attribute_name": "active_power", "value": 2 }, "0x0000": { "attribute_name": "measurement_type", "value": 3221762439 }, "0x0508": { "attribute_name": "rms_current", "value": 14 }, "0x0505": { "attribute_name": "rms_voltage", "value": 236 } }, "unsupported_attributes": { "0x0300": { "attribute_name": "ac_frequency" }, "0x0401": { "attribute_name": "ac_frequency_divisor" }, "0x0302": { "attribute_name": "ac_frequency_max" }, "0x0400": { "attribute_name": "ac_frequency_multiplier" }, "0x0403": { "attribute_name": "power_divisor" }, "0x0402": { "attribute_name": "power_multiplier" }, "0x0507": { "attribute_name": "rms_voltage_max" }, "0x050a": { "attribute_name": "rms_current_max" }, "0x050d": { "attribute_name": "active_power_max" }, "0x050f": { "attribute_name": "apparent_power" }, "0x0510": { "attribute_name": "power_factor" } } }, "0xe001": { "endpoint_attribute": null, "attributes": {}, "unsupported_attributes": {} } }, "out_clusters": { "0x000a": { "endpoint_attribute": "time", "attributes": {}, "unsupported_attributes": {} }, "0x0019": { "endpoint_attribute": "ota", "attributes": {}, "unsupported_attributes": {} } } }, "242": { "device_type": { "name": "PROXY_BASIC", "id": 97 }, "profile_id": 41440, "in_clusters": {}, "out_clusters": { "0x0021": { "endpoint_attribute": "green_power", "attributes": {}, "unsupported_attributes": {} } } } } } } ```

Logs

Logs ```python [Paste the logs here] ```

Additional information

No response

TheJulianJES commented 7 months ago

This might really be a ZHA issue. If the measurement type is kWh (0), we do not use the summation_formatting attribute for some reason. We only use the multiplier and divider attributes in that case: zha/sensor.py#L522-L531

@Adminiuga If you're around, do you have any idea why you added that check in the original PR? I'm guessing that it's unexpected the formatter is still needed for kWh? Or did some devices perhaps provide something wrong?


This can be worked around with a quirk. I'm not sure if that's a good idea though, as the plug seems to provide summation_formatting correctly: 00101010 => 2 digits to right of decimal point, 5 digits to left of decimal point. Changing the ZHA code could break some other devices though. Especially the ones we have quirks for which set the multiplier / dividers right now.

.. but apparently we already use quirks for other Innr plugs though: https://github.com/zigpy/zha-device-handlers/blob/dev/zhaquirks/innr/innr_sp120_plug.py I guess I'll get one ready for this plug too for now.

TheJulianJES commented 7 months ago

@rrozema Please test this file as a custom quirk. The comment above is still relevant for the isuse though.

tube0013 commented 7 months ago

I think the US version of this plug the 234 may have the same issue. I have my LumenPNP on one and it's like a 3d printer without heaters and some small vacuum pumps when running. I don't think it's put out 50 kWh during it's lifetime.

image

Looks like the current quirk is just changing the voltage divisor: https://github.com/zigpy/zha-device-handlers/blob/d30dac2f3ffe99cc303690afb91513cb8836acc4/zhaquirks/innr/innr_sp234_plug.py#L34 I

If I query the Summation_Formatting attribute I get 4 (0x2A) as well.

I can try and add the fix you added for the 240 in the quirk for the 234 to see if the work around works as well.

{
  "node_descriptor": "NodeDescriptor(logical_type=<LogicalType.Router: 1>, complex_descriptor_available=0, user_descriptor_available=0, reserved=0, aps_flags=0, frequency_band=<FrequencyBand.Freq2400MHz: 8>, mac_capability_flags=<MACCapabilityFlags.FullFunctionDevice|MainsPowered|RxOnWhenIdle|AllocateAddress: 142>, manufacturer_code=4454, maximum_buffer_size=82, maximum_incoming_transfer_size=82, server_mask=11264, maximum_outgoing_transfer_size=82, descriptor_capability_field=<DescriptorCapability.NONE: 0>, *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": "0x0104",
      "device_type": "0x010a",
      "input_clusters": [
        "0x0000",
        "0x0003",
        "0x0004",
        "0x0005",
        "0x0006",
        "0x0702",
        "0x0b04",
        "0x0b05",
        "0x1000",
        "0xfc57",
        "0xfc82"
      ],
      "output_clusters": [
        "0x0003",
        "0x000a",
        "0x0019"
      ]
    },
    "242": {
      "profile_id": "0xa1e0",
      "device_type": "0x0061",
      "input_clusters": [],
      "output_clusters": [
        "0x0021"
      ]
    }
  },
  "manufacturer": "innr",
  "model": "SP 234",
  "class": "zhaquirks.innr.innr_sp234_plug.SP234"
}
TheJulianJES commented 7 months ago

@tube0013 I've pushed some changes to:

To install the SP234 quirk easily as a custom quirk, use this:

SP234 custom quirk test code (click to exapnd) ```python """Innr SP 234 plug.""" from zigpy.profiles import zgp, zha from zigpy.quirks import CustomCluster, CustomDevice from zigpy.zcl.clusters.general import ( Basic, GreenPowerProxy, Groups, Identify, OnOff, Ota, Scenes, Time, ) from zigpy.zcl.clusters.homeautomation import Diagnostic, ElectricalMeasurement from zigpy.zcl.clusters.lightlink import LightLink from zigpy.zcl.clusters.smartenergy import Metering from zhaquirks.const import ( DEVICE_TYPE, ENDPOINTS, INPUT_CLUSTERS, MODELS_INFO, OUTPUT_CLUSTERS, PROFILE_ID, ) class ElectricalMeasurementCluster(CustomCluster, ElectricalMeasurement): """Fix divisor for AC power.""" _CONSTANT_ATTRIBUTES = {ElectricalMeasurement.AttributeDefs.ac_power_divisor.id: 1} class MeteringClusterInnr(CustomCluster, Metering): """Provide constant multiplier and divisor. The device supplies the summation_formatting attribute correctly, but ZHA doesn't use it for kWh at the moment. """ _CONSTANT_ATTRIBUTES = { Metering.AttributeDefs.multiplier.id: 1, Metering.AttributeDefs.divisor.id: 100, } class SP234(CustomDevice): """Innr SP 234 smart plug.""" signature = { MODELS_INFO: [("innr", "SP 234")], ENDPOINTS: { 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, Metering.cluster_id, ElectricalMeasurement.cluster_id, Diagnostic.cluster_id, LightLink.cluster_id, 0xFC57, 0xFC82, ], OUTPUT_CLUSTERS: [ Identify.cluster_id, Time.cluster_id, Ota.cluster_id, ], }, 242: { PROFILE_ID: zgp.PROFILE_ID, DEVICE_TYPE: zgp.DeviceType.PROXY_BASIC, INPUT_CLUSTERS: [], OUTPUT_CLUSTERS: [GreenPowerProxy.cluster_id], }, }, } replacement = { ENDPOINTS: { 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, MeteringClusterInnr, ElectricalMeasurementCluster, Diagnostic.cluster_id, LightLink.cluster_id, 0xFC57, 0xFC82, ], OUTPUT_CLUSTERS: [ Identify.cluster_id, Time.cluster_id, Ota.cluster_id, ], }, 242: { PROFILE_ID: zgp.PROFILE_ID, DEVICE_TYPE: zgp.DeviceType.PROXY_BASIC, INPUT_CLUSTERS: [], OUTPUT_CLUSTERS: [GreenPowerProxy.cluster_id], }, }, } ```

Let me know if all your plug measurements are correct then.

tube0013 commented 7 months ago

Thanks got it running now.. and reset the summation delivered to get a fresh summation with the updated quirk.

TheJulianJES commented 7 months ago

Z2M also adds it for your plug (code here). They are doing some other things we're not doing too. Can you check if the current also needs to be divided by 1000 for your plug, @tube0013?

Actually, can you upload a diagnostics file for your plug? I'm interested in what ac_current_divisor returns on your plug.

tube0013 commented 7 months ago

Amperage seems okay to me:

IMG_3338

ac_current_divisor is 1000:

zha-e29ceebf7c284fe6a18d61622537f595-innr SP 234-bd4503f7c2ae9e99b0befd345d61ad65.json.txt

rrozema commented 7 months ago

image I confirm the quirk fixes my kWh sensor.

GerryInnr commented 7 months ago

Good to see the issue is resolved. Just for info: the SP 234 US plug had an issue in the first firmware with an incorrect divider that was fixed in a firmware update. That update also fixes a number of other issues and is available on https://github.com/Koenkk/zigbee-OTA/tree/master/images/Innr.

tube0013 commented 7 months ago

SP 234 quirk changes have been working well.

Interesting I missed that fact that innr had fw updates posted. so I guess the quick need to be adjusted for that... I'm pulling it down and will update. @TheJulianJES should we move the SP 234 to a new issue sorry fop combining it with the SP 240!

TheJulianJES commented 7 months ago

Ah, the info with the older firmware versions is interesting. It explains why Z2M still sets those dividers manually.

https://github.com/zigpy/zha-device-handlers/pull/2782 will be included in 2023.12.0b0 and should fix the issue even for older firmware versions of the SP 234, as it always sets the EM current and EM power divisors for the SP 234 now. The total sum delivered (Metering) fix is also included for all Innr plugs (setting divisor, as ZHA ignores summation_formatting at the moment).

So, the behavior should be fixed in all upcoming 2023.12.x versions. If there any remaining issues in 2023.12.x (beta should be out in about one to two hours or so), please open a new issue for other plugs and tag me.

tube0013 commented 7 months ago

My SP 234 was already on latest fw, so everything seems working with the modified one as I have been testing over last day or so.

thecoop commented 4 months ago

This is also an issue for the SP 242

chonkusZZ commented 3 months ago

This is also an issue for the SP 242

I too am having the same issue with SP 242, FW 1.4.3.

I can't seem to even find this device on Innr's website anymore despite only recently purchasing them, but am exhibiting the same issue with the summation being much higher than it should be, assuming it is the same problem.

GerryInnr commented 3 months ago

The new plugs SP 240, SP 242, and SP 244 all use the same firmware code base so the same quirk can be applied. Just for completeness: it is not a bug of the smart plugs; the plugs correctly provide the SummationFormatting attribute 0x0303 with value 0x2A (meaning 2 digits to the right 5 to the left of the decimal point), which is the only mandatory attribute for formatting the CurrentSummationDelivered attribute. The Multiplier and Divisor attributes 0x0301 and 0x0302 are optional.

dmulcahey commented 3 months ago

The new plugs SP 240, SP 242, and SP 244 all use the same firmware code base so the same quirk can be applied. Just for completeness: it is not a bug of the smart plugs; the plugs correctly provide the SummationFormatting attribute 0x0303 with value 0x2A (meaning 2 digits to the right 5 to the left of the decimal point), which is the only mandatory attribute for formatting the CurrentSummationDelivered attribute. The Multiplier and Divisor attributes 0x0301 and 0x0302 are optional.

Hrm we should look at the HA side of this to make sure we are doing things correctly then…

TheJulianJES commented 3 months ago

Hrm we should look at the HA side of this to make sure we are doing things correctly then…

Yeah, I think there's an issue with ZHA at the moment, see this comment: https://github.com/zigpy/zha-device-handlers/issues/2781#issuecomment-1830832448 (formatter isn't used for kWh) Even if we fix ZHA code, we risk breaking multiple devices with existing quirks. Some devices report it correctly and others not, so we don't know which quirks should stay and which should be removed (without knowing the attributes reported by the device).

exalyte commented 2 days ago

Sorry to add to an old bug but it seems the newer innr 242 has the same bug summation is 100x expected

Firmware reported by zha is 0x14033682

Please let me know if this should it's own ticket

EXA

GerryInnr commented 20 hours ago

Sorry to add to an old bug but it seems the newer innr 242 has the same bug summation is 100x expected Firmware reported by zha is 0x14033682 Please let me know if this should it's own ticket EXA

As described before in this thread, this is not a bug of the SP 242, it is a bug of ZHA not using the SummationFormatting attribute of the Metering cluster to determine the right scale of the CurrentSummationDelivered attribute.