I’ve been trying for a while to create an automation for turning a smart bulb (Tapo) on/off based on motion detected by a sensor (Ikea Zigbee motion sensor).
What do I want to achieve? I want to turn on the light (in the bathroom) between 7 PM and 12 AM at a brightness of 70%, and between 12 AM and 7 AM at a brightness of 10%, when the motion sensor detects presence. After detecting motion, the light should turn on for 2 minutes and then turn off.
I tried the following automation, but it doesn’t work correctly… and it doesn’t turn off the light after 2 minutes; it stays on continuously.
alias: Bathroom_NightMode
description: ""
trigger:
- type: motion
platform: device
device_id: b345fwf0745rt1345853e7f43f4e605
entity_id: binary_sensor.ikea_motion_sensor_occupancy
domain: binary_sensor
condition: []
action:
- if:
- type: is_motion
condition: device
device_id: b345fwf0745rt1345853e7f43f4e605
entity_id: binary_sensor.ikea_motion_sensor_occupancy
domain: binary_sensor
- condition: time
before: "07:00:00"
after: "00:00:00"
then:
- service: light.turn_on
data:
brightness_pct: 10
target:
entity_id: light.bathroom
- delay: "00:02:00"
- if:
- type: is_motion
condition: device
device_id: b345fwf0745rt1345853e7f43f4e605
entity_id: binary_sensor.ikea_motion_sensor_occupancy
domain: binary_sensor
- condition: time
before: "00:00:00"
after: "19:00:00"
then:
- service: light.turn_on
data:
brightness_pct: 70
target:
entity_id: light.bathroom
- delay: "00:02:00"
mode: single
What’s wrong in this code and how can i fix it to work accordingly to my request?
Thank you all!