I am playing around with lights automation at the moment, and stumbled upon the same issue. My setup is an Aeotec Multisensor 6 with Hue lights in the living room.
I solved the issue of lights turning off after the set amount of time despite there is motion with a condition that does an additional check: if the motion sensor is not in ‘no motion’ state then restart the timer, and only turn off the lights when the motion sensor is actually in ‘no motion’ state.
In addition I noticed that when I watch TV in the evening I am often not moving for some time and the lights turn off - I solved this issue in a similar way as described above by checking if the TV is still turned on or Plex (on the TV) is currently playing.
Here’s my current configuration:
automation:
alias: "Turn on living room lights when there is movement"
trigger:
- platform: state
entity_id: sensor.aeotec_zw100_multisensor_6_burglar_2
to: '8'
condition:
- condition: state
entity_id: sun.sun
state: 'below_horizon'
action:
service: homeassistant.turn_on
entity_id: script.timed_lamp
script:
timed_lamp:
alias: "Turn on lamp and set timer"
sequence:
# Cancel ev. old timers
- service: script.turn_off
data:
entity_id: script.timer_off
- service: light.turn_on
data:
entity_id: group.living_room
# Set new timer
- service: script.turn_on
data:
entity_id: script.timer_off
timer_off:
alias: "Turn off lamp after 15 minutes"
sequence:
- delay:
minutes: 15
- service_template: >
{% if ((not is_state('sensor.aeotec_zw100_multisensor_6_burglar_2', '0')) or (is_state('media_player.living_room_tv', 'on')) or (is_state('media_player.my_bravia_2015', 'playing'))) %}
script.turn_on
{% else %}
light.turn_off
{% endif %}
data_template:
entity_id: >
{% if ((not is_state('sensor.aeotec_zw100_multisensor_6_burglar_2', '0')) or (is_state('media_player.living_room_tv', 'on')) or (is_state('media_player.my_bravia_2015', 'playing'))) %}
script.timer_off_restart
{% else %}
group.living_room
{% endif %}
timer_off_restart:
alias: "Turn off lamp after 15 minutes (restart)"
sequence:
# Cancel current script
- service: script.turn_off
data:
entity_id: script.timer_off
# Set new timer
- service: script.turn_on
data:
entity_id: script.timer_off
The if-statements are quite complicated, and I’m not sure if there’s a simpler way to do this. The restart script was necessary as apparently you can’t cancel and then restart a script from within itself.
Issues remaining:
- My automation only kicks in after sunset. However, if there is motion before sunset and continues to be, then the automation is never triggered because the sensor never changes its state. To solve this a separate automation triggered at sunset itself may be required.
- When I get up before sunrise and trigger the automation so the lights turn on, as long as there’s still motion even after sunrise, the lights will never turn off. To solve this another condition may be required in the if-statements to check if the sun has risen.
Happy to hear about any suggestions for improving the code. It’s already getting quite longish for a single automation.