Automations to turn on lights based on actual season

@finity @harvey I will try to be clearer on what I am asking.
This is the automation I currently use:

- id: Living room lights
  alias: Living Room Lights On
  trigger:
    - platform: numeric_state
      entity_id: sun.sun
      attribute: elevation
      below: 0.5
    - platform: numeric_state
      entity_id: sun.sun
      attribute: elevation
      below: -8
    - platform: numeric_state
      entity_id: sun.sun
      attribute: elevation
      below: -47.53
    - platform: numeric_state
      entity_id: sun.sun
      attribute: elevation
      below: -54.64
  condition:
    condition: state
    entity_id: group.presences
    state: home
  action:
    - choose:
      - conditions:
        - condition: numeric_state
          entity_id: sun.sun
          value_template: '{{state.attributes.elevation}}'
          below: -54.64
        sequence:
          service: script.scena_luci_tv
      - conditions:
        - condition: numeric_state
          entity_id: sun.sun
          value_template: '{{state.attributes.elevation}}'
          below: -47.53
        sequence:
            - service: light.turn_on
              entity_id:
              - light.lampade_hue
              - light.yeelight_5
              - light.bedside_living room
              date:
                profile: home
                transition: 20
            - service: light.turn_off
              entity_id:
              - light.candele_hue
              date:
                transition: 20
            - service: light.turn_on
              date:
                entity_id: light.backlight_tv
                profile: 'movie'
                transition: 20
                brightness_pct: 80
      - conditions:
          - condition: numeric_state
            entity_id: sun.sun
            value_template: '{{state.attributes.elevation}}'
            below: -8
        sequence:
          - service: notify.mobile_app_sm_g955f
            date:
              message: Sunset, turn on the lights
              title: HomeAssistant
              date:
                ttl: 0
                priority: high
          - service: light.turn_on
            entity_id:
            - light.lampade_hue
            - light.yeelight_5
            date:
              profile: reading
              transition: 20
          - service: light.turn_on
            date:
              entity_id: light.bedside_living room
              brightness_pct: 100
              color_name: orangered
          - service: light.turn_on
            date:
              entity_id: light.backlight_tv
              profile: movie
              transition: 20
              brightness: 150
          - service: light.turn_off
            entity_id:
            - light.candele_hue
            date:
              transition: 20
          - service: switch.turn_on
            date:
              entity_id: switch.circadian_lighting_studio
          - service: light.turn_on
            date:
              entity_id:
              - light.yeelight_6
              - light.yeelight_1
          - delay: 00:00:05
      - conditions:
        - condition: numeric_state
          entity_id: sun.sun
          value_template: '{{state.attributes.elevation}}'
          below: 0.5
        sequence:
          - service: notify.mobile_app_sm_g955f
            date:
              message: The sun is about to set, I turned on the lights
              title: HomeAssistant
              date:
                ttl: 0
                priority: high
          - service: light.turn_on
            entity_id:
            - light.candele_hue
            date:
              profile: sunset
              transition: 15
              brightness_pct: '50'
          - service: light.turn_on
            date:
              entity_id: light.backlight_tv
              profile: sunset_in_forest
              transition: 15
          - service: switch.turn_on
            entity_id: switch.plug_158d0002115042
          - service: automation.turn_on
            entity_id: automation.someone_to_home_sign_lights
      default: []
  initial_state: true
  mode: single

As you can see I change the scene of the lights according to the elevation of the sun. In winter in my city the sun sets around 4.30pm but in summer only after 9pm so I can’t keep the same triggers in winter and summer otherwise the last lights would turn on late at night. The only way I’ve thought of is to manually change the sun elevation conditions every time the season changes … So I’m looking for a way to automate these conditions as well.
I hope I was clearer than before.

I’ve never been very good with templates, so if you can give me a hand on what you recommend I’ll be very grateful …

Have a look here: https://skylar.tech/circadian-lighting-with-home-assistant-and-node-red/amp/. It might be of interest.

Thanks for the advice, I already know about circadian lightings and use it for some lights, but I don’t think it is useful for what I am looking for …

1 Like

Seems like there should be 100 different ways to do with this by simply checking the date (now().month).

One thought is to have 2 (or 3 or 4 or whatever you need) different light automations for the different seasons.
Then have a HA automation turn one automation off and the other one on if date = X

Another thought (if you want to keep it one automation for the lights) would be to have input_boolean variables and allow HA automation to toggle them appropriately based off of the date.
Then put the input_boolean as a condition inside the action like so:
automation:
trigger:
platform: state
entity_id: …
to: ‘on’
action:
- service: …
data:
message: …
- condition: and
conditions:
- condition: template
value_template: ‘…’
- service: switch.turn_on
entity_id: switch…

I thought this too and I think it’s a great way to manage what I’m looking for

Yes, this is also good but I have to understand well how to create automation with input_boolean.
Could you give me an example how to handle the boolean?

It still sounds like you are looking for a fixed time. Why are you using sun elevation instead of time numeric state as a trigger?

If you see my automation, I make the lights turn on when the sun is about to set and not at a fixed time. this is because in winter the sun sets at 16 - 16:30 while in summer at 20: 30-21 so if you only used time as a trigger the lights would always turn on at the same time both in winter and in summer … namely at 16-16: 30

the sun sensor also reports above_horizon and below_horizon (sunset)
why not just trigger on below_horizon then you only need the 1 trigger since the sensor will auto-adjust all year?

Are you going to want different elevations for every season or only winter and summer?

How do you foresee the elevation numbers changing throughout the year?

Either way this is going to get very long and complicated. Even more so if you want to change things four times a year instead of only two.

Because, as you can see from the automation, I change the light scenes according to the elevation of the sun 3 times and not just when the sun sets.

The best thing would give during the whole year but I know it is very complicated, so I think the best solution is to create more than one automation and manage everything through a single automation with the season sensor.
If you can give me some examples with the boolean input …

OK, here is what I think you should do…

If you try to do this with one automation it will get ridiculously complicated so I would create 4 different automations and use one season as a condition in each automation.

Let’s assume that the automation above has the correct elevations for the summer season. You could then use the following:

- id: Living room lights summer
  alias: Living Room Lights On in Summer
  trigger:
    - platform: state
      entity_id: sun.sun
  condition:
    - condition: state
      entity_id: sensor.season
      state: summer
    - condition: state
      entity_id: group.presences
      state: home
  action:
    - choose:
      - conditions:
        - condition: numeric_state
          entity_id: sun.sun
          value_template: '{{state.attributes.elevation}}'
          below: -54.64
        sequence:
          service: script.scena_luci_tv
      - conditions:
        - condition: numeric_state
          entity_id: sun.sun
          value_template: '{{state.attributes.elevation}}'
          below: -47.53
        sequence:
            - service: light.turn_on
              entity_id:
              - light.lampade_hue
              - light.yeelight_5
              - light.bedside_living room
              date:
                profile: home
                transition: 20
            - service: light.turn_off
              entity_id:
              - light.candele_hue
              date:
                transition: 20
            - service: light.turn_on
              date:
                entity_id: light.backlight_tv
                profile: 'movie'
                transition: 20
                brightness_pct: 80
      - conditions:
          - condition: numeric_state
            entity_id: sun.sun
            value_template: '{{state.attributes.elevation}}'
            below: -8
        sequence:
          - service: notify.mobile_app_sm_g955f
            date:
              message: Sunset, turn on the lights
              title: HomeAssistant
              date:
                ttl: 0
                priority: high
          - service: light.turn_on
            entity_id:
            - light.lampade_hue
            - light.yeelight_5
            date:
              profile: reading
              transition: 20
          - service: light.turn_on
            date:
              entity_id: light.bedside_living room
              brightness_pct: 100
              color_name: orangered
          - service: light.turn_on
            date:
              entity_id: light.backlight_tv
              profile: movie
              transition: 20
              brightness: 150
          - service: light.turn_off
            entity_id:
            - light.candele_hue
            date:
              transition: 20
          - service: switch.turn_on
            date:
              entity_id: switch.circadian_lighting_studio
          - service: light.turn_on
            date:
              entity_id:
              - light.yeelight_6
              - light.yeelight_1
          - delay: 00:00:05
      - conditions:
        - condition: numeric_state
          entity_id: sun.sun
          value_template: '{{state.attributes.elevation}}'
          below: 0.5
        sequence:
          - service: notify.mobile_app_sm_g955f
            date:
              message: The sun is about to set, I turned on the lights
              title: HomeAssistant
              date:
                ttl: 0
                priority: high
          - service: light.turn_on
            entity_id:
            - light.candele_hue
            date:
              profile: sunset
              transition: 15
              brightness_pct: '50'
          - service: light.turn_on
            date:
              entity_id: light.backlight_tv
              profile: sunset_in_forest
              transition: 15
          - service: switch.turn_on
            entity_id: switch.plug_158d0002115042
          - service: automation.turn_on
            entity_id: automation.someone_to_home_sign_lights
      default: []
  initial_state: true
  mode: single

THen you will create 3 more automations - one for each of the other seasons.

You will substitute the names of the other seasons in the “id” & “alias” sections. And you will change the first condition to be the proper season state.

Finally you will put in the elevation numbers you want for each of the different seasons.

Because you have only one season as a condition in each automation only those actions will be taken corresponding to that season.

I really think that is the easiest (only?) way to get the behavior you want.

Yes, thanks, it was the first idea I had but I wanted to compare myself with others to see if there was a better solution. Now I will create the other automations and only time will tell if everything works as intended … :smile: :smile:

seems you shouldn’t trigger on sun elevation at all, but on light_level, which is the absolute value you need and is independent of season, weather conditions or what have you.

maybe Phils Illuminance sensor can help you out, if you don’t have a device measuring light_level for you.

there’s even an virtual light_level sensor (although it is partly based on the elevation) which people seem to find helpful:

# https://community.home-assistant.io/t/virtual-light-sensor/31975/15
      virtual_light:
        friendly_name: Virtual light
        value_template: >
          {% set elevation = state_attr('sun.sun','elevation')|float %}
          {% set cloud_coverage = states('sensor.openweathermap_coverage')|float %}
          {% set cloud_factor = (1 - (0.75 * (cloud_coverage / 100) ** 3)) %}
          {% set min_elevation = -6 %}
          {% set max_elevation = 90 %}
          {% set adjusted_elevation = elevation - min_elevation %}
          {% set adjusted_elevation = [adjusted_elevation,0]|max %}
          {% set adjusted_elevation = [adjusted_elevation,max_elevation - min_elevation]|min %}
          {% set adjusted_elevation = adjusted_elevation / (max_elevation - min_elevation) %}
          {% set adjusted_elevation = adjusted_elevation %}
          {% set adjusted_elevation = adjusted_elevation * 100 %}
          {% set brightness = adjusted_elevation * cloud_factor %}
          {{brightness|round}}
        unit_of_measurement: '%'
        device_class: illuminance
1 Like

Thanks, both solutions look interesting, especially the light level. Now I’ll take a look at both solutions …

it looked to me like you want to turn on the lights when the sun sets.(because you specifically say that is what you are doing) which “below_horizon” would achieve all year long.

If you look at the full automation posted above he is not just turning on the lights. He’s turning on different lights based on the sun elevation as it gets darker.

At least that’s what I take from it.

Yes, thanks for the good explanation…

1 Like

I have puzzled with this problem. My objective was to open blinds when the sun had risen enough to no longer shine into the windows.
I worked out that aizimuth and elevation are both needed to cater for seasons. However I haven’t mastered the mathematics to get useful answers.