Condition Stop a Motion Sensor for 10 minutes

Dear all,
I have an automation that turn on a light when a motion sensor detect a presence.
I would like that this automation run one time and the for 10 minute stay off.

I have this automation:

- alias: "Movimento Bagno"
  trigger:
    platform: state
    entity_id: binary_sensor.motion_bagno_occupancy
    to: 'on'

  condition:
    condition: or
    conditions:
    - condition: template
      value_template: >
        {{ now().strftime("%H:%M:%S") > states.input_datetime.accensione_movimento_notte.state }}
    - condition: template
      value_template: >
        {{ now().strftime("%H:%M:%S") < states.input_datetime.spegnimento_movimento_notte.state }}


  action:
    - service: switch.turn_on
      data:
        entity_id: switch.shelly1_specchio

For set a condition that avoid a start for 10 minutes, I must to add this code?

- condition: template
        value_template: "{{ (as_timestamp(now())-as_timestamp(states.switch.shelly1_specchio.last_changed)) > 600 }}"

It’s right?

You should have a look at run modes

When this automation is triggered it turns on the switch and then waits for 10 minutes. If it is triggered again during the 10-minute delay, it will silently ignore the trigger.

- alias: "Movimento Bagno"
  mode: single
  max_exceeded: silent
  trigger:
  - platform: state
    entity_id: binary_sensor.motion_bagno_occupancy
    to: 'on'
  condition:
  - condition: template
    value_template: >
      {% set t = now().strftime("%H:%M:%S") %}
      {{ t > states('input_datetime.accensione_movimento_notte') or
         t < states('input_datetime.spegnimento_movimento_notte') }}
  action:
  - service: switch.turn_on
    data:
      entity_id: switch.shelly1_specchio
  - delay: '00:10:00'
3 Likes

I am using the same method as 123 for multiple types of events where triggers may occur multiple times during a period after the first trigger but only 1 automation run is desired

I try this one and come back with the results.
Thank you

I’ve try this solution.
First of all, thank you for your work and for the new code about “condition”, very smart.

The automation work but it’s strange.
When I walk in front of the sensor, for the second time, the light does not turn on but the timer restart so if I walk continuosly the light does not turn on also for 1h.

I believe what you are calling the “timer” is the delay statement. It will not restart until it finishes its countdown and another trigger occurs. That’s how mode: single works.

I’m not sure why it is behaving the way you described.

Yes, you are right.
The delay seems to restart when I pass in front of the motion sensor.
Very strange

The sensor is a motion sensor Ikea used with a zigbee dongle and zigbee2mqtt