Battery Monitoring Solution for Smart Devices

Hey everyone! :rocket: I’ve been diving into the world of smart home automation and wanted to share a solution I came up with for monitoring battery levels across my devices. I’ve got a mix of Homematic, Z-Wave, and other battery-powered gadgets, and keeping track of their battery status has been a bit of a challenge. Let me walk you through how I tackled this and where I’d love some feedback! :brain:

The Problem:
Every device reports battery levels differently. Some show percentages, others use terms like ‘High’ or ‘Low’. Manually checking each one was getting tedious, especially with new devices being added all the time. I wanted a centralized way to monitor and get notifications when batteries were running low.

My Solution:
I decided to create a system that automatically checks all battery-powered devices and alerts me when levels drop below 30%. Here’s how I did it:

  1. Configuration in configuration.yaml:
    I set up a template sensor that iterates through all states, checks for battery attributes, and compiles a list of devices with low batteries. If a device reports ‘High’, it’s converted to 100% for consistency.

yaml
sensor:

  • platform: template
    sensors:
    low_batteries:
    friendly_name: Low batteries
    value_template: >-
    {% for state in states if state.attributes.battery_level or state.attributes.battery %}
    {% set battery = state.attributes.battery_level or state.attributes.battery %}
    {% if battery == ‘High’ %}
    {% set battery = 100 %}
    {% endif %}
    {% if battery | int < 30 %}
    {{state.attributes.friendly_name}}
    {% endif %}
    {% endfor %}
    battery_status:
    friendly_name: Batteries
    icon_template: ‘{% if states.sensor.low_batteries.state %}mdi:battery-10{% else %}mdi:battery{% endif %}’
    value_template: ‘{% if states.sensor.low_batteries.state %}{{states.sensor.low_batteries.state}}{% else %}OK{% endif %}’
  1. Automation for Notifications:
    I added an automation that triggers when the low_batteries sensor detects an issue. It sends a Pushover notification with the list of devices needing attention.

yaml
automations.yaml:

  • alias: Low battery notification
    trigger:
    • platform: state
      entity_id: sensor.low_batteries
      condition:
    • condition: template
      value_template: ‘{% if states.sensor.low_batteries.state %}true{% else %}false{% endif %}’
      action:
    • service: notify.pushover_jan
      data_template:
      message: ‘Low batteries detected: {{ states.sensor.low_batteries.state }}’

What’s Working:
This setup works seamlessly across all my devices, current and future. The battery_status sensor gives me a quick glance on my dashboard, and the notifications ensure I never overlook a low battery.

Where I’m Stuck:
I’m not entirely happy with how the low_batteries sensor presents the data. It just lists the device names separated by spaces. I’d love to display this as a proper list for better readability. Any suggestions on how to achieve this would be fantastic! :thinking:

Final Thoughts:
It’s amazing how a bit of scripting can solve such a common issue. I’d love to hear how others are handling battery monitoring in their setups. Whether it’s a different approach or just some tweaks to improve my current setup, I’m all ears! :headphones:

Thanks for reading, and happy automating! :star2: