Low battery level detection & notification for all battery sensors

Thanks for confirming. I did that and it works very well, but was wondering if there was a simpler option.

I’m still a newbie on Home Assistant :slight_smile:

@itn3rd77 Am I on the right track here? Thanks !

Not sure what {{sensors}} contains exactly.

What I currently get for {{sensors}} (example): Light sensor EG Kitchen Battery (36 %), Multi sensor OG Bath Battery (72 %)

What I want: get rid of the unnecessary repetitive Battery, which is part of the friendly_name.

  1. Can I achieve that using {{sensors|replace("Battery","")}} ?
  2. Are multiple replaces possible?

@itn3rd77 Blueprint working fantastic. I noticed that I still get notification of my son’s phone even though it’s charging. Is that intended or can it be mended somehow to where if a device is being charged the automation skip it?

Generally you want to exclude phones and other devices that get regularly charged. This Blueprint is really intended to monitor sensors with batteries that need replacing when they run low.

1 Like

Hi,

I’m currently running into issues as some entities don’t have a device_class attribute:

UndefinedError: ‘homeassistant.util.read_only_dict.ReadOnlyDict object’ has no attribute ‘device_class’

By rejecting those enities with missing attributes as suggested in How to handle missing attribute on some entities (binary_sensors) and avoid the UndefinedError I modified the blueprint a bit so it works correctly for my setup:

{% for state in states.sensor | rejectattr('attributes.device_class', 'undefined') | selectattr('attributes.device_class', '==', 'battery') -%}

I created a fork for those who face similar issues: Home Assistant Blueprint: Low battery level detection & notification for all battery sensors · GitHub

Open your Home Assistant instance and show the blueprint import dialog with a specific blueprint pre-filled.

Cheers,
Roman

2 Likes

It is best to send sensors (entitiy) name enclodes in backtick as preformatted text, otherwise special characters in entitiy name will format the Telegram Message like underscore → italic:

message: 'The battery of the sensor(s) `{{sensors}}` is low.'

Telegram Text Format Reference: Telegram Bot API

Example:
grafik

@itn3rd77 Just following up to make sure I am on the right track. Your assistance is appreciated.

Thank you so much for this updated blueprint… i had to scroll down and explore this entire thread to find your improvements!

2 requests for you:

  1. Remove the words “Battery level” or “Battery’ (any casing) from the sensor name. This avoids sensor names like “Basement Multisensor Battery Level” when “Basement Multisensor” is better and more legible. Perhaps ideal way is to add a configurable field for wildcards to be removed?

  2. I have a bunch of devices where a binary sensor for “Low battery level” is also added. Useful for some situations in automations, but for these messages/notifications, it is redundant to the main battery level for the same device. E.g. I have “Basement Multisensor Battery Level” and “Basement Multisensor Low Battery Level” appearing. I know there is an exclude entities features but it requires me to pick entities one by one. is it possible to add a wildcard filter?

for me not working…
image

this screenshot is not telling us anything of ‘not working’. What is your experience when running the automation?

Does the line break after each sensor work for you in the Telegram notification?

After last update of ha , it seems that it broke something, as i get notifications even tho the threshold is not passed?

I was able to add a condition {{ sensors != '' }} to check if the sensors was an empty string.
Not sure why the condition in the blueprint doesn’t work as it checks the same thing.

This warning is normal. Do you run an automation without your newly added condition?
Then sensors will be replaced with devices matching your defined treshhold.

@Sbyx I just wanted so say thankyou, this is a great blueprint!

I couldn’t find any great way to get notified when a Zigbee/ZWave device has dropped off the network entirely - and it was even dangerous, e.g if I didn’t know my water-leak-sensor had dropped off the network.

So, I have borrowed (very) heavily from your code here, just making a couple of modifications, and make a new blueprint to notify once a day with a list of any devices that have gone offline.

It’s my first ever time making a blueprint, and there was no way I could have done it without your code. So, thank you!

Blueprint to notify of offline battery devices

3 Likes

@Sbyx thank you for such a nice blueprint!)

Is there a way to add a custom attribute to the notification message? I have a battery_type attribute added for my battery sensors. Would be nice to see something like
Low battery warning for: bathroom temperature battery (15% CR2032)
:upside_down_face:

2 Likes

Hi @Sbyx,

Could this blueprint work with sensors that have the battery state in volts and not percentage?

Thanks.

That would also interest me.
have the same problem. For me it is even the case that 3.0V corresponds to 100% and 2.1V to 0% since the actuators already have 2.1V low bat.

Maybe a stupid question, but when I manually ran the script, then I did get a notification (without the sensor name in it because all batteries are full).

But isn’t it supposed to only send the notification when the threshold really is below 20% or is manual running supposed to send the notification anyway?