Can someone help me understand what im doing wrong here?
The following automation is loaded, can be manually triggered but will not trigger on
the time_pattern provided… I want every hour eventually but atm I’m doing 1 minute for testing purposes.
- alias: Zigbee|Devices|IsUnavailable
trigger:
- platform: time_pattern
minutes: "/1" # Typo fixed
variables:
devices_count: >
{% set ns = namespace(zb_offline=[]) %}
{% for s in states.sensor %}
{% if 'snzb' in s.entity_id and '_power' in s.entity_id and states(s.entity_id)=='unavailable' %}
{% set ns.zb_offline = ns.zb_offline + [ s ] %}
{% endif %}
{% endfor %}
{{ ns.zb_offline | list | count > 0 }}
devices: >
{% set ns = namespace(zb_offline=[]) %}
{% for s in states.sensor %}
{% if 'snzb' in s.entity_id and '_power' in s.entity_id and states(s.entity_id)=='unavailable' %}
{% set ns.zb_offline = ns.zb_offline + [ s ] %}
{% endif %}
{% endfor %}
{{ ns.zb_offline | map(attribute='entity_id') | join('<br>') | replace('sensor.','') | replace('_power','') | upper}}
condition:
- condition: template
value_template: '{{ devices_count }} > 0'
action:
- service: notify.all_devices
data_template:
title: "Varning: Zigbee-enheter kan inte nås"
message: >
{{ devices }}
My fix:
# Stupid typo in variable... forgot to remove the conditional test from testing
# Changed
{{ ns.zb_offline | list | count > 0 }}
# to
{{ ns.zb_offline | list | count }}
But I can trigger the automation by hitting “run” in the “…config/automation/dashboard”
And I do get the notification that way so the condition gets fullfilled?