I’m pulling my hair out trying to figure out the issue here. I have the below two automations for turning on and off my kitchen lights. The lights turn on in the first instance, then turn off as expected if no motion sensed within 1 minute. However, the lights won’t turn on again if the motion sensor is re-triggered within about 5-10 seconds after the lights turning off. After that they will turn on.
I’ve tried changing the light effect call to just kelvin and calling scripts but it’s the same each time.
They are Philips Wiz bulbs connected to a Sonoff light switch, set to always on.
Can anyone see an issue with either the turn on or turn off automation that would cause this behaviour? Or could it be device specific?
- alias: Kitchen Ceiling Lights On Motion
id: kitchen_ceiling_lights_on_motion
mode: single
trigger:
- platform: state
entity_id: binary_sensor.kitchen_motion_sensor_motion
to: 'on'
condition:
- condition: template
value_template: "{{ states('binary_sensor.kitchen_motion_sensor_motion') not in ['unknown', 'unavailable'] }}"
- condition: template
value_template: "{{ states('sensor.kitchen_motion_sensor_illuminance')|float(100) < 12 }}"
action:
- choose:
- conditions:
- condition: time
after: '05:00:01'
before: '07:30:00'
sequence:
- service: light.turn_on
target:
entity_id: light.kitchen_ceiling_lights
data:
effect: "Warm white"
- conditions:
- condition: time
after: '07:30:01'
before: '23:00:00'
sequence:
- service: light.turn_on
target:
entity_id: light.kitchen_ceiling_lights
data:
effect: "Golden white"
- conditions:
- condition: or
conditions:
- condition: time
after: '23:00:01'
- condition: time
before: '05:00:00'
sequence:
- service: light.turn_on
target:
entity_id: light.kitchen_ceiling_lights
data:
effect: "Night light"
Some motion sensors won’t detect motion again for a while after they stop detecting motion. Does the history of the sensor show that it was detected within the 15 seconds after it cleared?
Yes, I’ve created a card in a dashboard with just the relevant entities and I can see that all entities are on/off as expected. The Hue motion sensor takes just around 3 seconds to clear after I have left the room but no more than that.
- alias: Kitchen Ceiling Lights Off Motion
id: kitchen_ceiling_lights_off_motion
mode: single
trigger:
platform: state
entity_id: binary_sensor.kitchen_motion_sensor_motion
to: 'off'
for:
minutes: 1
action:
- service: light.turn_off
target:
entity_id: light.kitchen_ceiling_lights
I’ve checked traces for when it fails to re-turn on the lights and get the below:
*EDIT: I tried commenting out the value_template: "{{ trigger.from_state.state not in ['unknown', 'unavailable'] }}" but it still failed. So it must relate to the only other global condition which is illuminance level. Maybe that’s not updating quickly enough??
This approach eliminates the inter-automation timing issues and the illuminance sensor lag problem since motion detection triggers immediately while illuminance only gates the turn-on logic.