Template Automation trigger with for

Hi,

Consider the following simple automation :
The for clause gives an error and apparently it’s not supported, any ideas how to work around this ?

- alias: 'Roomba bin is misplaced'
  trigger:
    platform: template
    value_template: "{%if is_state_attr('vacuum.grisha', 'bin_present', false) %}true{%endif%}"
    for:
      minutes: 10 
  action:
  - service: notify.gmail_notifier
    data:
      message: 'Roomba bin is misplaced'

Hi there.

Why don’t you define a separate template sensor with that value_template and then use platform state for that sensor in the automation?

That should work properly.

Try it and let us know how it goes.

3 Likes

Take a look at the new TIMER component.

Why, that’s an elegant solution to the problem:

I ended up with this :


automations.yaml:

- alias: 'Roomba bin is misplaced'
  trigger:
    - platform: state
      entity_id: sensor.roomba_bin_present
      from: 'yes'
      to: 'no'
      for:
       minutes: 10
  action:
  - service: notify.gmail_notifier
    data:
      message: 'Roomba bin is misplaced'

sensors.yaml:

- platform: template
  sensors:
   roomba_bin_present:
     value_template: "{%if is_state_attr('vacuum.grisha', 'bin_present', true) %}yes{% else %}no{% endif %}"
5 Likes