Multiple sensors multiple lights

Hi there, I wonder how to make an automation(s) that control my lights outside. I have some sensors that I want to control multiple lights but also the same lights. Here I have arranged all the sensors and the lights I want them to turn on: (Sorry for my poor naming convention!)

#Frontdoor
Sensor: xiaomi_sensor_frontdoor_ias_zone
Lights:	eWeLight1

#Backdoor
Sensor: sonoff_sensor1_ias_zone
Lights:	eWeLight1
		ikea_light1
		sonoff_relay1_on_off

#Behind house
Sensor: sonoff_sensor2_ias_zone
Lights:	ikea_light1
		sonoff_relay1_on_off

#Patio
Sensor: xiaomi_sensor_ude_ias_zone
Lights:	xiaomi_light
		eWeLight2

#Shed
Sensor: sonoff_sensor3_ias_zone
Lights:	eWeLight2

It’s probably most the “turn off” part that I cannot figure out. Whenever there isn’t movement, I want a 120 seconds delay and then the lights should turn off.

If I walk from the frontdoor to backdoor and then behind house then I want the ikea_light1 and the sonoff_relay1_on_off to stay on because I just triggered the behind house sensor, but the ewelight1 should turn off following the 120 seconds rule because it belongs to the frontdoor.

I hope it makes sense and someone can help me :slight_smile:

1 Like

Alright I think I’ve figured out a solution. I will try to explain it here to help others - take this as some sort of a guide and not a directly answer to my own problem…

Here we go …

First we need a timer for each light - so 1 to 1 relation between lights and timers:

timer:
  light1:
    duration: "00:02:00"
  light2:
    duration: "00:02:00"

Then I’ll suggest a light group whenever multiple lights has to be turned on at the same time - the reason I do this is that I could not make the service: light.turn_on accept multiple input’s:

#Light groups
light:
  - platform: group
    name: group1
    entities:
      - light.light1
      - light.light2

Next we need an automation that will 1. turn one or more lights on and start/restart one or more timers.

alias: MotionAndLight
trigger:
  - platform: state
    entity_id: binary_sensor.sensor1
    to: 'on'
  - platform: state
    entity_id: binary_sensor.sensor2
    to: 'on'
action:
  - service: timer.start
    target:
      entity_id: >-
        {% if trigger.entity_id == 'binary_sensor.sensor1' %}
          timer.light1
        {% elif trigger.entity_id == 'binary_sensor.sensor2' %}
          timer.light1, timer.light2
        {% endif %}
  - service: light.turn_on
    target:
      entity_id: >-
        {% if trigger.entity_id == 'binary_sensor.sensor1' %}
          light.light1
        {% elif trigger.entity_id == 'binary_sensor.sensor2' %}
          light.group1
        {% endif %}
mode: queued
max: 10

Here sensor1 should turn light1 on, and sensor2 should turn both light1 and light2 on. If light1 is already turned on, then the timer.start should restart light1’s timer whenever sensor1 or sensor2 is triggered.

Now we have to make an automation that turns off the light again whenever a timer is done counting down.

alias: TimerEndTurnoffLight
trigger:
  - platform: event
    event_type: timer.finished
condition: []
action:
  - service: light.turn_off
    target:
      entity_id: |-
        {% if trigger.event.data.entity_id == 'timer.light1' %}
          light.light1
        {% elif trigger.event.data.entity_id == 'timer.light2' %}
          light.light2
        {% endif %}
mode: queued
max: 10

I’ve corrected all configuration to make is more understandable . Therefore it can contain some mistakes. I hope this is helpful for someone .

1 Like

I don’t know if it’s your breakdown, or it all just finally fell into place, but I’ve been struggling with this for a bit and after reading this, I get it now.
Thanks!!

1 Like

I’m glad to hear it helped you! :slight_smile: