various tidyups

This commit is contained in:
root
2025-12-21 20:55:54 +13:00
parent 416efa6bd3
commit 19a14e1d1b
54 changed files with 5932 additions and 502 deletions
+76 -16
View File
@@ -1,20 +1,80 @@
sensor:
- platform: template
sensors:
devices_with_low_battery:
friendly_name: "Devices with low battery"
unit_of_measurement: devices
value_template: >-
{{ states.sensor
| selectattr('attributes.device_class', 'eq', 'battery')
| map(attribute='state')
| reject('in', ['unknown', 'unavailable', 'Ok'])
| map('int', -1) | select('le', 97)
| list | count
}}
icon_template: >-
{% if is_state('sensor.devices_with_low_battery', '0') %}
template:
- sensor:
- name: "Devices with low battery"
unique_id: devices_with_low_battery_count
unit_of_measurement: "devices"
state: >
{% set ns = namespace(c=0) %}
{% for s in states.sensor %}
{% 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 %}
{% set ns.c = ns.c + 1 %}
{% endif %}
{% endif %}
{% endif %}
{% endfor %}
{{ ns.c }}
icon: >
{% if this.state | int(0) == 0 %}
mdi:check-circle
{% else %}
mdi:battery-alert
{% endif %}
- name: "Devices with low battery list"
unique_id: devices_with_low_battery_list
icon: >
{% if states('sensor.devices_with_low_battery') | int(0) == 0 %}
mdi:check-circle
{% else %}
mdi:battery-alert
{% endif %}
state: >
{% set ns = namespace(names=[]) %}
{% for s in states.sensor %}
{% 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 %}
{% set ns.names = ns.names + [s.name ~ ' (' ~ (st | int(0)) ~ '%)'] %}
{% endif %}
{% endif %}
{% endif %}
{% endfor %}
{% if ns.names | length == 0 %}
None
{% else %}
{{ ns.names | join(', ') }}
{% endif %}
attributes:
count: "{{ states('sensor.devices_with_low_battery') | int(0) }}"
entities: >
{% set ns = namespace(e=[]) %}
{% for s in states.sensor %}
{% 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 %}
{% set ns.e = ns.e + [s.entity_id] %}
{% endif %}
{% endif %}
{% endif %}
{% endif %}
{% endfor %}
{{ ns.e }}
names: >
{% set ns = namespace(n=[]) %}
{% for s in states.sensor %}
{% 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 %}
{% set ns.n = ns.n + [s.name] %}
{% endif %}
{% endif %}
{% endif %}
{% endif %}
{% endfor %}
{{ ns.n }}