Sunset & Sunrise Config?

Hi.

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?

This should work:

Thanks - maybe it was the “-” before 01:30:00 I was missing. Will give it a whirl - thanks for the reply

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.

Let us know! and welcome to the community!

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?

1 Like

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.

In your Integrations menu, Zigbee Integrations, bring up your motion sensor device. You should see something like this:


Click on the illuminance icon (if you have one) and see what that attribute is named.

No, I don’t appear to have that option…

Ok, so here is my automations (one for on, one for off) as it stands:

If I add in the condition:

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!

Any help greatly appreciated.

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”.

The conditions make so that the automation only work during the day, and not in the evening, when I would assume it would be needed.

Is that intended?

If not, it should be After sunset and Before sunrise

1 Like

@koying you are correct!

@sobeitjedi sorry for the mistake.

Condition should be:
Before sunrise (offset 01:00:00)
After sunset (offset -01:30:00)

Tried this too, but still no joy.

Do I need to restart Home Assistant for automation to take effect?

What on earth am I doing wrong? This is very frustrating.

Does the automation trigger?
Did you check the debug functionality I mentioned above?

Thanks, not used the debug feature before so not entirely sure what to look for, but it does indicate it’s failing because of the condition (I think)…

Tap on the A/B of the diagram, then on the “step details” tab and post an screenshot.

Ok, as requested…

hmmm…
try splitting the conditions inside and OR block. Ensure both Sun conditions are inside the OR block. Like this:

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!

1 Like