How to stop automation happening for number of minutes

Hi, I have tried different ways to stop my automation which is triggered by a folder_watcher firing more than once when motion is detected and a file or files are saved on my hard drive using ftp.

This attempt doesn’t do it neither. Any way of stopping this from happening please?

  - alias: test motion
trigger:
  platform: event
  event_type: folder_watcher
  event_data:
    event_type: created
condition:
  condition: template
  value_template: '{{ (as_timestamp(now()) - as_timestamp(states.automation.test_motion.attributes.last_triggered | default(0)) | int > 300)}}'
action:
  - service: input_boolean.turn_on
    entity_id: input_boolean.motion_automation_active


  - service: notify.ios_zzz_iphone
    data_template:
      message: 'motion {{ trigger.event.data.folder.split("/IPCamRecord/")[1].split("/")[0] }}'
      data:
        attachment:
          url: 'http://zwhitfield.ddns.net:443/local/IPCamRecord/{{ trigger.event.data.folder.split("/IPCamRecord/")[1] }}/{{ trigger.event.data.file }}'
          content-type: jpeg
          hide-thumbnail: false
  - delay:
      minutes: 2
  - service: input_boolean.turn_off
    entity_id: input_boolean.motion_automation_active

Please format your YAML code according to the instructions at the top of the page.

sorry about that

Thanks, now I can make sense of it. :slight_smile:

The problem is your condition. First, last_triggered is a direct part of the state object, it’s not under attributes. Also, it will always be there, so you don’t need default. Lastly as_timestamp returns a number so you don’t need the int filter either. Change your condition to:

condition:
  condition: template
  value_template: '{{ as_timestamp(now()) - as_timestamp(states.automation.test_motion.last_triggered) > 300}}'

EDIT (much later): Wow! What was I talking about?! Lol! last_triggered is indeed under attributes. (I must have been thinking about last_updated or last_changed.) So it really should be:

condition:
  condition: template
  value_template: '{{ as_timestamp(now()) - as_timestamp(states.automation.test_motion.attributes.last_triggered) > 300}}'
1 Like