Is there any way that Grafana can use HomeAssistant to send notifications?

Lately, I’ve setup Grafana and I love it.
I’d like to use the Alarm functionality for a few things in my HomeAssistant system, but I’d like Grafana to use HomeAssistant’s notification service to send out important notifications.

Is there anybody that has done this?

2 Likes

Hi Timkoers,

I had the same question and did not find an answer in the blog.
I used the following approach:

I created a notification channel in grafana and used the type webhook and the following webhook settings:

URL: https://mydomain.duckdns.org/grafanapost/api/states/input_boolean.alrm_hightemp
http method: POST

I struggled with passing the autharization bearer key in the post.
Because I have a ngnix server and I used that one to extend the header with the key.

I used the following proxy rule in nginx:

 location  ^~/grafanapost/ {
    proxy_pass http://<my_local_ip>:8123;
    proxy_method POST;
    rewrite ^/grafanapost/(.*)$ /$1 break;
    proxy_set_body '{ "state": "on"  }';
    proxy_set_header  content-type "application/json";
    proxy_set_header  Authorization  "Bearer blabla...................................................................." ; 

}

It is not the best option, but it allows grafana to trigger a status change of an input_boolean in home assistant.

I would certainly be interested in a simpler solution…

1 Like

I build a tool exactly for this. You can find it here: https://github.com/pinpox/home-assistant-grafana-relay
It will listen for webhooks from grafana and send you a notification via home-assistant like this

2 Likes

This is great! I’m able to see the notifications on my phone - but they don’t seem to persist in Home Assistant. But I don’t seem to see any historical notifications in HA so it’s probably a different issue than yours. I do seem to get an exit status of 1 when a client timeout happens, though…

2021/10/26 14:01:30 {"title":"[Alerting] Test notification","ruleId":7876552415975495364,"ruleName":"Test notification","state":"alerting","evalMatches":[{"value":100,"metric":"High value","tags":null},{"value":200,"metric":"Higher Value","tags":null}],"orgId":0,"dashboardId":1,"panelId":1,"tags":{},"ruleUrl":"http://grafana.tylephony.com/","imageUrl":"https://grafana.com/assets/img/blog/mixed_styles.png","message":"Someone is testing the alert notification within Grafana."}

2021/10/26 14:01:35 Post "https://hass.tylephony.com:8123/api/services/notify/notify": context deadline exceeded (Client.Timeout exceeded while awaiting headers)

exit status 1

Should I review over on your Github? Thanks again!