New to Home Assistant (migrating from SmartThings) and I’m just setting up my devices.
I want my Lounge Lights to turn on when there is motion detected via my sensor and turn off if no motion has been detected for 25 minutes, and I have successfully configured this automation.
What I’m struggling with is I only want the lights to come on when there is motion 90 minutes before sunset through to 60 minutes after sunrise.
There’s a condition regarding Sunrise / Sunset times, but I’ve tried a few combinations and cannot get it to work.
Please can someone describe/show me how I should be setting this up (not in code please)? Can I do it in one automation or do I need one for sunset and another automation for sunrise?
Yes, the “before offset” label could make you think that the offset will be negative by itself, but it is not.
I just did a quick test on my system and it works fine.
Not to confuse you, but you might consider working with the sun elevation instead than a fixed offset from sunset.
Depending on the seasons, a 1h offset might be too much or too little.
See the note regarding sun triggers below, that applies to conditions as well ofc.
Thanks for posting this. I was wondering how 2 triggers (sunset/sunrise or sunset/set time) would work.
If you don’t have the motion trigger, will a sunset -00:20 and a set time of 12:15am cause the light to automatically turn off at 12:15, or do you need a separate automation to have it turn off?
Most motion sensors also have an ambient light sensor. I use that instead of sunrise/sunset because of “dark and stormy days” and such. If that makes sense in your environment, here’s a automation I use:
(btw; I’m using a group of motion sensors, just replace the group with an individual binary sensor entity if needed)
#######################################
# Breezeway lights on motion detection
# if motion sensed turn on light
# turn off after 4 minutes
# (2 minute sensor, 2 minute timer)
#-|---|---|---|---|---|---|---|---|---|
- id: 'breezeway_lights_on_motion'
alias: 'Breezeway lights on motion'
trigger:
platform: state
entity_id: group.back_porch_motion
to: 'on'
condition:
condition: numeric_state
entity_id: sensor.breezeway_motion_illuminance
below: 110
action:
service: light.turn_on
entity_id: light.breezeway_lights_zha_group_0x000c
- id: 'breezeway_lights_off_delay'
alias: 'Breezeway lights off delay'
trigger:
platform: state
entity_id: group.back_porch_motion
to: 'off'
for:
minutes: 2
action:
service: light.turn_off
entity_id: light.breezeway_lights_zha_group_0x000c
Well I put the condition in exactly as pictured but the lights never came on when there was motion. I take the condition out and they came on (but obviously now they are coming on all throughout the day).
No idea if my sensors detect ambient light? Would be useful if they did. They are Samsung Smartthings sensors.
Ok, so here is my automations (one for on, one for off) as it stands:
If I add in the condition:
the lights don’t come on.
What am I doing wrong? At the moment I have to disable the automation to turn the lights on at mid-morning and re-enable it in the evening when it gets dark. I have similar automations setup for each room too. This is not home automation!
Have you used the “debug” functionality of the automation?
You can see there what happened with the conditions when the automation was triggered and then understand what is going wrong.
It is the button beside the “edit automation”.
I think the problem was that if you put your 2 conditions in a single Sun condition, it will never happen that both are met. It will be early in the morning OR late at evening,but not both at the same time.
With this OR aproach, it should work!