Core: AVM FRITZ!Box loosing current_power_w state attribute when 0W

Created on 28 Feb 2020  路  17Comments  路  Source: home-assistant/core

The problem

I have three AVM 546e Powerline adapter which are capable of reading the power consumption. ever since updating to 0.106.X the devices looses the state attribute current_power_w whenever the reading is 0W. The attribute shows up again when a actual consumption is being read.

When the attribute disappears, template sensors relying on it start to spam errors in the log.

Environment

  • Home Assistant release with the issue: 0.106.1
  • Last working Home Assistant release (if known): 0.105.X
  • Operating environment (Hass.io/Docker/Windows/etc.): HASSIO on NUC
  • Integration causing this issue: fritzbox:
  • Link to integration documentation on our website: https://www.home-assistant.io/integrations/fritzbox/

Problem-relevant configuration.yaml

Device state attribute when 0W:

device_locked: true
locked: true
total_consumption: '182.065'
total_consumption_unit: kWh
friendly_name: PowerLine-Keller

Device attributes when >0W

current_power_w: 8.01
device_locked: true
locked: true
total_consumption: '182.065'
total_consumption_unit: kWh
friendly_name: PowerLine-Keller

Template sensor that creates error when the attribute is gone

  # Power sensor laundry
      messstelle_waschmaschine:
        friendly_name: "Messstelle Waschmaschine"
        unit_of_measurement: 'W'
        value_template: "{{states.switch.powerline_keller.attributes.current_power_w}}"

Traceback/Error logs

when the attribute is gone

Value cannot be processed as a number: <state switch.powerline_keller=on; device_locked=True, locked=True, total_consumption=182.064, total_consumption_unit=kWh, friendly_name=PowerLine-Keller @ 2020-02-28T19:26:35.436258+01:00> (Offending entity: )

Additional information

in 0.105 and earlier the attribute was named current_consumption. the naming changed in 0.106. in previous version the attribute stayed at 0W

fritzbox

Most helpful comment

I use this

switch_soggiorno_consumption:
        friendly_name: 'Consumo [Soggiorno]'
        value_template: >-
          {% if states.switch.soggiorno.attributes.current_power_w %}
            {{ states.switch.soggiorno.attributes.current_power_w }}
          {% else %}
            0
          {% endif %}
        icon_template: mdi:sofa
        unit_of_measurement: 'W'

All 17 comments

Has this been a problem before in fritzdect? See https://github.com/home-assistant/home-assistant/issues/20056

Thanks for pointing this out. that's odd, I've been running this setup since 1,5 years without any issue. it just popped out after the recent update

I can confirm that behaviour for hassio, 0.106.2, rpi3b after switching from fritzdect platform to fritzbox as stated in the breaking chages for 0.106. This Issue never appeared for me with fritzdect.

i think is better:

current_power: POWER
current_power_unit: W

(or as before current_consumption and current_consumption_unit)

so, the same format of total_consumption

i used a template, but with no current_power (<=0) the attribute will be hidden.

@escoand, from the changelog of 0.106 I noticed that you made the PR for moving from FRITZ!Dect to FRITZ!Box. Maybe you have an idea on how to fix this issue as well.

Anybody able to investigate what pyfritzhome is returning in such a case? The HA code looks right https://github.com/home-assistant/core/blob/19254eee3037651ffb095d6643394fcdf7805a3e/homeassistant/components/fritzbox/switch.py#L97

my workaround for this issue so far via templating:
(which I need for integration platform, too)

fritzbox:
  devices:
    - host: fritz.box
      username: user
      password: pass

sensor solarPower:
  - platform: template
    sensors:
      solar_power_sensor: 
        value_template: "{{ state_attr('switch.fritz_dect_210_1', 'current_power_w') | float | default(0) }}"
        unit_of_measurement: W
        friendly_name: "Solar Power"

very interesting, I was using this for years without ever running into this problem. Anyway, I followed the proposed solution by mitigating errors using the value template in the link

I use this

switch_soggiorno_consumption:
        friendly_name: 'Consumo [Soggiorno]'
        value_template: >-
          {% if states.switch.soggiorno.attributes.current_power_w %}
            {{ states.switch.soggiorno.attributes.current_power_w }}
          {% else %}
            0
          {% endif %}
        icon_template: mdi:sofa
        unit_of_measurement: 'W'

If nobody is willing to debug pyfritzhome we could also close this issue.

I would like to help but I don't know how....

@Kugelfang666 basically install pyfritzhome and request the data, this should work (not tested)

pip3 install pyfritzhome
fritzhome -v -u admin -p password

all I'm getting is this:

DEBUG:pyfritzhome.fritzhome:logout Traceback (most recent call last): File "/home/pi/.local/bin/fritzhome", line 10, in <module> sys.exit(main()) File "/home/pi/.local/lib/python3.7/site-packages/pyfritzhome/cli.py", line 187, in main args.func(fritzbox, args) AttributeError: 'Namespace' object has no attribute 'func'

Hmm, pyfritzhome seems to show the value correctly. I've to debug the HA code.

$ fritzhome -v -u admin -p ... -f 192.168.1.1 list
DEBUG:pyfritzhome.fritzhome:<xml.dom.minidom.Document object at 0xb1cc80a0>
DEBUG:pyfritzhome.fritzhome:<device functionbitmask="640" fwversion="07.12" id="20000" identifier="..." manufacturer="AVM" productname="FRITZ!Powerline 546E">
        <present>1</present>
        <name>FRITZ!Powerline 546E</name>
        <switch>
                <state>0</state>
                <mode>manuell</mode>
                <lock>0</lock>
                <devicelock>0</devicelock>
        </switch>
        <powermeter>
                <voltage>231757</voltage>
                <power>0</power>
                <energy>588387</energy>
        </powermeter>
</device>

##############################
name=FRITZ!Powerline 546E
  ain=...
  id=20000
  productname=FRITZ!Powerline 546E
  manufacturer=AVM
  present=True
  lock=True
  devicelock=False
 Switch:
  switch_state=False
 Powermeter:
  power=0
  energy=588387
  voltage=231.757
DEBUG:pyfritzhome.fritzhome:logout

since I'm struggeling with the same after deprecation of fritzdect, here is my output. switch.media is currently off... but states 0.

since I'm to stupid to paste it here with the proper formating:
https://0bin.net/paste/cL4EuvodWlokejUj#yywqDJlDD3LWyLjM9xsVzUGWFYEKSgsstV-0I5v/ZSr

@balloob After doing some testing I would say this is a bug (or feature) in HA. Is there a way to avoid this behaviour?

Was this page helpful?
0 / 5 - 0 ratings