Homematic detecting lost connections

Anyone implemented a Homematic lost connection detection either like documented or something similar?

I’m trying to implement the doc example using a sensor (HM-ES-PMSw1-Pl-DN-R1 which sends frequency or voltage updates regularly and is always connected) using HA 0.88.1.

automation:
  - alias: Homematic Reconnect
    trigger:
      platform: state
      entity_id: sensor.funksteckdose_spuli_frequency
      for:
        hours: 1
    action:
      service: homematic.reconnect

But I get the following error message on config validation:

Invalid config for [automation]: dependency violation - key “for” requires key “to” to exist @ data[‘trigger’][0]. Got None. (See /config/configuration.yaml, line 36). Please check the docs at Automation - Home Assistant

Looks like “to” is required here as well, maybe this is new and was not required before?

Anyone some idea or working example?

Thx.

You need the state it should be when it triggers…

automation:
  - alias: Homematic Reconnect
    trigger:
      platform: state
      entity_id: sensor.funksteckdose_spuli_frequency
      from: 'on'  ####I don't know what this devices states would be
      to: 'off'     ####you also can use just to: without the from
      for:
        hours: 1
    action:
      service: homematic.reconnect

@Bartem that exactly is the problem, the sensor is constantly measuring the power line frequency which changes randomly (in a defined range), there is no to or from I could use. I also could use a temperature sensor for example. Same problem here I don’t know the values for to or from. I’m anyway only interested in the fact the sensor updates or does not update.

I think https://www.home-assistant.io/components/homematic/#detecting-lost-connections is wrong here?

Maybe @danielperna84 has some idea?

You could try using a statistics sensor to level out the value a little then use a numeric state trigger with above/below

Apparently there was a change with how the state trigger worked back then and now. I personally only use the second method where reboots of the CCU trigger the reconnect.

I think I found some working solution using a template binary sensor to recognize Homematic updates and trigger reconnect if needed:

binary_sensor:
  - platform: template
    sensors:
      homematic_up:
        friendly_name: "Homematic is sending updates"
        entity_id:
          - sensor.funksteckdose_spuli_frequency
          - sensor.time
        value_template: >-
          {{as_timestamp(now()) - as_timestamp(states.sensor.funksteckdose_spuli_frequency.last_changed) < 600}}

The important pieces here are the combination of entity_id: with value_template. The template evaluates the a sensor which is usually updates frequently and let the binar sensor stay on as long as there are updates in the last 10 minutes. Since no updates means no change on the sensor last_change time we need the sensor.time which updates every minute.
The template is re-calculated minimum every minute or if the actual sensor changes. If Homematic updates fail for > 10 minutes the binary sensor will change to off.

Using the following automation then can trigger the re-connect:

automation:
  - alias: Homematic Reconnect
    trigger:
      platform: state
      entity_id: binary_sensor.homematic_up
      to: 'off'
    action:
      - service: homematic.reconnect

WDYT? I can also create a pull request to update the Homematic documentation.

2 Likes

If it works I don’t see any reason why the documentation should not be updated. Would be great if you can do this. And thank’s a lot for figuring out a solution. :slight_smile:

Created https://github.com/home-assistant/home-assistant.io/pull/8880 with updated sample to detect lost Homematic connections.

Hello - well described, but in my case it seems that nothing is being updated.
I use an HmIP switch (HmIP-BSM) together with a CCU3
Is there anything different with HmIP devices?
As soon as I manually trigger a switch the binary_sensor is updated…

Thanks for your support!

For testing I created a second sensor which records how long it takes until the light-switch sensor is updated. As you can see during the night this could take up to 80 Minutes!

Here is the code for the sensor - any suggestion what I’m doing wrong?

- platform: template
    sensors:
      last_hm_update:
        friendly_name: Last Update to Homematic
        unit_of_measurement: 'min'
        entity_id: sensor.date_time
        value_template: >-
          {{((as_timestamp(now()) - as_timestamp(states.sensor.wzls_kuche_voltage.last_changed))/60)|round}}

As I run into this problem from time to time, I implemented a reconnection logic that seems more logical and reliable to me. It’s only been running here for a few days so I can’t yet speak to the true reliability. Feedback would be great, I would like to include this method in the documentation at some point if it works out well. It is still pretty convoluted and has lots of moving parts.

It is based around a program on the CCU that creates a virtual remote keypress every minute, and a 5 minute timer in Home Assistant that gets restarted (it starts again with the full 5 minutes) when the keypress is received, but will go down to zero/finish if the keypress stops for too long- which then triggers the reconnection service.

The CCU program is “Time: Recurring All-day starting at 29.01.2020 trigger at point of time Time Interval All 1 minutes; Channel selection: rcv_50:1 immediately Button press short”
rcv_50 is my name for the Virtual Remote Control HmIP-RCV-50

The Home Assistant configuration is:

timer:
  homematic_timeout: # Automation will restart homematic component on timer finish
    name: Homematic Timeout
    duration: 300

automation:
- id: homematic_timeout_renew
  alias: Homematic Timeout Renew Timer
  trigger:
  - event_data:
      channel: 1
      name: rcv_50
      param: PRESS_SHORT
    event_type: homematic.keypress
    platform: event
  action:
  - entity_id: timer.homematic_timeout
    service: timer.start
- id: homematic_timeout_start
  alias: Homematic Timeout Start Timer
  trigger:
  - event: start
    platform: homeassistant
  action:
  - entity_id: timer.homematic_timeout
    service: timer.start
- id: homematic_timeout_elapsed
  alias: Homematic Timeout Elapsed, Reconnect
  trigger:
  - event_data:
      entity_id: timer.homematic_timeout
    event_type: timer.finished
    platform: event
  action:
  - service: homematic.reconnect
  - entity_id: timer.homematic_timeout
    service: timer.start
3 Likes

Very nice!

I find the moving parts much less brittle than in the strategy above (relying on physical sensors like voltage fluctuations or energy count) which made it into the official documentation.

A bit convoluted … maybe … may I suggest the following simplification? It needs one automation less and is clearer (at least for me), too.

timer:
  homematic_watchdog_timeout:
    name: "Homematic Watchdog: Timeout"
    duration: "00:05:00"

automation:
  - alias: "Homematic Watchdog: Start & Keepalive"
    trigger:
      - platform: homeassistant
        event: start
      - platform: event # Homematic keepalive must be sent at periods < timer.homematic_watchdog_timeout.duration
        event_type: homematic.keypress
        event_data:
          name: HM-RCV-50 BidCoS-RF
          channel: 1
          param: PRESS_SHORT
    action:
      - service: timer.start
        entity_id: timer.homematic_watchdog_timeout
  - alias: "Homematic Watchdog: Dead -> Start Over & Reconnect"
    trigger:
      - platform: event
        event_type: timer.finished
        event_data:
          entity_id: timer.homematic_watchdog_timeout
    action:
      - service: timer.start
        entity_id: timer.homematic_watchdog_timeout
      - service: homematic.reconnect

BTW: Your homematic.keypress event selector didn’t work on my CCU (Raspberrymatic), but I found the correct selector for my CCU by connecting a homematic.keypress event node to a debug node in Node-RED.

1 Like

An even cleaner approach which only requires a single automation … it also allows for a more complex reconnect routine behind the guard clause for the timeout event (in my setup, I use a Telegram notification):

timer:
  homematic_watchdog_timeout:
    name: "Homematic Watchdog: Timeout"
    duration: "00:05:00"

automation:
  - alias: "Homematic Watchdog"
    trigger:
      - platform: homeassistant
        event: start
      - platform: event # Homematic keepalive at periods < timer.homematic_watchdog_timeout.duration
        event_type: homematic.keypress
        event_data:
          name: HM-RCV-50 BidCoS-RF
          channel: 1
          param: PRESS_SHORT
      - platform: event
        event_type: timer.finished
        event_data:
          entity_id: timer.homematic_watchdog_timeout
    action:
      - service: timer.start
        entity_id: timer.homematic_watchdog_timeout
      - condition: and
        conditions: "{{ trigger.event.event_type == 'timer.finished' }}"
      - service: homematic.reconnect
      - service: notify.telegram_admin
        data:
          message: "Homematic dead. Attempting to reconnect ..."
4 Likes