Time condition passes when it shouldn't


I’m still learning HA but familiar with Python and Jinja. I’m trying to run an automation every two minutes, which checks when there was last motion. If it’s more than 30 minutes ago, do something. As a test, the action for now is just sending me a message.

But the condition passes (the action sends me a message) even though it returns False (when tested in developer tools). Is this my dodgy use of value_template at fault, or a quirk with how time_pattern works / wrong trigger?

alias: Last motion > 30 min
description: ''
  - platform: time_pattern
    minutes: /2
  - condition: template
    value_template: "{{ (as_timestamp(now()) - as_timestamp(states.automation.moshun_latest.attributes.last_triggered))|int > 1800 }}"
  - service: notify.hasshass
      message: >-
        Hello {{states.automation.moshun_latest.attributes.last_triggered}}---{{
        (as_timestamp(now()) -
         {{ (as_timestamp(now()) -
        > 1800 }}
mode: single



Welcome to HA! :slightly_smiling_face:
If you test the automation with the ‘EXECUTE’ button in the more-info dialog, only the action of the automation is executed.
The conditions are ignored.
Have you waited the 2 mins until it triggered?

Using the trigger automation service in the developer tools has a “skip conditions” option you can set to false.

1 Like

Didn’t know about that. :+1:

Oh man. Sorry - what a newbie. Though, that page could do with a tooltip explaining that. Will do a PR at some point :slight_smile: Thanks a lot for the help

Already explained in the documentation for automation services.

Also in the developer tools when Services look at the bottom. Available parameters are usually listed. Clicking the fill data button will even throw the YAML in there for you.


Is that automation just for experimentation or it used in production?

Still experimenting. Will be adding 3 more conditions

OK, because when I see automations using a Time Pattern Trigger most of the time they aren’t using the correct type of trigger.