Automation, is_motion for a time (5min)

hello,

i have a automation that has a condition that the motion of a binary_sensor is ON for 5 minutes.
it should be 5 minutes of movement before he performs the next one.

here is the piece code

- condition: and
    conditions:
      - type: is_motion
        condition: device
        device_id: 53b255e469a65751ad0ada6661b76198
        entity_id: binary_sensor.presence_42
        domain: binary_sensor
        for:
          hours: 0
          minutes: 5
          seconds: 0
      - condition: device
        device_id: 06c3a968a177cfaacf95843823bf7f5e
        domain: media_player
        entity_id: media_player.fire_tv_192_168_0_42
        type: is_off

when the 5 mins not reached or the sensor changed in this time, restarts the automation?
or do I have to set the automation to restart? or is sort single enough?

my sonoff motion detector triggers every 3 minutes, but that should not cause a problem here

here is the complete code to understand.

alias: RAUM KÜCHE - Schalte alles wieder an bei Bewegung
description: ''
trigger:
  - platform: state
    entity_id: group.bewegungsmelder_sonoff_kueche_group
    to: 'on'
condition: []
action:
  - service: notify.mobile_app_iphone_von_marc
    data:
      message: BEWEGUNG ERKANNT, PERSON IN DER KÜCHE
  - choose:
      - conditions:
          - condition: sun
            before: sunrise
            after: sunset
        sequence:
          - service: switch.turn_on
            data: {}
            target:
              device_id: 788dbd5e56d29b9d3b319344df389458
          - service: light.turn_on
            data: {}
            target:
              device_id: c733add90279c54c552b40d5ffbd016d
    default: []
  - condition: and
    conditions:
      - type: is_motion
        condition: device
        device_id: 53b255e469a65751ad0ada6661b76198
        entity_id: binary_sensor.presence_42
        domain: binary_sensor
        for:
          hours: 0
          minutes: 5
          seconds: 0
      - condition: device
        device_id: 06c3a968a177cfaacf95843823bf7f5e
        domain: media_player
        entity_id: media_player.fire_tv_192_168_0_42
        type: is_off
  - service: androidtv.adb_command
    data:
      command: POWER
    target:
      device_id: 06c3a968a177cfaacf95843823bf7f5e
  - delay:
      hours: 0
      minutes: 0
      seconds: 4
      milliseconds: 0
  - service: androidtv.adb_command
    data:
      command: CENTER
    target:
      device_id: 06c3a968a177cfaacf95843823bf7f5e
  - delay:
      hours: 0
      minutes: 0
      seconds: 2
      milliseconds: 0
  - service: media_player.select_source
    data:
      source: Plex
    target:
      device_id:
        - 06c3a968a177cfaacf95843823bf7f5e
mode: single

greets

It seems like you are using a Condition action where you should be using either a Wait action or a second trigger.

Also, you have an error in you Choose action, you need an Or:

  - choose:
      - conditions:
          - condition: or
            conditions:
              - condition: sun
                after: sunset
              - condition: sun
                before: sunrise

you are right, the sunset error is gone.

for my understanding, is it possible for example in a Trigger to define a time for it?

platform: state
entity_id: group.bewegungsmelder_sonoff_kueche_group
to: 'off'
for:
  hours: 0
  minutes: 5
  seconds: 0

waits he than 5 minutes until he starts the automation?
what happens when the 5 minutes not reached? stops he the automation ?

for example here

- conditions:
          - condition: and
            conditions:
              - condition: state
                entity_id: group.bewegungsmelder_sonoff_kueche_group
                state: 'on'
                for:
                  hours: 0
                  minutes: 2
                  seconds: 0
              - condition: device
                device_id: 06c3a968a177cfaacf95843823bf7f5e
                domain: media_player
                entity_id: media_player.fire_tv_192_168_0_42
                type: is_off

for me and my logic its better to use the the code above, but i mean that the automation fails then.

Yes, you can define a for time for certain types of triggers.

The trigger does not fire until the state requirement has been true for the set amount of time.

Nothing happens,the automation is not stopped, because it never started.

The automation is working exactly like it should for how you wrote it, you just don’t understand the difference between how triggers and conditions function in Home Assistant automations. Conditions look similar to triggers but are very different. A trigger will look at events happening in the system, while a condition only looks at how the system looks right now. A trigger can observe that a switch is being turned on. A condition can only see if a switch is currently ‘on’ or ‘off’.

alias: RAUM KÜCHE - Schalte alles wieder an bei Bewegung
description: ''
trigger:
  - platform: state
    id: initial_motion
    entity_id: group.bewegungsmelder_sonoff_kueche_group
    to: 'on'
    from: 'off'
  - platform: state
    id: 5_minutes
    entity_id: binary_sensor.presence_42
    to: 'on'
    from: 'off'
    for: '00:05:00'
condition: []
action:
  - choose:
      - conditions:
          - condition: trigger
            id: initial_motion
        sequence:
          - service: notify.mobile_app_iphone_von_marc
            data:
              message: BEWEGUNG ERKANNT, PERSON IN DER KÜCHE
          - condition: or
            conditions:
            - condition: sun
              before: sunrise
            - condition: sun
              after: sunset
          - service: switch.turn_on
            data: {}
            target:
              device_id: 788dbd5e56d29b9d3b319344df389458
          - service: light.turn_on
            data: {}
            target:
              device_id: c733add90279c54c552b40d5ffbd016d
      - conditions:
          - condition: trigger
            id: 5_minutes
        sequence:
          - condition: state
            entity_id: media_player.fire_tv_192_168_0_42
            state: 'off'
          - service: androidtv.adb_command
            data:
              command: POWER
            target:
              device_id: 06c3a968a177cfaacf95843823bf7f5e
          - delay: 4
          - service: androidtv.adb_command
            data:
              command: CENTER
            target:
              device_id: 06c3a968a177cfaacf95843823bf7f5e
          - delay: 2
          - service: media_player.select_source
            data:
              source: Plex
            target:
              device_id: 06c3a968a177cfaacf95843823bf7f5e
    default: []
mode: single