Support for AVM Fritz! Smart Home Components

did you try to check your installed version of urllib3 and chardet?

try pip show urllib3 and pip show chardet

Can you please double check the REQUIREMENTS = ['pyfritzhome==0.3.1'] variable of the custom component? and also the version in your /root/.homeassistant/deps/lib/python3.6/site-packages/pyfritzhome/version.py file?

Thx for your feedback and you hard work @hthiery. :slight_smile:

Seems the Requirements Variable in the custom components is the correct one:

But if I look under /root/.homeassistant/deps/lib/python3.6/site-packages/pyfritzhome/version.py it shows me 0.2.4 as Version:

I had to install it in the virtualenv and now it works. This is awesome, ComeDECT support was the only thing I missed with Homeassistant so it is a really great addition. I hope it gets merged into master soon.

I just deleted the pyfritzhome folder under /root/.homeassistant/deps/lib/python3.6/site-packages/ manually.

After a restart, it works as expected and I can now set my temperature via the HA webinterface :+1:

I found this post after my github entry Problem with FRITZ OS 6.51 · Issue #1 · hthiery/homeassistant · GitHub .

I have a similar problem with my fritzbox 6490 and OS 6.51 (newer isn’t possible at this time → provider).

% pip3 show pyfritzhome
Name: pyfritzhome
Version: 0.3.3

Error message in HA and also fritzhome cli tool:

2017-11-08 11:42:06 ERROR (MainThread) [homeassistant.components.climate] Error while setting up platform fritzhome
Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/homeassistant/helpers/entity_component.py", line 170, in _async_setup_platform
    SLOW_SETUP_MAX_WAIT, loop=self.hass.loop)
  File "/usr/lib/python3.6/asyncio/tasks.py", line 358, in wait_for
    return fut.result()
  File "/usr/lib/python3.6/asyncio/futures.py", line 245, in result
    raise self._exception
  File "/usr/lib/python3.6/concurrent/futures/thread.py", line 56, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/home/dominion/.homeassistant/custom_components/climate/fritzhome.py", line 31, in setup_platform
    device_list = fritz.get_devices()
  File "/home/dominion/.homeassistant/deps/lib/python3.6/site-packages/pyfritzhome/fritzhome.py", line 133, in get_devices
    device = FritzhomeDevice(self, node=element)
  File "/home/dominion/.homeassistant/deps/lib/python3.6/site-packages/pyfritzhome/fritzhome.py", line 239, in __init__
    self._update_from_node(node)
  File "/home/dominion/.homeassistant/deps/lib/python3.6/site-packages/pyfritzhome/fritzhome.py", line 272, in _update_from_node
    self.device_lock = bool(get_node_value(n, 'devicelock'))
  File "/home/dominion/.homeassistant/deps/lib/python3.6/site-packages/pyfritzhome/fritzhome.py", line 28, in get_node_value
    return get_text(node.getElementsByTagName(name)[0].childNodes)
IndexError: list index out of range

greetz,
Dominion

Hi, @hthiery,

With the latest version of the fritzhome custom component from github (Nov. 3), that should fix a problem when device is not present I’am facing the following error:

2017-11-07 23:57:24 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/asyncio/tasks.py", line 180, in _step
    result = coro.send(None)
  File "/usr/local/lib/python3.6/site-packages/homeassistant/helpers/entity_component.py", line 398, in async_process_entity
    new_entity, self, update_before_add=update_before_add
  File "/usr/local/lib/python3.6/site-packages/homeassistant/helpers/entity_component.py", line 246, in async_add_entity
    yield from entity.async_update_ha_state()
  File "/usr/local/lib/python3.6/site-packages/homeassistant/helpers/entity.py", line 211, in async_update_ha_state
    if not self.available:
  File "/root/.homeassistant/custom_components/climate/fritzhome.py", line 59, in available
    return self._device.present
AttributeError: 'FritzhomeDevice' object has no attribute 'present'
2017-11-07 23:57:25 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/asyncio/tasks.py", line 180, in _step
    result = coro.send(None)
  File "/usr/local/lib/python3.6/site-packages/homeassistant/helpers/entity_component.py", line 398, in async_process_entity
    new_entity, self, update_before_add=update_before_add
  File "/usr/local/lib/python3.6/site-packages/homeassistant/helpers/entity_component.py", line 246, in async_add_entity
    yield from entity.async_update_ha_state()
  File "/usr/local/lib/python3.6/site-packages/homeassistant/helpers/entity.py", line 211, in async_update_ha_state
    if not self.available:
  File "/root/.homeassistant/custom_components/climate/fritzhome.py", line 59, in available
    return self._device.present
AttributeError: 'FritzhomeDevice' object has no attribute 'present'

My installed pyfritzhome Version is 0.3.3 and HA is on Version 0.57.2

Hi @hthiery,

I wan’t to just give you feedback, that my error was again because of an old pyfritzhome version under “/root/.homeassistant/deps/lib/python3.6/site-packages/”
There was version 3.1 while 3.3 is needed for your latest custom components.
After deleting the 3.1 folder under /root/.homeassistant/deps/lib/python3.6/site-packages/ it works again.

Thank you very much for your help :+1:

Hi @CM000n,

I think there is a problem with your home assistant installation. I installed it in an virtualenv and homeassistant manages the package dependencies. I followed the installation description here: https://home-assistant.io/docs/installation/virtualenv/.

Maybe you should take a look on that to avoid this kind of problems in the future.


Heiko

I updated to Home Assistant 0.58 and Python 3.5 and now my Fritzdect modules don’t show up anymore in Home Assistant. In the logs I am getting this message:

2017-11-19 00:55:34 ERROR (MainThread) [homeassistant.loader] Error loading custom_components.climate.fritzhome. Make sure all dependencies are installed
Traceback (most recent call last):
  File "/opt/homeassistant/lib/python3.5/site-packages/homeassistant/loader.py", line 142, in get_component
    module = importlib.import_module(path)
  File "/usr/lib/python3.5/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 986, in _gcd_import
  File "<frozen importlib._bootstrap>", line 969, in _find_and_load
  File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 673, in exec_module
  File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
  File "/home/homeassistant/.homeassistant/custom_components/climate/fritzhome.py", line 11, in <module>
    from homeassistant.components.climate import (
ImportError: cannot import name 'PRECISION_HALVES'
2017-11-19 00:55:34 ERROR (MainThread) [homeassistant.loader] Unable to find component climate.fritzhome
2017-11-19 00:55:37 ERROR (MainThread) [homeassistant.loader] Error loading custom_components.climate.fritzhome. Make sure all dependencies are installed
Traceback (most recent call last):
  File "/opt/homeassistant/lib/python3.5/site-packages/homeassistant/loader.py", line 142, in get_component
    module = importlib.import_module(path)
  File "/usr/lib/python3.5/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 986, in _gcd_import
  File "<frozen importlib._bootstrap>", line 969, in _find_and_load
  File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 673, in exec_module
  File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
  File "/home/homeassistant/.homeassistant/custom_components/climate/fritzhome.py", line 11, in <module>
    from homeassistant.components.climate import (
ImportError: cannot import name 'PRECISION_HALVES'
2017-11-19 00:55:37 ERROR (MainThread) [homeassistant.loader] Unable to find component climate.fritzhome

I installed the latest pyfritzhome into my virtualenv successfully without errors:

pip3 install pyfritzhome
Collecting pyfritzhome
Requirement already satisfied: requests in /opt/homeassistant/lib/python3.5/site-packages (from pyfritzhome)
Requirement already satisfied: idna<2.7,>=2.5 in /opt/homeassistant/lib/python3.5/site-packages (from requests->pyfritzhome)
Requirement already satisfied: certifi>=2017.4.17 in /opt/homeassistant/lib/python3.5/site-packages (from requests->pyfritzhome)
Requirement already satisfied: urllib3<1.23,>=1.21.1 in /opt/homeassistant/lib/python3.5/site-packages (from requests->pyfritzhome)
Requirement already satisfied: chardet<3.1.0,>=3.0.2 in /opt/homeassistant/lib/python3.5/site-packages (from requests->pyfritzhome)
Installing collected packages: pyfritzhome
Successfully installed pyfritzhome-0.3.4

Okay, I commented out/removed both PRECISION_HALVES sections, and the Comet DECT show up again.

Changed sections:

from homeassistant.components.climate import (
    ClimateDevice, STATE_ECO
)

and

#    @property
#    def precision(self):
#        """Return precision 0.5."""
#        return PRECISION_HALVES

Indeed the version on github isnt’t working ;-( I currently prepare the component for bring it upstream.

Now the version in master branch should work again.

Thanks, hope it gets into the official repository soon.

Wow, look how much work has already been invested in the implementation of the new Fritzhome components:

It looks like the component will be released soon.
Thank you so much @hthiery and all the others.

Works also beautifull with the DECT!200 Switches! Thank you so much!

1 Like

Hey CM000n, could you be so kind and share your code (how you implemented this) with me?
I’m using lovelace.ui and still to fresh to get it to work correctly :slight_smile:

Deutsch geht auch :slight_smile:

Hi @Dominik_Heiss,

I think in the official section of the forum we should stay with the English. But if you want, you can send me a PM in German.

I just use the -meanwhile - official Fritzbox component from @hthiery : https://www.home-assistant.io/components/fritzbox/

Then I have some template sensors in my sensors.yaml, for single values from the Fritzbox switches and thermostats. for me t looks like this for example:

####################################################
#                                                  #
#                  TEMPLATE SENSORS                #
#                                                  #
####################################################

  - platform: template
    sensors:
      sonos_wohnzimmer_state:
        value_template: '{{ states("media_player.wohnzimmer") }}'
        friendly_name: 'Status'
      sonos_schlafzim_state:
        value_template: '{{ states("media_player.sonos_schlafzim") }}'
        friendly_name: 'Status'
      sonos_bad_state:
        value_template: '{{ states("media_player.sonos_bad") }}'
        friendly_name: 'Status'
      chromecast_wohnzimmer_state:
        value_template: '{{ states("media_player.chromecast_wohnzimmer") }}'
        friendly_name: 'Status'
      tv_wohnzimmer_state:
        value_template: '{{ states("binary_sensor.device_tracker_philipstv") }}'
        friendly_name: 'Status'
      stromverbrauch_spuehlmaschine:
        value_template: '{{ states.switch.steckdose_spulmaschine.attributes["current_power_w"] | replace(" W", "") | float }}'
        unit_of_measurement: 'W'
        friendly_name: 'Stromverbrauch Spülmaschine'
      stromverbrauch_waschmaschine:
        value_template: '{{ states.switch.steckdose_waschmaschine.attributes["current_power_w"] | replace(" W", "") | float }}'
        unit_of_measurement: 'W'
        friendly_name: 'Stromverbrauch Waschmaschine'
      stromverbrauch_trockner:
        value_template: '{{ states.switch.steckdose_trockner.attributes["current_power_w"] | replace(" W", "") | float }}'
        unit_of_measurement: 'W'
        friendly_name: 'Stromverbrauch Trockner'
      stromverbrauch_wohnzimmer_ecke:
        value_template: '{{ states.switch.steckdose_wohnzimmer_ecke.attributes["current_power_w"] | replace(" W", "") | float }}'
        unit_of_measurement: 'W'
        friendly_name: 'Stromverbrauch Wohnzimmer Ecke'
      stromverbrauch_buero:
        value_template: '{{ states.switch.steckdose_buro.attributes["current_power_w"] | replace(" W", "") | float }}'
        unit_of_measurement: 'W'
        friendly_name: 'Stromverbrauch Büro'
      gesamtverbrauch_spuehlmaschine:
        value_template: '{{ states.switch.steckdose_spulmaschine.attributes["total_consumption"] | replace(" kWh", "") | float }}'
        unit_of_measurement: 'kWh'
        friendly_name: 'Gesamtvebrauch Spülmaschine'
      gesamtverbrauch_waschmaschine:
        value_template: '{{ states.switch.steckdose_waschmaschine.attributes["total_consumption"] | replace(" kWh", "") | float }}'
        unit_of_measurement: 'kWh'
        friendly_name: 'Gesamtverbrauch Waschmaschine'
      gesamtverbrauch_trockner:
        value_template: '{{ states.switch.steckdose_trockner.attributes["total_consumption"] | replace(" kWh", "") | float }}'
        unit_of_measurement: 'kWh'
        friendly_name: 'Gesamtvebrauch Trockner'
      gesamtverbrauch_wohnzimmer_ecke:
        value_template: '{{ states.switch.steckdose_wohnzimmer_ecke.attributes["total_consumption"] | replace(" kWh", "") | float }}'
        unit_of_measurement: 'kWh'
        friendly_name: 'Gesamtvebrauch Wohnzimmer Ecke'
      gesamtverbrauch_buero:
        value_template: '{{ states.switch.steckdose_buro.attributes["total_consumption"] | replace(" kWh", "") | float }}'
        unit_of_measurement: 'kWh'
        friendly_name: 'Gesamtvebrauch Büro'
      temperatur_wohness:
        value_template: '{{ states.switch.steckdose_spulmaschine.attributes["temperature"] | replace(" C", "") | float }}'
        unit_of_measurement: '°C'
        friendly_name: 'Temperatur Wohn./Ess.'
      temperatur_keller:
        value_template: '{{ states.switch.steckdose_waschmaschine.attributes["temperature"] | replace(" C", "") | float }}'
        unit_of_measurement: '°C'
        friendly_name: 'Temperatur Keller'
      temperatur_wohnzimmer_ecke:
        value_template: '{{ states.switch.steckdose_wohnzimmer_ecke.attributes["temperature"] | replace(" C", "") | float }}'
        unit_of_measurement: '°C'
        friendly_name: 'Temperatur Wohnzimmer Ecke'
      temperatur_buero:
        value_template: '{{ states.switch.steckdose_buro.attributes["temperature"] | replace(" C", "") | float }}'
        unit_of_measurement: '°C'
        friendly_name: 'Temperatur Büro'
      status_spuelmaschine:
        friendly_name: 'Spülmaschine'
        value_template: >-
          {% if states('sensor.stromverbrauch_spuehlmaschine')|float <= 0 %}
            Aus
          {% elif states('sensor.stromverbrauch_spuehlmaschine')|float < 100 %}
            Spült
          {% elif states('sensor.stromverbrauch_spuehlmaschine')|float >= 100 %}
            Trocknet
          {% else %}
            PRÜFEN!
          {% endif %}
      status_waschmaschine:
        friendly_name: 'Waschmaschine'
        value_template: >-
          {% if states('sensor.stromverbrauch_waschmaschine')|float <= 0 %}
            Aus
          {% elif states('sensor.stromverbrauch_waschmaschine')|float <= 3.9 %}
            Fertig
          {% elif states('sensor.stromverbrauch_waschmaschine')|float > 3.9 %}
            Wäscht
          {% else %}
            PRÜFEN!
          {% endif %}
      status_trockner:
        friendly_name: 'Trockner'
        value_template: >-
          {% if states('sensor.stromverbrauch_trockner')|float <= 0 %}
            Aus
          {% elif states('sensor.stromverbrauch_trockner')|float <= 7 %}
            Fertig
          {% elif states('sensor.stromverbrauch_trockner')|float > 7 %}
            Trocknet
          {% else %}
            PRÜFEN!
          {% endif %}
      fritzbox_uptime:
        value_template: '{{ states.sensor.fritz_netmonitor.attributes["uptime"] | replace("s", "") }}'
        unit_of_measurement: 's'
        friendly_name: 'Fritzbox Uptime'
      fritzbox_bytes_sent:
        value_template: '{{ states.sensor.fritz_netmonitor.attributes["bytes_sent"] | replace("B", "") }}'
        unit_of_measurement: 'B'
        friendly_name: 'Fritzbox Bytes sent'
      fritzbox_bytes_received:
        value_template: '{{ states.sensor.fritz_netmonitor.attributes["bytes_received"] | replace("B", "") }}'
        unit_of_measurement: 'B'
        friendly_name: 'Fritzbox Bytes received'
      fritzbox_transmission_rate_up:
        value_template: '{{ states.sensor.fritz_netmonitor.attributes["transmission_rate_up"] | replace("B/s", "") }}'
        unit_of_measurement: 'B/s'
        friendly_name: 'Fritzbox Current Upstream Speed'
      fritzbox_transmission_rate_down:
        value_template: '{{ states.sensor.fritz_netmonitor.attributes["transmission_rate_down"] | replace("B/s", "") }}'
        unit_of_measurement: 'B/s'
        friendly_name: 'Fritzbox Current Downstream Speed'
      fritzbox_max_byte_rate_up:
        value_template: '{{ states.sensor.fritz_netmonitor.attributes["max_byte_rate_up"] | replace("B/s", "") }}'
        unit_of_measurement: 'B/s'
        friendly_name: 'Fritzbox Maximum Upstream-Rate'
      fritzbox_max_byte_rate_down:
        value_template: '{{ states.sensor.fritz_netmonitor.attributes["max_byte_rate_down"] | replace("B/s", "") }}'
        unit_of_measurement: 'B/s'
        friendly_name: 'Fritzbox Maximum Downstream-Rate'
      fritzbox_is_connected:
        friendly_name: 'Fritzbox Connection Status'
        value_template: >-
          {% if is_state('sensor.fritzbox_is_connected2', 'True') %}
            1
          {% else %}
            0
          {% endif %}
      fritzbox_is_linked:
        friendly_name: 'Fritzbox Link Status'
        value_template: >-
          {% if is_state('sensor.fritzbox_is_linked2', 'True') %}
            1
          {% else %}
            0
          {% endif %}
      fritzbox_is_connected2:
        value_template: '{{ states.sensor.fritz_netmonitor.attributes["is_connected"] }}'
        friendly_name: 'Fritzbox Connection Status'
      fritzbox_is_linked2:
        value_template: '{{ states.sensor.fritz_netmonitor.attributes["is_linked"] }}'
        friendly_name: 'Fritzbox Link Status'
      batterie_heizung_bad:
        value_template: '{{ states.climate.heizungbad.attributes["battery_level"] | replace(" %", "") | float }}'
        unit_of_measurement: '%'
        device_class: battery
        friendly_name: 'Batterie Heizung Bad'
      batterie_heizung_buero:
        value_template: '{{ states.climate.heizungburo.attributes["battery_level"] | replace(" %", "") | float }}'
        unit_of_measurement: '%'
        device_class: battery
        friendly_name: 'Batterie Heizung Büro'
      temperatur_climate_bad:
        value_template: '{{ states.climate.heizungbad.attributes["current_temperature"] | replace(" C", "") | float }}'
        unit_of_measurement: '°C'
        friendly_name: 'Temperatur Bad'
      temperatur_climate_buero:
        value_template: '{{ states.climate.heizungburo.attributes["current_temperature"] | replace(" C", "") | float }}'
        unit_of_measurement: '°C'
        friendly_name: 'Temperatur Büro'

And then it is, for the example from above, just a simple group in groups.yaml:

####################################################
#                   SWITCHES                       #
####################################################

Steckdosen:
  control: hidden
  entities:
    - switch.steckdose_spulmaschine
    - sensor.stromverbrauch_spuehlmaschine
    - sensor.gesamtverbrauch_spuehlmaschine
    - switch.steckdose_waschmaschine
    - sensor.stromverbrauch_waschmaschine
    - sensor.gesamtverbrauch_waschmaschine
    - switch.steckdose_trockner
    - sensor.stromverbrauch_trockner
    - sensor.gesamtverbrauch_trockner
    - switch.steckdose_buro
    - sensor.stromverbrauch_buero
    - sensor.gesamtverbrauch_buero
    - switch.steckdose_wohnzimmer_ecke
    - sensor.stromverbrauch_wohnzimmer_ecke
    - sensor.gesamtverbrauch_wohnzimmer_ecke

Hope this helps you a little :wink:
Greetings from BaWü

1 Like

Hi @CM000n,

Thank you for the examples, they helped me very much.
I started to use the Component from @hthiery right now, it is fantastic!

Concerning the FritzDECT Switches I had a little problem:

When trying to read the current Power Consumption of a FritzDECT 100 (or 200) as in your example above with:

value_template: ‘{{ states.switch.stecker_trockner.attributes[“current_power_w”] | float | round(1) }}’

I got this:

Error rendering template: UndefinedError: ‘mappingproxy object’ has no attribute ‘current_power_w’

A little research showed the following behaviour:

It doesn’t matter if the switch is set to on or off, if there is no load (no current flow) at the FritzDECT Plug, the attribute is missing.

So, depending on the current flow (zero vs nonzero), the attribute “current_power_w” disappears/appears dynamically in the state list.

My workaround to avoid the error above is this template in the sensor definition:

    value_template: >
      {% if  states.switch.stecker_trockner.attributes["current_power_w"] %}
        {{ states.switch.stecker_trockner.attributes["current_power_w"] | float | round(1) }}
      {% else %}
        0.0
      {% endif %}

Seems to work, but the question is,
Why has (only?) this attribute such a dynamic behaviour ??

Anyway: Thanks to @hthiery for his great work to integrate FritzDect into Home Assistant!

BTW:
I’m Using HassIO 0.84.2
FritzBox 7490 Firmware Release: 7.01

.

2 Likes

Hi All.

great to hear that someone else is using the components …

By the way … the sensor template can be eased by using the state_attr('switch.stecker_trockner', 'current_power_w').

1 Like

Hi @hthiery

thank you, That’s a lot easier!
I’m still trying to find may way through HA und the Jinja jungle :smile: