Based on dale3h’s hassctl
Gets the state of the apps specified in the list and publishes the results to MQTT.
I send over MQTT as another server reads states for redundancy.
(i.e. if HA goes down it notifies me)
check_app_state.sh
#!/bin/bash
mqtthost="localhost" # mqtt broker address
mqtttopic="appcheck" # first part of topic
mqtttopichost="vostro" # second part of topic
app=$1
ps_out=`ps -ef | grep $1 | grep -v 'grep' | grep -v $0`
result=$(echo $ps_out | grep "$1")
if [[ "$result" != "" ]];then
/usr/bin/mosquitto_pub -h $mqtthost -q 0 -t $mqtttopic/$mqtttopichost/$app -m "Online"
else
/usr/bin/mosquitto_pub -h $mqtthost -q 0 -t $mqtttopic/$mqtttopichost/$app -m "Offline"
fi
check_app_list.sh
#!/bin/bash
bash /home/hass/.homeassistant/shell_scripts/check_app_state.sh motion
bash /home/hass/.homeassistant/shell_scripts/check_app_state.sh appdaemon
bash /home/hass/.homeassistant/shell_scripts/check_app_state.sh influxdb
bash /home/hass/.homeassistant/shell_scripts/check_app_state.sh docker
bash /home/hass/.homeassistant/shell_scripts/check_app_state.sh glances
bash /home/hass/.homeassistant/shell_scripts/check_app_state.sh mosquitto
bash /home/hass/.homeassistant/shell_scripts/check_app_state.sh mysql
bash /home/hass/.homeassistant/shell_scripts/check_app_state.sh webmin
bash /home/hass/.homeassistant/shell_scripts/check_app_state.sh home-assistant@hass
bash /home/hass/.homeassistant/shell_scripts/check_app_state.sh homebridge
set up a cron job to run the check_app_list.sh every x minutes.
You will have to make an mqtt sensor for each app
- platform: mqtt
state_topic: "appcheck/nana/imessage"
name: "App iMessage"
unit_of_measurement: ""
qos: 0
hope this makes sense. rushing out the door.
this is a total hack job. I don’t know what I’m doing but trial end error I got it working and I’m learning . .
feel free to fix or point out anything I could have copied better . . .
Happy new year!