Skip to content

Conversation

TheJulianJES
Copy link
Collaborator

@TheJulianJES TheJulianJES commented Oct 13, 2025

Proposed change

This fixes the Metering divisor for the Frient EMI Norwegian HAN to a value of 1000 and ignores all attribute updates for that attribute, as the device apparently sends attribute reports with a value of 512 randomly.

TODO:

  • add tests
  • address TODOs in quirk
  • get device diagnostics
  • get invalid device report data (turn on debug logs for this)

Additional information

See Z2M issue for reference:

Testing

This is an experimental and untested quirk. We need device diagnostics to make sure this fixes the issue.

If you want to test this as a custom quirk, you can do the following:

  1. Install an addon that allows you to modify files in Home Assistant's /config directory.
    The "Samba share" addon or VSCode addon can be used for this.
  2. Create a zha_custom_quirks folder in Home Assistant's /config directory. So, in the folder where HA's configuration.yaml is.
  3. Use the download button on the linked GitHub page to get the custom quirk as a .py file.
  4. Copy the custom quirk file you've just downloaded into the newly created zha_custom_quirks.
  5. Now, add the following to HA's configuration.yaml:
zha:
  custom_quirks_path: /config/zha_custom_quirks

(Make sure you only have one zha: entry in your configuration.yaml. If you modified other ZHA YAML settings, you may need to merge your modifications with the one above.)

  1. Restart Home Assistant.
  2. Check if ZHA still works. if not, check the logs and post any errors.
  3. Check if the custom quirk works as expected.

If you search the web, you should also be able to find some more info on installing custom quirks.

Device diagnostics

We ideally need these before merging:

You can find the diagnostics information by going to the device page, clicking the
three dots, and then by clicking on "Download diagnostics". Drag-and-drop the
downloaded file into this section.

Checklist

  • The changes are tested and work correctly
  • pre-commit checks pass / the code has been formatted using Black
  • Tests have been added to verify that the new code works
  • Device diagnostics data has been attached

Copy link

codecov bot commented Oct 13, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.13%. Comparing base (500e74e) to head (ed49bc4).

Additional details and impacted files
@@           Coverage Diff           @@
##              dev    #4396   +/-   ##
=======================================
  Coverage   92.12%   92.13%           
=======================================
  Files         358      359    +1     
  Lines       11917    11930   +13     
=======================================
+ Hits        10979    10992   +13     
  Misses        938      938           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@uvNikita
Copy link
Contributor

I was just going to submit a PR for this device, but you beat me to it :)

There is a zigbee spec doc for this device which explains issues with divisor attribute: EMI Norwegian HAN - Onics Technical Manual - EMIZB-132.pdf

image

So manufacture specific attibute 0x0302 conflicts with the standard divisor attribute.
The divisor attribute should indeed be fixed to 1000 as you've done in this PR which fixes the power readings for me.

However, ideally, it would be possible to write to this attribute to be able to change meter type using enum type like this:

class InterfaceMode(t.enum16):
    """Interface Mode."""

    NorwegianHAN = 0x0200
    NorwegianHANExtraLoad = 0x0201
    NorwegianHANAidon = 0x0202
    NorwegianHANKaifa = 0x0203
    AutoDetect = 0x0204

I have no idea if this is something zigpy can handle (fixed attribute read with value 1000, but still possible to write).

If not, at least getting fixed divisor would be nice because this would at least fix the power readings.



(
# TODO: check which manufacturer name is used by the device
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just bought this device and can confirm that manufacturer name is "frient A/S", model name is "EMIZB-132", endpoint is 2.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I'll update the PR to only include that for now.

@TheJulianJES
Copy link
Collaborator Author

TheJulianJES commented Oct 14, 2025

@uvNikita Thanks for the comment! Can you provide both a diagnostics file for the device (ideally without the quirk, but shouldn't really matter) and a debug log of the "invalid divisor" attribute report? Would be great to have the actual messages the device sends in the tests.

@uvNikita
Copy link
Contributor

Here is signature and diagnostics files, let me know if you need something else:
zha-frient A_S EMIZB-132-signature.json
zha-frient A_S EMIZB-132-diagnostics.json

As for the invalid divisor message, how can I get it? I enabled debug logging in zha integration and grepping my home assistant logs with:

$ sudo journalctl -u home-assistant --since today --grep 0x0302 -f

But nothing shows up for now, do I need to do anything else?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants