Notification when home assistant is down

I am happy with the fact that Homeassistant is running quite stable, but every now and then it stops responding. Of course there are numerous threads on receiving a notification when a device is down, but I would like to know if there is a simple way to get a notification when Homeassistant is down.

Is there a way to do this easily? As inbound connections to my setup are blocked I was thinking of running a script on Homeassistant that sends an alive message every minute to a webserver. If that webserver hasn’t received the alive message for ten minutes it will send an email.

You can automate this (checking the web port and sending email) using monit. It is packaged in raspbian already.

1 Like

I am interested in this as well, can you tell us more @kirichkov? Any instructions or guides?

BEWARE! THE CONFIGURATION BELOW MIGHT EXPOSE YOUR HASS INSTANCE TO CONTROL FROM AN UNAUTHORIZED USER! USE AT YOUR OWN RISK

After the big bold let me explain - my hass instance is accessible only from my internal network! It is not accessible from the Internet in any ways, hence my security is somewhat lax! If you’ve exposed your HASS host to the Internet I advise you NOT TO use the configuration below, unless you understand the configuration and its implications.

First install monit:

 $ sudo apt-get install monit

Then edit /etc/monit/monitrc and make changes to the following lines so that you can send e-mails (you need a working smtp server to send e-mails!):

# set mailserver mail.bar.baz,               # primary mailserver
#                backup.bar.baz port 10025,  # backup mailserver on port 10025
#                localhost                   # fallback relay

Enable the built-in localhost by uncommenting and editing the following lines:

 set httpd port 2812 and
    use address localhost  # only accept connection from localhost
    allow localhost        # allow localhost to connect to the server and
 #   allow admin:monit      # require user 'admin' with password 'monit'
 #   allow @monit           # allow users of group 'monit' to connect (rw)
 #   allow @users readonly  # allow users of group 'users' to connect readonly

The line above enables the http server and allows ANYONE to connect to it from localhost (i.e. the server where it is running). I use ssh local forwarding to access the monit instance from my own computer by adding the following parameters to ssh: -L 2812:localhost:2812 , this forwards port 2812 on my laptop/desktop to the Raspberry’s port 2812, so I type http://localhost:2812 in my browser and I’m able to view monit’s web UI.

Find the line below in /etc/monit/monitrc and modify accordingly:

# set alert [email protected]                       # receive all alerts

Then in /etc/monit/conf.d/home-assistant I have the following:

check process home-assistant pidfile /home/hass/.homeassistant/home-assistant.pid
  group automation
  group home-assistant
  start program = "/bin/systemctl start home-assistant.service"
  stop program = "/bin/systemctl stop home-assistant.service"
  if failed host localhost port 8123 proto http for 5 cycles then restart
  if 5 restarts with 5 cycles then timeout
  if cpu usage > 20% for 10 cycles then restart

Keep in mind that the above location of the PID file (/home/hass/.homeassistant/home-assistant.pid) might be different for you! I have to admit setting up monit is not really that straightforward, and also it means with the above configuration, anyone, who has access to localhost can stop/start/restart your HASS instance! Use at your own risk!

1 Like

@rpitera has posted a google spreadsheet that monitors a IP and can send an e-mail if the site doesn’t respond.

Might be a better way with no security issues.

Discussion here:

2 Likes

It can do multiple IP/URLs as well. I’ve been using it to monitor my website for two years and then added HA for at least one year and it works really well and best of all… free!

This was almost to easy to setup and seams to work flawless

1 Like

how do you put each address? Separated by comma and space, or just comma?

ANd results tells you which is down (when you have multiple)?