Time_pattern automation wont trigger?!

Hi!

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 }}
  trigger:
    - platform: time_pattern
      minutes: "/1"

that will trigger every minute.

without the / it will only trigger at the minute 1 of every hour.

Yes I know that much, the problem is … it’s not triggering at all.
The 1 is for testing purposes.

the way you have it in your first post the automation will only ever trigger once every hour at 1 minute past the hour.

if you add the / it will trigger every minute.

Apologies. I do have it in my code… the /1.
And its still not triggering every minute…
Will update first post.

- alias: Zigbee|Devices|IsUnavailable
  trigger:
    - platform: time_pattern
      minutes: "/1"
  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 }}
  

THat’s likely because your condition template is also wrong:

'{{ devices_count > 0 }}'

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?

No, if you run the automation manually it will skip the conditions by default.

If you go to the services tab and run the automation from there you can optionally tell it to not skip the conditions.

Aha! Did not know that, explains alot, thank you, I’ll investigate further

Found a typo

Ay was a typo related to the condition :slight_smile:
Thank you

1 Like