Having a weird problem with a light automation. Everything works fine except there is a condition right at the end of the code for a light to only turn off once a sensor has detected no movement for 5 minutes.
But according to my logs the automation ignores this 5 minute condition and turns the light on but then off immediately afterwards. I hope the comments in the code make sense. Apologies this automation is perhaps a bit too complicated and I may have made a logic error somewhere. Grateful for any pointers!
id: '1630278597828'
alias: living room lights
description: ''
trigger:
#start the automation when movement is detected in room
- type: occupied
platform: device
device_id: 1069a605af077ab7fe03158f91e57c33
entity_id: binary_sensor.philips_sml001_a32fb404_occupancy
domain: binary_sensor
#condition - only if illumination sensor says its dark
condition:
- type: is_illuminance
condition: device
device_id: 1069a605af077ab7fe03158f91e57c33
entity_id: sensor.philips_sml001_a32fb404_illuminance
domain: sensor
below: 7
#and dont turn on the light if we are watching a movie on plex - so need both plex sensors to be NOT playing
- condition: not
conditions:
- condition: state
entity_id: media_player.plex_plex_for_xbox_xboxone
state: playing
- condition: state
entity_id: media_player.plex_plex_htpc_for_windows_bigbox
state: playing
#if conditions met, turn the nightlight on if its after 11pm and before 6am. If its outside those times turn on the living room lamp and another light called "space TV"
action:
- if:
- condition: time
after: '23:00:00'
before: 06:30:00
then:
- service: light.turn_on
data: {}
target:
entity_id: light.yeelight_ceiling18_0x10d694c7_nightlight
else:
- service: light.turn_on
data: {}
target:
entity_id: light.livingroomlamp
- service: switch.turn_on
data: {}
target:
entity_id: switch.space_tv
#now we want to set conditions for when the lights will be turned off. Wait for the sensor to detect no movement for 5 minutes
- wait_for_trigger:
- type: not_occupied
platform: device
device_id: 1069a605af077ab7fe03158f91e57c33
entity_id: 6a285f4d7010e442ed2a67fb799712f5
domain: binary_sensor
for:
hours: 0
minutes: 5
seconds: 0
timeout:
hours: 0
minutes: 0
seconds: 0
milliseconds: 0
#but the motion sensor is unreliable - if someone is sitting down watching TV they probably arent moving much so the sensor will change its state to no movement after a few minutes - But we dont want the light to go off if someone is still in the room, so this condition checks to see if the TV is turned on (which would indicate someone is still in the room). If it is - then dont turn off the light. Otherwise, turn it off.
- condition: not
conditions:
- condition: state
entity_id: media_player.denon_avr_x2200w
state: 'on'
- service: light.turn_off
data: {}
target:
entity_id:
- light.yeelight_ceiling18_0x10d694c7_nightlight
- light.livingroomlamp
mode: restart