Automation with sequential condition

Hi there,

One question concerning conditions. As i read they have all to be true to execute an action. But what if i want something to be executed after a row of conditions is executed in exactly the given order. Like a secret knock sing?
i want the children to be able to open the gardendoor with a secret ringing (e.g. some seconds ringing, then pause for x seconds, then ringing for a time,…).
As an action i’d use a ring intercom which i already integrated successfully.

Is something like that possible?

What i currently have is as follows:

alias: Auto öffnen
description: ""
trigger:
  - platform: state
    entity_id:
      - binary_sensor.gartentor_ding
    to: "on"
    for:
      hours: 0
      minutes: 0
      seconds: 5
    enabled: true
  - platform: state
    entity_id:
      - binary_sensor.gartentor_ding
    to: "on"
    for:
      hours: 0
      minutes: 0
      seconds: 0
    enabled: false
condition:
  - condition: state
    entity_id: binary_sensor.gartentor_ding
    state: "on"
    for:
      hours: 0
      minutes: 0
      seconds: 5
    enabled: false
action:
  - device_id: c6db6c52077b4e788f1b238d91667efd
    domain: lock
    entity_id: 8288a956c7ee1d8f77a1cbba85ed5300
    type: unlock
  - service: camera.record
    target:
      entity_id:
        - camera.vorm_haus_hd_stream
      device_id: []
      area_id: []
    data:
      duration: 30
      lookback: 0
      filename: >-
        /share/NAS_Freigabe/Kamera/Video_{{ now ().year }}{{ now
        ().month         }}{{now().day }}_{{ now ().hour }}{{ now ().minute
        }}.mp4
  - service: notify.all_telegram
    data:
      message: Bewegung erkannt
      title: Überwachung
      data:
        photo:
          - file: >-
              /share/NAS_Freigabe/Kamera/Video_{{ now ().year }}{{ now ().month
              }}{{now().day }}_{{ now ().hour }}{{ now ().minute }}.mp4
            capture: Snapshot
mode: single

This works. But it’s not a “secret knock sign” :slight_smile:
Funnily it only works (as of now) when the trigger lasts 5 seconds. If i put it in condition, it doesn’t work (or everytime i tried i did not do it 5s long…)

Best regards
wasty

Use wait_for_trigger.

alias: Auto öffnen
description: ""
trigger:
  - platform: state
    entity_id:
      - binary_sensor.gartentor_ding
    to: "on"
    for:
      seconds: 5
condition: []
action:
  - wait_for_trigger:
      - platform: state
        entity_id:
          - binary_sensor.gartentor_ding
        to: "on"
        for:
          seconds: 5
    timeout:
      seconds: 7
    continue_on_timeout: false
  - device_id: c6db6c52077b4e788f1b238d91667efd
    domain: lock
    entity_id: 8288a956c7ee1d8f77a1cbba85ed5300
    type: unlock
  - service: camera.record
    target:
      entity_id:
        - camera.vorm_haus_hd_stream
      device_id: []
      area_id: []
    data:
      duration: 30
      lookback: 0
      filename: >-
        /share/NAS_Freigabe/Kamera/Video_{{ now ().year }}{{ now
        ().month         }}{{now().day }}_{{ now ().hour }}{{ now ().minute
        }}.mp4
  - service: notify.all_telegram
    data:
      message: Bewegung erkannt
      title: Überwachung
      data:
        photo:
          - file: >-
              /share/NAS_Freigabe/Kamera/Video_{{ now ().year }}{{ now ().month
              }}{{now().day }}_{{ now ().hour }}{{ now ().minute }}.mp4
            capture: Snapshot
mode: single
max_exceeded: silent

Thanks. This looks promising.
ONe more question. Do make it more “fail-safe”, is it possible to add a second action in parallel?

alias: Gartentor Auto öffnen
description: Neuer Versuch
trigger:
  - platform: state
    entity_id:
      - binary_sensor.gartentor_ding
    to: "on"
    for:
      seconds: 5
  - platform: state
    entity_id:
      - binary_sensor.gartentor_ding
    to: "on"
    for:
      hours: 0
      minutes: 0
      seconds: 4
condition: []
action:
  - parallel:
      - wait_for_trigger:
          - platform: state
            entity_id:
              - binary_sensor.gartentor_ding
            to: "on"
            for:
              hours: 0
              minutes: 0
              seconds: 4
        timeout:
          hours: 0
          minutes: 0
          seconds: 6
          milliseconds: 0
        continue_on_timeout: false
      - wait_for_trigger:
          - platform: state
            entity_id:
              - binary_sensor.gartentor_ding
            to: "on"
            for:
              seconds: 5
        timeout:
          seconds: 7
        continue_on_timeout: false
  - device_id: c6db6c52077b4e788f1b238d91667efd
    domain: lock
    entity_id: 8288a956c7ee1d8f77a1cbba85ed5300
    type: unlock
  - service: camera.record
    target:
      entity_id:
        - camera.vorm_haus_hd_stream
      device_id: []
      area_id: []
    data:
      duration: 30
      lookback: 0
      filename: >-
        /share/NAS_Freigabe/Kamera/Video_{{ now ().year }}{{ now
        ().month         }}{{now().day }}_{{ now ().hour }}{{ now ().minute
        }}.mp4
  - service: notify.all_telegram
    data:
      message: Bewegung erkannt
      title: Überwachung
      data:
        photo:
          - file: >-
              /share/NAS_Freigabe/Kamera/Video_{{ now ().year }}{{ now ().month
              }}{{now().day }}_{{ now ().hour }}{{ now ().minute }}.mp4
            capture: Snapshot
mode: single
max_exceeded: silent

Or does it then need to fulfill both?

BR
Wasty

Regarding the lastest version of the automation you posted, tell me how you think it works.

Hi
Honestly my first intention was that this will offer me a better timeframe with 1 seconds ringing tolerance and 1s waiting tolerance.
But I think meanwhile I found out that all the values from your template are minimum values. If I press 1s longer or wait 1s longer this is also ok (at least that’s my impression).
So yours is ok :grin:
Thanks
Wasty

1 Like