I’m trying to create an automation based on a log event. I have the Envisalink component that will not load for some reason after a power failure, however upon a normal restart loads without any issue.
I would like to create an automation to automatically restart homeassistant based on the component not loading. I have attached some of the errors I pulled out of the logs. Does anyone have any idea on how to use this?
Log Details (ERROR)
Mon Feb 18 2019 11:19:59 GMT-0600 (CST)
Could not establish a connection with the Envisalink
Log Details (ERROR)
Mon Feb 18 2019 11:20:00 GMT-0600 (CST)
Setup failed for envisalink: Component failed to initialize.
Do you run a device_tracker to get the information which devices are connected?
If this is the case I think you should be able to trigger an automation based on the (un)availability of the Envisalink device, the fact that it does not show a ‘home’ status.
Just a high level thought, though - not 100% sure how I’d code it right now.
I’m not using any device_tracker(s) at this point. The alarm system in just routed into HomeKit which then does some fun stuff regarding location tracking of individuals.
I have solved part of my problem, which is that if HomeKit gets started without the Envisalink module it creates problems. I do this by running a check seeing if the Alarm is either armed_away, pending, or disarmeed. If it is any of these then it will start homekit.start which starts HomeKit.
I need Home Assistant to recognize that the Envisalink compment hasn’t loaded and then to restart home assistant itself so that it will successfully restart and load the Envisalink compnent.
This ultimately happens when the Raspberry Pi running Hassio loses power and starts up. It always loses the Envisalink compment. However after a quick restart it loads successfully… Which is why I’m trying to figure out how to make it look at the error logs to trigger a reset…
What do your binary_sensors show in the /dev-state tab when the Envisalink component doesn’t load?
Are they on, off, or unknown or do the sensors themselves not show up at all?
And what state does the alarm_control_panel.home_alarm show in this case?
I had tried some of the examples further down in the thread before. But I’m trying the intial one now for the binary sensor looking at the Home Assistant Logs.
Disable auto-start for the HomeKit component and use an automation to start it 10-15 seconds after Home Assistant restarts.
This gives time for the Envisalink component to initialize before the HomeKit component starts. Adjust the delay period to suit the Envisalink’s needs.
It’s the solution suggested in the HomeKit component’s documentation (includes an example of the required automation):
I’ve already done that, unfortunately it just doesn’t load the Envisalink component so the delay doesn’t help in this situation to remedy the Envisalink Component failing to load on hard boot
I see. So the Envisalink component fails to initialize after a hard-restart (server power off/on) but will initialize after a soft-restart (Home Assistant stop/restart)?
So I’m formatting something wrong. When trying to read directly from the
home-assistant.log
How should I phrase it so that this is found?
2019-02-19 14:10:31 ERROR (MainThread) [homeassistant.components.envisalink] Could not establish a connection with the Envisalink
I’ve tried:
binary_sensor:
platform: command_line
name: “Envisalink Loaded”
command: if grep -i ‘[homeassistant.components.envisalink] Could not establish a connection with the Envisalink’ .homeassistant/home-assistant.log; then echo OFF; else echo ON; fi
and tried:
binary_sensor:
platform: command_line
name: “Envisalink Loaded”
command: if grep -i ‘[homeassistant.components.envisalink] Could not establish a connection with the Envisalink’ .homeassistant/home-assistant.log >/dev/null; then echo OFF; else echo ON; fi
command: if grep -i '\[homeassistant.components.envisalink\] Could not establish a connection with the Envisalink' .homeassistant/home-assistant.log; then echo OFF; else echo ON; fi
This works when run directly from the command line:
xyz=`cat home-assistant.log | grep -ic "Could not establish a connection with the Envisalink"`; if [ $xyz -gt 0 ]; then echo ON; else echo OFF; fi
The -c option makes grep return a count of the number of matches for the given string. If it’s greater than 0 then it reports ON (else OFF).
I suggest you adapt it (my log file is located in a different folder from yours) and run it from the command line to confirm it returns ON or OFF as the case may be. Yes, those are backquotes delimiting the cat and grep section.
As per the documentation’s note, it is advisable to delimit the entire thing with single quotes for the command: option, like this
command: 'xyz=`cat home-assistant.log | grep -ic "Could not establish a connection with the Envisalink"`; if [ $xyz -gt 0 ]; then echo ON; else echo OFF; fi'
EDIT
According to the documentation, the default payload for on and off is true and false. Therefore you’ll need to add this:
payload_on: "ON"
payload_off: "OFF"
or modify the command script to return true and false (assuming that’ll be interpreted correctly by Home Assistant).