Restart hass if platform fails to load

Hi all. Looking for a quick idea on how to create an automation so that if a platform fails to load then hass is rebooted again.
Scenario is that after a power outage hass PI loads faster than my router and KNX bus is unreachable and hass is useless unless rebooted again.

This doesn’t get triggered when in an automation but if I raise the component_loaded even manually everything gets triggered fine.

  • id: Platform_monitor
    alias: Platform monitor
    initial_state: ‘on’
    trigger:
    platform: event
    event_type: component_loaded
    event_data:
    component: knx
    action:
    • service: input_boolean.turn_on
      entity_id: input_boolean.knx_platform_loaded

And the hass log says this:
2019-01-25 14:52:54 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event component_loaded[L]: component=knx>
So it seems the event is raised by the core (and this is after automation is initialized).

Clueless

So for anybody that is struggling with this - this can’t work because the event is fired before the automation is setup.
So the easy way to solve this is the following:

When hass starts run a script (in automations.yaml).

- id: Notify_home_assistant_started
  alias: Notify home assistant started
  initial_state: 'on'
  trigger: 
    platform: homeassistant
    event: start
  action: 
# run watchdog for KNX to auto resetart hass if KNX not working properly (can't reach one of the lights)        
    - service: script.turn_on
      entity_id: script.restart_hass_if_knx_fails

In the script - check if an entity that is dependent on the platform is in state “undefined”.

  restart_hass_if_knx_fails:
    sequence:
      - delay: '00:02:00'
      - condition: template
        value_template: "{{ is_state('light.kitchen_all_light', 'unavailable')  }}"
      - service: notify.mail_push
        data_template:
          title: 'Home assistant restarting'
          message: 'KNX switch not detected - restarting home assistant'
      - alias: restart HA
        service: homeassistant.restart
1 Like

Hello
Can you give me a hint on where to put your code?
I mean i’m a little confused
The first

  • id: Notify_home_assistant_started
    alias: Notify home assistant started
    initial_state: ‘on’
    trigger:
    platform: homeassistant
    event: start
    action:

run watchdog for KNX to auto resetart hass if KNX not working properly (can’t reach one of the lights)

- service: script.turn_on
  entity_id: script.restart_hass_if_knx_fails 

I need to put it in Automation.yaml

And the second part where? in automation/script?

What i want to do is if not everything has loaded after a power break, just restart home assistant.
Thank you very much

This really shouldn’t be needed at all. With HA 2021.2 there will be a new version of xknx with slightly updated reconnection logic. Maybe this improves behavior on your specific setup.

If your connection problems persist, please try to log debug messages and telegrams and file an issue on https://github.com/XKNX/xknx so it can be fixed properly.
When testing please remember it takes up to 2 minutes to detect connection loss.

It’s not a connection loss. In my case it’s inability to reach the IP to KNX controller because the network is still not fully up… I guess. So if you reconnect within 2 minutes it’s great but it doesn’t have to be a connection loss. Thanks.

The KNX connection is lost / can’t be established. That’s more or less the same in this context.
Even if there was no connection before, after a failed attempt to connect the reconnection logic should start and try again until success.

Again, if it doesn’t (after 2012.2) please let the xknx dev team know so it can be fixed. Networking problems like this are hard to test so we rely on your bug reports.