Looking into my home-assistant.log file I discovered that my Xiaomi Gateway sometimes is going crazy:
ERROR (Thread-9) [xiaomi_gateway] No data in response from hub None
I would like to create an pushbullet/telegram alert when something like this occurs.
I was thinking bash script with a command like:
grep ERROR home-assistant.log | grep xiaomi_gateway
But I am not sure how to process the output and how to integrate it with HA.
Any help,please?
gpbenton
(Graham)
November 24, 2018, 10:49am
2
Have you considered the file sensor to monitor the log file?
tom_l
November 24, 2018, 11:03am
3
I dont see how that would work as only the last line of the file is used.
Why do you have doubts?
Do you think that (even a little) flooding could lead to miss the ERROR line?
Even a 5 minutes cron could lead to that.
Anyway, I am digging into:
Creating bash or pyhton script that grep ,match the output and do a API request to HA in order to put an input_boolean to ON
Automation that checks the inputboolean and sends notification (so I will have only ONE notification)
Could it work?
gpbenton
(Graham)
November 24, 2018, 4:58pm
5
The file sensor checks the last line of the file periodically, but I have done some tests, and it doesn’t seem to check often enough to be of much use tailing a log file.
You can have mosquitto_pub read from stdin, so a cron job like
grep 'ERROR.*xiaomi_gateway' /home/homeassistant/.homeassistant/home-assistant.log | tail -n 1 | mosquitto_pub -l -t "sensor_topic"
would update the sensor periodically. You would have to update the mosquitto_pub parameters to match your broker.
You can do the same thing with curl to use the HA API, but I don’t have any experience using that.