Create a template sensor to get the number of Z-Wave devices running on low battery
Emiliano Guerzoni
Project Manager | BESS Development | Driving 3+ GW of Energy Storage Projects in Italy
Hi folks and welcome to a new episode of my daily newsletter?Tips & Tricks on HomeAssistant.
If you get a new e-mail about the availability of this article it's not spam! Please open it, react and comment.
It will be appreciated and will give me a much better idea of who is actually reading all this stuff.
Thank you so much!???
Welcome to this tutorial on how to create a template sensor to monitor the number of Zwave devices in your home automation system that are running on low battery.
Low battery levels can be a frustrating problem, as it can lead to intermittent connectivity or even complete device failure (here to read the previous article on this matter).
By using a template sensor, you can easily keep track of the number of devices that need to be replaced, ensuring that your home automation system stays reliable and efficient.
In this new episode of my newsletter, I will walk you through the steps to set up a template sensor in Home Assistant to track the number of Zwave devices with low battery levels.
Let's get started!
Hardware configuration
领英推荐
Software configuration
Home Assistant code (yaml) / procedure
And for your reference this is the code behind this sensor:
? - platform: template
? ? sensors:
? ? ? nr_low_battery_zwave_devices:
? ? ? ? friendly_name: Nr ZWave devices running low battery
? ? ? ? icon_template: >
? ? ? ? ?mdi:battery-alert
? ? ? ? value_template: >??
? ? ? ? ?{% set threshold = states('input_number.sensor_battery_level_threshold') | int %}
? ? ? ? ?{%- set item = namespace(sensors=[]) -%}
? ? ? ? ?{%- for state in states.sensor
? ? ? ? ? ?| selectattr('attributes.device_class', 'defined')
? ? ? ? ? ?| selectattr('attributes.state_class', 'defined')
? ? ? ? ? ?| selectattr('attributes.device_class', '==', 'battery')
? ? ? ? ? ?| selectattr('attributes.state_class', '==', 'measurement')
? ? ? ? ? ?| rejectattr('attributes.friendly_name', 'in', 'SoggiornoPortaIngresso Charging status')
? ? ? ? ? ?| rejectattr('attributes.friendly_name', 'in', 'SoggiornoPortaIngresso Recharge or replace')
? ? ? ? ? ?| selectattr('state', 'is_number') -%}
? ? ? ? ? ?{%- if state.state | int < threshold | int -%}
? ? ? ? ? ? ?{% set item.sensors = item.sensors + [dict(name = state.name | replace(' battery', '') | replace('Battery', ''), state = state.state | int)] %}
? ? ? ? ? ?{%- endif -%}
? ? ? ? ?{%- endfor -%}
? ? ? ? ?{{ item.sensors | count }}
Thank you for reading and watching! ?? I hope you have enjoyed this article and video too.
I'm available for any feedback so, feel free to contact me or share your thoughts in the comments section below.
Your feedbacks will be very appreciated!
Meanwhile,?if you liked this article share it or?subscribe?to my newsletter?about?Home Assistant?to read all previous episodes and still up to date on latest news.