Problem with time pattern not triggering automations

time_pattern is not correctly triggering automations for me.

This does not work reliably:

alias: Indoor Air Quality Check
trigger:
  - platform: time_pattern
    minutes: "5"
condition:
(etc...)

Also tried this:

alias: Indoor Air Quality Check
trigger:
  - platform: time_pattern
    minutes: 5
condition:
(etc...)

Every 5 minutes I want to check if my indoor air sensor is above a certain value (set to 15 for testing). If so, I turn on an input_boolean which I use to show a notification on my dashboard.

However, after I clear the notification by setting the input_boolean back to off, I want the input_boolean to be set back to true if after 20+ minutes the air sensor is still above the set threshold (which I do with a template checking how long ago the state of the input_boolean was changed).

It will occasionally work with the time_pattern if I set it to 10 seconds (for testing), but not reliably, nor did setting it to 5 minutes work. I even tried removing the quotation marks around the 5, didn’t seem to make a difference.

I’m using a time_pattern since a numeric_state condition won’t trigger again until it’s dropped below the stated value and I want it to trigger again if the value is still too high after I’ve cleared it. As a secondary question, is there a better way to do this?

Here’s the full automation:

alias: Indoor Air Quality Check
trigger:
  - platform: time_pattern
    minutes: "5"
condition:
  - condition: numeric_state
    entity_id: sensor.purpleair_inside_air_quality_index_epa
    above: 15
  - condition: template
    value_template: >-
      {{ as_timestamp(now()) -
      as_timestamp(states.input_boolean.indoor_air_quality_particles_high.last_changed)
      > 20*60 }}
action:
  - service: input_boolean.turn_on
    data: {}
    target:
      entity_id: input_boolean.indoor_air_quality_particles_high
mode: single

This all works as expected if I use a custom sensor that changes every minute:

This works as I would expect:

alias: Indoor Air Quality Check
trigger:
  - platform: state
    entity_id:
      - sensor.time_simple
condition:
(same code as above) 

This sensor returns the time, like “5:23” and changes once a minute:

    time_simple:
      friendly_name: "Time Simple"
      value_template: "{{ now().strftime('%-I:%M') }}"
      icon_template: "mdi:clock"

I’m running the latest version of everything as of this post:
Home Assistant 2022.9.2
Supervisor 2022.08.6
Operating System 8.5
Frontend 20220907.0 - latest

Try

"/5” :+1:

2 Likes

Ahh, this very unclear from the UI

And of course, reading the docs cleared it all up.

Thank you!

Yeah it can be. For sure.