Template Trigger not triggering Automation

Hey!

I am using this template in one of my automations. The Tempate works and goes from false to true, however when that happens it doesn’t trigger the automation.
What am I doing wrong?
Help is very appreciated!


platform: template
value_template: >-
  "{{ as_timestamp(states('sensor.date_time').replace(',', '') ~ ':00') -
  state_attr('input_datetime.chores_grocery_shopping', 'timestamp') > 302400 }}"
id: grocery_shooping

What is the calculation attempting to achieve?

It subtracts the input_datetime from the current time (and date) and then checks if the result is greater than 302400 seconds (84 hours or 3.5 days). In other words, it’s determining if the input_datetime is more than 3.5 days in the past. Is that correct?

If that’s how you want it to work then I suggest you do it like this:

alias: Your automation
trigger:
- platform: template
  value_template: >
    {{ now() - as_datetime(states('input_datetime.chores_grocery_shopping')).astimezone() > timedelta(hours=84) }}
action:
... etc ...

You are correct and it seems to work!

Thank you!

1 Like