Trigger notification based on results of script

Is it possible to trigger a notification, based on results from an script? For example, my current setup constists of this:

1. Config on Github, HA runs on clone of it
2. When a new device is connected, create a new commit with the new devices
3. Push that commit to github

Now, my last step can fail, for example, when I’ve added a new commit on Github, but not yet pulled it down on my HA.
I’ve got a simple script for now, that just says git push, I could extend that to take account for this issue.

I’m just wondering if it is possible to capture the results of the shell_command (other than using a dummy sensor which I’d update using the REST API) so I can send myself a notification whenever the action fails?

Well…you already accounted for my usual answer :slight_smile:

But no a shell_command is afaik currently a send only so no return value is read. You could also do the error handling in the script that is called by the shell_comand component and send a notification from there… e.g. via REST API and Telegram (WITHOUT dummy sensor :D)



I’ve just added that part with the dummy sensor, since I now know how I would need to do it that way, not to prevent you from answering offcourse :wink:
Anyways, I think it’ll be better to use a dummy sensor anyways (if, like you said, there’s no other way), no need to fiddle with REST API’s (other than the one from HA) .

EDIT: I just though about something, couldn’t I use the script to send a custom event using HA REST API, instead of creating a dummy sensor?
That way I could just create an automation that acts on that event. Gotta figure out how/if custom events can be done

That’s pretty much what I was trying to say. I don’t know about events being sent from REST but you could trigger any service for notification from the REST API.

Fiddeling with events seems to be a bit more complicated for me and seems to require tinkering around with python code inside of HA to add handlers for that.


Actually, I have just done a quick test.
Turns out, you can just fire any custom event from the API.

I’ve got it setup like this now:

alias: "Testing event"
  platform: event
  event_type: my_test_event
  - service: persistent_notification.create
      title: "Test"
      message: "Yep, triggered all right"

While calling it from the API like this:

curl --verbose -X POST -H "x-ha-access: MYPASS" -H "Content-Type: application/json" https://ip:8123/api/events/my_test_event -d "{ 'data': 'Testing' }"

No need to thinker with the Python code, the notification popped up nicely


Thanks for letting me know and awesome work done here! Always the best feeling if you can get something right :smiley:


1 Like

Absolutely, finding a solution to a problem is already a good feeling.
Knowing that somebody else is helped by the same solution is even better :smiley:

1 Like

Greetings! I want to use this to trigger sending a notification from Hass in a script of mine.
Now i need to figure out how to include data from the curl aswell. I want to include message and attachment information. Any Ideas how to do this with json and the http api?

      service: notify.ios_robbies_iphone_7_plus
        message: "Something happened at home!""
            url: <URL>
            content-type: gif
            hide-thumbnail: false