Automated low battery warnings in under 5 minutes for Home Assistant

Published by Oliver on

A modern smart home often relies on a lot of battery powered devices. That means you need a low battery warning to keep track of all of them and change batteries in time to avoid devices dropping from your network. Fortunately I found a nice and simple solution for this problem.

Battery powered devices

I use a lot of small battery powered Zigbee devices. The awesome and cheap Aqara sensors combined with ZHA or Zigbee2MQTT make a great and cheap smart home setup.

While these devices are really energy efficient and run on a coincell for more than a year at some point you will need to change them. To avoid them running out of juice and causing problems with your automations you have to monitor all those devices.

Simple monitoring for battery states in Home Assistant

Setting up a small dashboard to keep track of them is pretty simple but still requires me to manually check regularly. But of course smart home means automation and automate we shall … this problem away.

Using a blueprint

My goal was to write an automation to regularly check all battery states and notify me if a device drops below a certain threshold. Fortunately someone already figured out how to do this and wrote this great blueprint. I simply installed it via the import function and created a new automation.

Importing a blueprint in the Automations – blueprint menu

Creating an automation

The automation needs just a couple of simple inputs. I set the threshold value to 20%, as batteries tend to drop quite quickly towards the end. Then I told the automation to check each day at 19:00 in the evening.

My automation for low battery level alerts

I excluded my phone which would otherwise also get picked up as this automation checks all available battery entities. Now comes the interesting part: the action. This could be literally anything. I have already set up my Pushover integration to send alerts to my phone and I reused it here. It sends a simple message with the the name and battery percentage of the device.

This data can be included into the message via the {{sensors}} part. Unfortunately this breaks the UI editor (as {} are seen as part of the yaml) but it can still be easily added via the yaml editor.

This code will display a list of low battery sensors split by a “,” if there is more than one device. If you want to change this you can use pipes (“|”) and any Jinja2 code to change this. To get a list with each element in a new line for example you can use this code in your template: {{sensors | replace(", ", "\n")}}.

Low battery warning notifications

This automation now runs every evening and checks all the devices. If it finds one with a low battery level it sends me a notification to my phone, allowing me to simply switch out the battery in time.

Notification on my phone

A very simple solution but one that, again, shows the power of automations and a unified control system. I can get notifications about a Google phone, an IKEA button, a Aqara sensor and a Xiaomi vacuum robot.

PS: there is also a way of creating a graph in Grafana that will automatically show all your sensor battery levels for easy visualization. More on that in my dynamic Grafana variables guide.