Sunrise trigger conditional on time of day

Hi hope someone can help. I like my outside lights to come on in winter in the morning before sunrise as it’s normal to be up and about from 6.30 AM. A simple sunrise trigger with a negative offset works in winter but in summer I don’t want the lights coming on at 4AM!

I would like the lights to only come on if the time of day is after 6.30 and the sun has not risen. Any ideas how I can do this please as the UI options don’t seem to cut it!

Code looks like this currently:

alias: String lights on morning
  description: ''
  trigger:
  - platform: sun
    event: sunrise
    offset: '-10'
  condition:
  - condition: sun
    before: sunrise
  action:
  - service: light.turn_on
    target:
      entity_id: light.patio_string_lights
  - service: switch.turn_on
    target:
      entity_id: switch.dining_patio_socket
  mode: single

Thanks!

It seems odd to me to turn the lights on based on the sunrise; the lights would never turn on at a consistent time. Also, currently, your condition will always be true since the trigger is based on a sunrise offset…

I’d recommend a very similar automation, but based on time:

alias: String lights on morning
  description: ''
  trigger:
  - platform: time
    at: "6:30:00"
  condition:
  - condition: sun
    before: sunrise
  action:
  - service: homeassistant.turn_on
    target:
      entity_id:
        - light.patio_string_lights
        - switch.dining_patio_socket
  mode: single
3 Likes

Thank you I will give this a try. I need to spend some more time studying Python.

More Python knowledge wouldn’t help you here; this is all Home Assistant. All the information you need for stuff like this can be found in the docs. For example, here is all the information you need on triggers:

And remember to keep it simple. Just think about what you want, and try to get there in as few steps as possible. Taking the case you presented in this topic, “if it is 630am, but the sun isn’t up, turn on the porch lights.” It can be broken down like so:

Trigger: It is 6:30am
Condition: The sun is not up
Action: Turn on the porch lights

Then you can build the automation piece by piece, with a goal in mind for each piece.

1 Like

you should put both of those conditions as both as triggers and conditions in your automation:

alias: String lights on morning
  description: ''
  trigger:
  - platform: sun
    event: sunrise
  - platform: time
    at: '06:30:00'
  condition:
  - condition: sun
    before: sunrise
  - condition: time
    after: '06:30:00'
  action:
  - service: light.turn_on
    target:
      entity_id: light.patio_string_lights
  - service: switch.turn_on
    target:
      entity_id: switch.dining_patio_socket
  mode: single

the above will turn on the lights at sunrise if it is after 0630 or at 0630 if the sun hasn’t risen by then.

I’m not sure how you are figuring the offset from sunrise since I’ve never seen the offset written like that (not that I use many sunrise offsets tho) so I removed it from the example above.

but however you think it might work you need to add the offset to both sunrise condition and trigger. Or you may decide you don’t need it.

and I’m not sure how you are using the “at sunrise” trigger but the condition is “before sunrise”? I left it in for illustrative purposes but I don’t think that logic will work.

I think you should just trigger at 0630 and make before sunrise a condition. but I may be missing something.

This just seems like a long-winded way of recommending the approach I already did… :slight_smile: Am I just missing the distinction?

Only if I actually am missing something. If I’m not missing something then you are correct.

But I also wanted to show what could be done in case I am.

so the answer is…maybe… :wink:

1 Like