various tidyups

This commit is contained in:
zorruno
2026-07-21 13:40:06 +12:00
parent 66bee0ccf7
commit 4e2107f7f7
31 changed files with 3120 additions and 502 deletions
+41 -4
View File
@@ -1,3 +1,40 @@
#:########################################################################################:#
# Low Battery Device Summary Package #
#:########################################################################################:#
#
# TITLE:
# Low Battery Device Summary
#
# FILE:
# packages/low_battery_device_quantity.yaml
#
# VERSION:
# V1.1 2026-07-20
#
# VERSION HISTORY:
# V1.1 2026-07-20
# - Changed the low-battery threshold from 97% to 20%.
# - Added structured documentation for scope, exclusions, and outputs.
#
# V1.0
# - Initial low-battery count and list sensors.
#
# PURPOSE:
# Finds numeric sensor entities with device_class battery whose value is 20%
# or lower, then exposes a count and a human-readable device list.
#
# SCOPE AND EXCLUSIONS:
# - Only entities in the sensor domain with device_class battery are checked.
# - Unknown, unavailable, non-numeric, and "Ok" states are excluded.
# - Battery entities in other domains are not included.
#
# OUTPUTS:
# - sensor.devices_with_low_battery reports the number of matching sensors.
# - sensor.devices_with_low_battery_list reports names and percentages.
# - The list sensor also exposes count, entities, and names attributes.
#
#:########################################################################################:#
template:
- sensor:
- name: "Devices with low battery"
@@ -9,7 +46,7 @@ template:
{% if s.attributes.device_class == 'battery' %}
{% set st = s.state %}
{% if st not in ['unknown', 'unavailable', 'Ok'] %}
{% if st | int(-1) != -1 and (st | int(0)) <= 97 %}
{% if st | int(-1) != -1 and (st | int(0)) <= 20 %}
{% set ns.c = ns.c + 1 %}
{% endif %}
{% endif %}
@@ -37,7 +74,7 @@ template:
{% if s.attributes.device_class == 'battery' %}
{% set st = s.state %}
{% if st not in ['unknown', 'unavailable', 'Ok'] %}
{% if st | int(-1) != -1 and (st | int(0)) <= 97 %}
{% if st | int(-1) != -1 and (st | int(0)) <= 20 %}
{% set ns.names = ns.names + [s.name ~ ' (' ~ (st | int(0)) ~ '%)'] %}
{% endif %}
{% endif %}
@@ -56,7 +93,7 @@ template:
{% if s.attributes.device_class == 'battery' %}
{% set st = s.state %}
{% if st not in ['unknown', 'unavailable', 'Ok'] %}
{% if st | int(-1) != -1 and (st | int(0)) <= 97 %}
{% if st | int(-1) != -1 and (st | int(0)) <= 20 %}
{% set ns.e = ns.e + [s.entity_id] %}
{% endif %}
{% endif %}
@@ -69,7 +106,7 @@ template:
{% if s.attributes.device_class == 'battery' %}
{% set st = s.state %}
{% if st not in ['unknown', 'unavailable', 'Ok'] %}
{% if st | int(-1) != -1 and (st | int(0)) <= 97 %}
{% if st | int(-1) != -1 and (st | int(0)) <= 20 %}
{% set ns.n = ns.n + [s.name] %}
{% endif %}
{% endif %}