Hello all!
I have just finished setting up my first Zigbee network and I have added a couple of motion sensors from Aqara to it. I also have some Sonoff switches that are flashed with Tasmota that I want to control with the motion sensors.
Now I am currently trying to create just a single automation that turns on and off the switches based on some triggers. My issue is that I would like to differentiate between when the switch was turned on manually or via the motion sensor. My goal is to add a delay when the switch was manually activated and to turn off the light 10 minutes later if no motion was detected at that point.
I am pretty new at this and I would really appreciate your help.
My current code:
alias: Kitchen Lights - Sensor Automation
description: ''
trigger:
- type: motion
platform: device
device_id: 73f5a8ea469412fa63612b051aaa75e4
entity_id: binary_sensor.kitchen_motion_sensor_occupancy
domain: binary_sensor
id: kitchen_motion_detected
- type: no_motion
platform: device
device_id: 73f5a8ea469412fa63612b051aaa75e4
entity_id: binary_sensor.kitchen_motion_sensor_occupancy
domain: binary_sensor
id: kitchen_motion_not_detected
- platform: device
type: turned_on
device_id: 6bc73152ef02b50ac1bf9a444145cb77
entity_id: light.kitchen_lights_right_side
domain: light
id: kitchen_lights_right_turned_on
- platform: device
type: turned_on
device_id: 6bc73152ef02b50ac1bf9a444145cb77
entity_id: light.kitchen_lights_left_side
domain: light
id: kitchen_lights_left_turned_on
condition:
- condition: and
conditions:
- type: is_illuminance
condition: device
device_id: 73f5a8ea469412fa63612b051aaa75e4
entity_id: sensor.kitchen_motion_sensor_illuminance_lux
domain: sensor
below: 30
action:
- choose:
- conditions:
- condition: time
before: '22:00:00'
after: '10:00:00'
- condition: trigger
id: kitchen_motion_detected
sequence:
- type: turn_on
device_id: 6bc73152ef02b50ac1bf9a444145cb77
entity_id: light.kitchen_lights_right_side
domain: light
- type: turn_on
device_id: 6bc73152ef02b50ac1bf9a444145cb77
entity_id: light.kitchen_lights_left_side
domain: light
- conditions:
- condition: time
after: '22:00:00'
before: '10:00:00'
- condition: trigger
id: kitchen_motion_detected
sequence:
- type: turn_on
device_id: 6bc73152ef02b50ac1bf9a444145cb77
entity_id: light.kitchen_lights_left_side
domain: light
- conditions:
- condition: trigger
id: kitchen_motion_not_detected
sequence:
- type: turn_off
device_id: 6bc73152ef02b50ac1bf9a444145cb77
entity_id: light.kitchen_lights_right_side
domain: light
- type: turn_off
device_id: 6bc73152ef02b50ac1bf9a444145cb77
entity_id: light.kitchen_lights_left_side
domain: light
- conditions:
- condition: or
conditions:
- condition: trigger
id: kitchen_lights_left_turned_on
- condition: trigger
id: kitchen_lights_right_turned_on
- type: is_no_motion
condition: device
device_id: 73f5a8ea469412fa63612b051aaa75e4
entity_id: binary_sensor.kitchen_motion_sensor_occupancy
domain: binary_sensor
sequence:
- delay:
hours: 0
minutes: 10
seconds: 0
milliseconds: 0
- type: turn_off
device_id: 6bc73152ef02b50ac1bf9a444145cb77
entity_id: light.kitchen_lights_right_side
domain: light
- type: turn_off
device_id: 6bc73152ef02b50ac1bf9a444145cb77
entity_id: light.kitchen_lights_left_side
domain: light
default: []
mode: single