various tidyups
This commit is contained in:
@@ -0,0 +1,78 @@
|
||||
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 %}
|
||||
{% 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 %}
|
||||
{% endfor %}
|
||||
{{ ns.n }}
|
||||
Reference in New Issue
Block a user