I’ve been using Home Assistant for a couple of months now, and love it. I’ve written several automations, but I need some help with this one. I’ve been puzzling over this, looking at all kinds of automation examples with time and sunset, and I can’t figure out how to make this work. I want to turn a light on when a motion detector triggers, but only between sunset and 10pm. This is where I am so far:
- alias: Turn on light when motion between sunset and 10pm
trigger:
platform: state
entity_id: sensor.motion_sensor
to: 'motion detected'
condition:
condition: and
conditions:
- condition: state
entity_id: sun.sun
state: 'below_horizon'
- condition: time
before: '22:00:00'
action:
service: light.turn_on
entity_id: light.my_light
data:
brightness: 120
It partially works…The problem is that after midnight, when the day changes, the conditions become true again (until sunrise). I do not want the light to turn on between midnight and sunrise. I’m probably missing something obvious, but if someone could help I’d really appreciate it. Thanks in advance!
I would just like to warm this up, because for me this is not working. What am I doing wrong? My goal is to only trigger the action in case it is in between 30 mins before sunset and before 22:00:00 in the evening.
Specifying ‘after sunset’ and setting a negative offset works pretty nice in another Automation. But combined in this case, the Automation cannot be set up. I also tried it without the inner ‘and’ condition, so just adding those conditions next to the other ones, but it does not work.
In case I remove one of both conditions, it works nicely again. So it seems they are somehow conflicting. When I say ‘before 01:00’ it works again, so it might be something because of midnight, but I don’t know what it is.
Don’t know why, but after restarting HA it works. Reloading simply didn’t work, so maybe there was an internal hickup. The typical ‘Have you tried turning it off and on again’ worked.