Wait 15 mins to turn off lights based on multiple motion sensors

I am new with HA. I have in the office 3 motion sensors, one at the door and one on each desk (my wife and myself). I want to wait until the three motion sensors have not detected motion for at least 15 mins each.
So far this is what I have:

alias: Office Off
description: ''
trigger:
  - type: no_motion
    platform: device
    device_id: device1
    entity_id: binary_sensor.lk_zb_motionsensor_d0003_ias_zone
    domain: binary_sensor
    for:
      hours: 0
      minutes: 15
      seconds: 0
      milliseconds: 0
  - type: no_motion
    platform: device
    device_id: device2
    entity_id: binary_sensor.lk_zb_motionsensor_d0003_ad2dcffe_ias_zone
    domain: binary_sensor
    for:
      hours: 0
      minutes: 15
      seconds: 0
      milliseconds: 0
  - type: not_occupied
    platform: device
    device_id: device3
    entity_id: binary_sensor.philips_sml001_10f11609_occupancy
    domain: binary_sensor
    for:
      hours: 0
      minutes: 15
      seconds: 0
      milliseconds: 0
condition:
  - type: is_no_motion
    condition: device
    device_id: device1
    entity_id: binary_sensor.lk_zb_motionsensor_d0003_ad2dcffe_ias_zone
    domain: binary_sensor
    for:
      hours: 0
      minutes: 0
      seconds: 0
      milliseconds: 0
  - type: is_no_motion
    condition: device
    device_id: device2
    entity_id: binary_sensor.lk_zb_motionsensor_d0003_ias_zone
    domain: binary_sensor
    for:
      hours: 0
      minutes: 0
      seconds: 0
      milliseconds: 0
  - type: is_not_occupied
    condition: device
    device_id: device3
    entity_id: binary_sensor.philips_sml001_10f11609_occupancy
    domain: binary_sensor
action:
  - type: turn_off
    device_id: my_switch
    entity_id: switch.office_light
    domain: switch
mode: single

But if one sensor has not detected motion for at least 15 mins and the others just stopped detecting motion (just a few seconds) the action will be triggered. I understand that based on my automation that is the correct result, but I want to know how to wait to at least 15 mins on every sensor.

See my code here -
Turn on light, switch, scene, script or group based on motion and illuminance (+ more conditions) - Blueprints Exchange - Home Assistant Community (home-assistant.io)

Just a suggestion, if you have multiple motion sensor in one room, it’s better to combine it using group-

group:
  office_presence:
    name: Office Presence
    entities:
      - binary_sensor.lk_zb_motionsensor_d0003_ias_zone
      - binary_sensor.lk_zb_motionsensor_d0003_ad2dcffe_ias_zone
      - binary_sensor.philips_sml001_10f11609_occupancy

By using group, if one of the entities inside the group is ON, the group state will be ON. If all entities are OFF, the group state will be OFF.

Next, use the group as a trigger in your automation-

trigger:
  - platform: state
    entity_id: group.office_presence
    to: 'off'
    for: '00:15:00'
condition: []
action:
  - service: switch.turn_off
    target:
      entity_id: switch.office_light
7 Likes

Thank you for your answer. The problem with the group is the same that I currently have. If one sensor has been 15 mins with no motion and for a couple of seconds the other two stop having motion, then the pre-requisites are met to turn off the light. What I want to do is to wait 15 mins for the last one who detected motion.

By grouping the sensors, the automation will be triggered 15 minutes after the last sensor stopped detecting motion.

As I mentioned previously, the group state will be OFF only when all sensors in the group are OFF.

I get it now, I will try this. Thank you for the follow up

That is the right answer. I made it work with a timer but this is a beautiful solution. Thank you