Home Assistant Down Notification

Wanted to share this little project, because whilst there are forum notes on the subject I couldn’t find a step by step solution, which would help other non-programmers such as myself. Spent a bit of time googling the pieces and produced the following:

I wanted to get a notification when Home Assistant has an “unplanned” shutdown. So I needed a script to check the server, a cronjob and server email.

Im running Ubuntu 17.10 and this should work with all Debians. Dont know enough about the rest.

Firs set up server email (you’ll need gmail) - https://opensourceinside.blogspot.ae/2016/09/how-to-install-and-configure-postfix-to.html.

Then create this script - sudo nano /usr/local/bin/hass_site_test.sh and add this content modifying the “youremail/domain” parts:

https://pastebin.com/t9GJ8xDz

Then - sudo nano chmod a+x /usr/local/bin/hass_site_test.sh

Add this cronjob:
crontab -e
*/5 * * * * /usr/local/bin/hass_site_test.sh >/dev/null 2>&1
ctrl o + ctrl x

Hope it helps.

3 Likes

Hi @juan11perez

Thanks for this.

A simple method that I use is using the services from Uptimerobot.com as all you need to do is punch in your HA address and it checks automatically if the server is down every 5 mins.

You then get a notification via email, telegram or the uptime robot app itself about services which are down and it’s all free as well.

2 Likes

Thank you. Agree. I found and even easier one using google sheets, but it would email 30 minutes or later after the server had gone down.
So I wanted to create my own which notifies right away.

1 Like

Does your method notify you if the computer HA runs on goes down (like a heartbeat)?

No. If your entire server goes down it doesn’t work.

Hi,

What is your 1/5/15 processor load on Ubuntu 17.10? Is it server or desktop version? Do you run anything else on it?

@Petrica Hi, It’s the desktop and I added the full LAMP stack. Running HA, zoneminder, happy bubbles, appdaemon. Runs well I think.
Not sure if this is what you’re asking regarding 1/5/15
https://hastebin.com/uzoteyuhus.sql
If not; happy to run the command if you can advise it.

Hi @juan11perez,

Thanks for the reply.

1/5/15 represents the processor load for 1 minute/5 minutes/15 minutes (in the right corner of the second row of your top command log - 2.57/2.53/2.58).

It is the sum of the individual processor tasks that are loaded at a certain time. The usual analogy is with a bridge: when there’s a car passing on a lane at each interval then the load is 1; when they’re passing slower than one at a time then the load is below 1. However, a load above 1 is normal as current gen processors are (at least) dual cores so a load of 1 on a quad core processor would be equivalent to 25% processor use (also, it depends how intensive are the tasks). The 1/5/15 loads are not necessarily a benchmark but can be an indicator when there’s something running out of sync. Yours show a constant load at 2.5x but needs to be followed over time.

When placed on a graph, the loads would be sinusoidal like. I had HA initially running on Ubuntu Server 16.04 (so pretty light) and the spike was, on idle, at 0.4 while the valley was at 0.1 over a 1.5 - 2 hours interval. During intensive tasks, generated by a lot of sensors updating, this would raise to 0.3 ~ 0.8 however afterwards it would get back to 0.1 ~ 0.4.

After Python 3.4 support has been deprecated I moved to Ubuntu Server 17.10 (same physical machine, Core i5 4250u processor running Ubuntu as VM) and the load is building up over time from 0.4 / 0.9 after restart to 0.7 / 1.3 after 1-2 days and 1.2 - 1.8 when busy (although processor use usually stays in 6 - 10% interval). There are occasional spikes in the 1 minute load over 3 but they don’t last. I’ve installed only HA in Python 3.5 virtual environment, UPS daemon (for NUT sensor), Gmusic API, Mosquitto and OpenZwave.

Although a worrying 15 m constant load would be around 3.5 there are some HA tasks that are running twice (such as toggling back on the lights after several seconds) or with a delay of 2-3 seconds but 98% of the tasks are running correctly and on time.

Is fortunate that Ubuntu 18.04 just came out :slight_smile:

1 Like

why not just use monit ? You can setup various alerts for mem/load/cpu etc.
see here.

@Petrica, Good day, thank you very much for taking the time to explain this to me. Much appreciated. I run a NuC type (clone) with Intel Celeron J1900 Quad Core 2.0G and 8GB RAM. If I understood you correctly the 2.5x then would seem normal?

The machine runs pretty light; before installing zoneminder it would see avg cpu 10% from the HA systemonitor. After zoneminder it hovers around 20%. Still light i believe.

The only issue I have noticed somewhat concerning is the RAM behaviour. Over time it runs down at maybe 0.1GB a day. I have no idea what’s causing it.

For backup I use Timeshift. Works perfect and has saved me from disaster after I go on my frequent CLI trials sprees. (Im not a computer engineer and have build up my skills like must; internet, trial and error) so Timeshift just allows me to go back where I started with one button. :slight_smile:

On that note since 18.04 is out; theoretically I should be able to install it and restore from timeshift? Any idea?

Lots of questions. Thank you again.

Also wanted to thank you again for (you may not remember) guidance with the MQTT gateway earlier this year. Got me the RF motion and contact sensors running and they’re (unlike zwave) trouble free and reliable.

@elRadix thank you. I was not aware of the tool. I presume you’re using a number of scripts. It would be useful for other new users to post the step by step implementation.

yes check here

@elRadix, thank you this is great ;-). Quick scan and seems pretty easy. I’ve set up all these MQTT binary sensors for my apache, sql, etc with automations to restart for each. Will give this a try.
Thank you again.

You’re welcome.

Yes, 2.5 load would be decent case 15 m load doesn’t go much north of that for a long period of time.

I found also some other posts complaining about resource misuse on Ubuntu 17.10. Anyway, I think that upgrading from 17.10 would be necessary as the “.10” versions have support for only 9 months (vs. 5 years for “.04”). I’m unsure whether this would play nice with the restore from 17.10 with Timeshift.

I basically do three type of backups for the VM I’m running HA on: 1. full system backup (I just turn off the machine and make a rar archive of the VM folder; the rar file amounts to about 3.5 GB); 2. snapshots of the VM (when I want to try different stuff and I need a safepoint to return to) or 3. copy only the HA config folder to another location (it has about 30 MB) whenever I only modify HA config files.

Also, the nice fact on the VM route is that I can simply copy the VM to another host (for maintenance or to one more powerful) so there is no need to change any settings and there’s virtually no downtime.

Going from 17.10 to 18.04 I wouldn’t jump the upgrade wagon but rather make a new VM with fresh 18.04, install the other programs needed, install HA and just copy the HA config files.

Are you using the 17.10 Desktop version? If so, then you might try Server version for 18.04, as it has a much lighter footprint and would reduce resource usage.

@Petrica. thank you again. Uff, lots to consider :wink:
The base OS on my machine is desktop 17.10. If I install VM and test 18.04 wont I still have the same memory problems since at the core 17.10 is supporting the VM?

I dont know enough about VM, but like the concept. It seems like a docker type approach but much simpler to implement/manage. I could have a VM for HA, one for Mosquitto, one for zoneminder, etc?

Agree, once I move I’ll only go for the server setup. I ended up with desktop because this was my RPI3 upgrade and came preinstalled with ubuntu 17.10 desktop. I just followed this tutorial https://www.home-assistant.io/docs/installation/raspberry-pi/ which sets up HA in venv including zwave etc and was running without issues in no time, so didnt want to push my luck.

Eventually you would also need to upgrade/do a clean install from 17.10 as it has limited time support.

I don’t think is there any need to have separate VMs for HA, Zoneminder and Mosquitto as long as they’re running fine at the moment.

Docker instances for each of these however would make more sense than a full VM (be it even with Ubuntu Server) which has much more overhead than Docker (Docker has also less disk requirements and it is easier to start and maintain). However, for me a full VM is more usefull (obviously, with very little effort I can mess up either type of install :smile: ).

Bare metal performance is unbeatable (at least for underpowered devices) but virtualization has a lot more advantages for convenience purposes.

In reality im only concerned about zoneminder. The latest version doesn’t work with ubuntu 17.10, so their wiki has a workaround and it works!

Reading your very helpful advise, i think bare-metal 18.04 server would suit me best. I only use this machine for this (HA,zm, etc). So best performance i can get only for that application makes sense.

So recommendation would be to dive into docker?

It is quite easy to take Docker for a spin; there’s some detailed info into a full install (and most of all, easy management): Finally dropped the Pi. This was my Move to Docker.

My setup for HA has about 2,000 entities, some 900+ being legacy scripts and automations (due to early enthusiasm when joining HA I’ve set many of them in a primitive way but afterwards haven’t got the time to edit so I’ve continued to build on those) thus a major overhaul is in sight. I’m not a software developer so I kind of find it difficult to go with Python scripts (there’s a whole different story with Yaml though). I made 300 scripts (actually very small, of only 3-4 rows each) to deal with the IR commands for 2 AC units with OpenMQTT as I didn’t had the time (and patience :slight_smile: ) to write a custom component. Or simply to use only 5 or 6 of those IR commands instead of the full block :slight_smile:

Thank you again. Will have a look at docker.
Pulled out an old laptop and installing 18.04 now to have a look.
I’ll try timeshift restore to see what happens on this test machine.

I’ve been in HA for about 8 months and learned a bit on the forum so I’ve had the opportunity to re-write 10 automations into 1 etc. So not so much legacy.

Will let you know how it goes.

Installed Monit but for some reason it does not start on boot

get this message when “sudo systemctl enable monit”

monit.service is not a native service, redirecting to systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install enable monit

Any ideas ?

Thanks in advance