Hi all,
I’m currently trying to figure out if it’s possible to read the output of a shell_command
call and check for errors.
My use case:
- I have a script that is triggered when I flick a switch on my HA, which backs up my Raspberry Pi.
- I also have an MQTT sensor that I use as an ‘info box’ to publish messages to to alert me of successes/failures/things in progress.
At present, my script updates the sensor to say it’s running, run the shell command, and then updates the sensor to say it is complete.
However I am now wanting to improve this process by tailoring an output message depending on success or failure of the backup.
So my question is, how would I determine the outcome of the shell command script, and tailor the message to suit?
Here is what I have so far:
backup_rpi:
alias: Backup RPi
mode: single # if the script is called again while still running, don't do anything
sequence:
- service: mqtt.publish
data:
topic: backup/message
payload: "RUNNING: RPi Backup"
qos: 2
retain: true
- service: shell_command.backup_rpi
- service: mqtt.publish
data:
topic: backup/message
payload: "COMPLETE: RPi Backup"
qos: 2
retain: true
Thanks in advance!