viciovb
(Vincenzo)
1
Hi everyone,
I’m trying to trigger an automation based on an error string in the log.
I created a .sh file with this command inside:
if grep -i "Switchbot communication failed" /config/home-assistant.log >/dev/null; then echo "ON"; else echo "OFF"; fi
Then on my configuration.yaml I’m using a binary sensor:
binary_sensor:
- platform: command_line
command: "/config/switchbot_error.sh"
name: "Switchbot Error"
I need help to understand why it’s not working. Thanks
koying
(Chris B)
2
Define “not working”, maybe?
What is the state of the binary sensor?
Something in the logs?
viciovb
(Vincenzo)
3
The state is always off but when I run the command from Terminal, the binary sensor state is set accordingly.
On the log I got just
2021-05-16 11:09:31 ERROR (SyncWorker_2) [homeassistant.components.command_line] Command failed: /config/switchbot_error.sh
koying
(Chris B)
4
That’s a big hint, isn’t it
Maybe try
command: "sh /config/switchbot_error.sh"
viciovb
(Vincenzo)
5
I don’t get the error anymore but it’s still not changing the binary sensor state
koying
(Chris B)
6
Be careful that command_line sensors only update once per minute, by default.
Also, I assume you took care of potential permissions issues?
viciovb
(Vincenzo)
7
Thanks for your help, I didn’t know the command_line updates once per minute. It seems to be working now
123
(Taras)
8
The polling frequency is governed by the scan_interval option and the default is 60 seconds.
scan_interval integer (optional, default: 60)
Defines number of seconds for polling interval