Sunset offset depending on season (is it possible?)

I am curious if it is possible to have an sunset offset depending on season.
Since the light are longer between sunset and dusk during spring and summer.

This is what i tried with no luck:

- alias: 'Fönster efter skymning'
  initial_state: true
  - platform: sun
    event: sunset
      entity_id: >
       {% if {{ states.sensor.season = 'Vinter' }} %}
        offset: "-0:20:00"
       {% elif {{ states.sensor.season = 'Vår' }} %}
        offset: "-0:10:00"
       {% elif {{ states.sensor.season = 'Sommar' }} %}
        offset: "+0:10:00"
       {% elif {{ states.sensor.season = 'Höst' }} %}
        offset: "-0:10:00"
       {% endif %}
  - condition: state
    entity_id: group.all_devices
    state: home
  - condition: state
    entity_id: input_select.status_hemma
    state: 'Hemma'
  - service: switch.turn_on
      - switch.fonster_koket
  - service: scene.turn_on
    entity_id: scene.livingroom_dim
  - delay: 00:15:00
  - service: switch.turn_on
    entity_id: switch.bokhylla

What about using sun elevation. That adjusts with season

See. Next_dawn next_dusk in automation

1 Like

Sweet i will try that :crossed_fingers:
Is there a way to find out what time a certain elevation will be?

I use below -10 degrees from memory.

That is about 20-30 minutes before sunset

That time changes each day based upon the season etc.

1 Like

I’m pretty sure the ‘sun’ component adjusts the sunset attribute value to coincide with the actual sunset in your location. if it didn’t why call it “sunset”?

I use the sunset value for several of my automations and it reliably tracks the actual sunset throughout the year.

for example:

- id: deck_light_on_at_dusk
  alias: Deck Light On at Dusk
    platform: sun
    event: sunset
    service: homeassistant.turn_on
    entity_id: light.sengled_e11g13_03070a4c_1

That’s more or less what i had from the beginning.
But the light is stronger and longer between sunset and dusk during spring and summer then autumn and winter, at least in Sweden.


  value_template: '{{ state.attributes.elevation }}'
  below: -5.9

…is probably a value that works somewhere else (but not here).
Its currently -4.39 degrees and really dark :slight_smile:
I will try:

  value_template: '{{ state.attributes.elevation }}'
  below: 2.5
1 Like

This site might help to give you time and elevation.

I am having the same “problem”, but I am almost also in Sweden :slight_smile:

I used to have a 30 minute after sunset trigger on the outside lights, that used to be fine. But now there is too much light for having the need to turn on outside lights 30 minutes after sunset.

Will elevation solve that, because I suppose that also not account for the sun being stronger at certain periods?

Using the solution from @phileep did the trick :ok_hand:

This is what i am using:

  value_template: '{{ state.attributes.elevation }}'
  below: 2.5

What the value would be in Denmark is hard to say. But should be slightly higher i think depending on where in Denmark you live.
Find your spot on the map and scroll down to find the elevation on this site

1 Like

I guess I don’t understand the problem…

I think you are saying that the sun is stronger in the spring and summer so you want the lights to come on later (sun further below horizon) since you want it to be more dark when the lights come on.

but if you use the elevation above 0 degrees (2.5 in your example) then doesn’t that cause the light to come on when the sun is still up (sun still above horizon)?

from the docs a positive elevation means the sun is still above the horizon.


Seems like it differs depending on your location.
Look at the link i posted above and try different locations.

unless you are saying that sunset as shown by the sun component isn’t actually the sun being at an elevation of 0 degrees then I still don’t see it.

I understand that the angles are different for different times of day and times of year depending on your location (i.e. 10 am at the equator has a different solar angle than 10 am somewhere due north of that location) causing the elevation angle to change more or less for every given hour at those two locations but the sunset (and sunrise) should still be at 0 degrees as referenced to the horizon at EITHER of those two locations. and that means the when the sun is at its (solar) noon position the elevation of the sun is at 90 degrees above the horizon and lowers in either direction relative to the time before or after noon.

which means that a positive elevation angle would still have the sun above the horizon no matter where you are on earth.

i can see what you are saying if the issue is that twilight is longer in the northern latitudes during summer but having an automation using a positive elevation angle shouldn’t help that problem since the sun is still above the horizon at that angle and twilight isn’t even a phenomenon occurring at that point.

I assume it will be some trial and error but it worked yesterday :crossed_fingers:
So so far the is correct.

In 2019, which is better: time offset or elevation? Does offset adjust with season or not?

I want to turn on lights at dusk, and turn off at sunrise.

Offset does not adjust with season, it just adds or subtracts X minutes from time of sunset / sunrise.

The time of next dusk and sunrise are available from the sun component. Perhaps you can use those. Check the sun docs.