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
- service: input_boolean.turn_on
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
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.