I am looking for some help resolving what should be a basic automation. I have a Tuya Zigbee Motion detector 809WZT which automatically changes state from Detected to Clear in approximately 60 seconds and a Sonoff ZBMiniL2 relay attached to the bathroom lights.
I want to acheive an automation that turns on the lights when occupancy is detected and remains on whilst occupancy is detected but turns off after 3 minutes if occupancy is not detected.
This was my original Yaml produced by using the inbuilt blueprint
alias: Bathroom Lights On
description: ""
triggers:
- type: occupied
device_id: d59c8588c114dce804f413049d024d3a
entity_id: 108364784b86112474088a686516c96c
domain: binary_sensor
metadata:
secondary: false
trigger: device
conditions: []
actions:
- type: turn_on
device_id: 0c6e1bd79db5e318cee1aba462b54f0d
entity_id: 921d8b547f88b0bc8cf1a43bb38d97e3
domain: switch
mode: single
This turns the lights on but not off again after a set time.
I searched these forums and the internet and found some examples and ended up with this Yaml file
alias: Bathroom Lights Occupancy
triggers:
- entity_id: binary_sensor.bathroom_pir_occupancy
to: "on"
trigger: state
- entity_id: binary_sensor.bathroom_pir_occupancy
to: "off"
for: "00:03:00"
trigger: state
actions:
- choose:
- conditions:
- condition: state
entity_id: binary_sensor.bathroom_pir_occupancy
state: "on"
sequence:
- target:
entity_id: switch.bathroom_lights
action: light.turn_on
- conditions:
- condition: state
entity_id: binary_sensor.bathroom_pir_occupancy
state: "off"
sequence:
- target:
entity_id: switch.bathroom_lights
action: light.turn_off
mode: restart
I had to change the entity IDs to match my devices (as flagged by Spook) but it doesn’t work in that even though the PIR identifies occupancy, it now does not trigger the switch. If it assists here is the Traces log
this:
entity_id: automation.bathroom_lights_on
state: 'on'
attributes:
id: '1768217802807'
last_triggered: '2026-01-12T13:01:10.888434+00:00'
mode: restart
current: 0
friendly_name: Bathroom Lights Occupancy
last_changed: '2026-01-12T12:30:22.730335+00:00'
last_reported: '2026-01-12T13:01:10.897718+00:00'
last_updated: '2026-01-12T13:01:10.897718+00:00'
context:
id: 01KES4QKB7G0S5EECZNGMKMX96
parent_id: 01KES4QKAZ9B1Z0D359AETZHRR
user_id: null
trigger:
id: '1'
idx: '1'
alias: null
platform: state
entity_id: binary_sensor.bathroom_pir_occupancy
from_state:
entity_id: binary_sensor.bathroom_pir_occupancy
state: 'on'
attributes:
device_class: occupancy
friendly_name: Bathroom PIR Occupancy
last_changed: '2026-01-12T13:01:10.879325+00:00'
last_reported: '2026-01-12T13:01:10.879325+00:00'
last_updated: '2026-01-12T13:01:10.879325+00:00'
context:
id: 01KES4QKAZ9B1Z0D359AETZHRR
parent_id: null
user_id: null
to_state:
entity_id: binary_sensor.bathroom_pir_occupancy
state: 'off'
attributes:
device_class: occupancy
friendly_name: Bathroom PIR Occupancy
last_changed: '2026-01-12T13:02:12.154571+00:00'
last_reported: '2026-01-12T13:02:12.154571+00:00'
last_updated: '2026-01-12T13:02:12.154571+00:00'
context:
id: 01KES4SF5T092RDBA3PXCY2ZYH
parent_id: null
user_id: null
for:
__type: <class 'datetime.timedelta'>
total_seconds: 180
attribute: null
description: state of binary_sensor.bathroom_pir_occupancy
Can anyone see what the issue is. Spook identified missing entities and I realised that the entity was not a light but a switch which I corrected but perhaps there are still errors?.