Automations to turn on lights based on actual season

Currently I use an automation to turn on the lights based on the elevation of the sun, but changing the season I should also change the triggers related to the elevation of the sun. Is there a way to use this automation based on the different seasons and therefore on the different elevation of the sun?

1 Like

there is a ā€œseasonā€ sensor.

install it and then you can use it in your automations like any other sensor.

Yes, I am already aware of this sensor, but my question is related to how, using this sensor, to change the value of the solar elevation in the various phases of the seasons. For example, now the automation turns on the lights to watch TV when the sun is at -54 degrees, which corresponds to around 9:30 pm in my city, which in summer is only reached late at night.
I wonder how to change or create a new automation that has solar elevation as a trigger and seasonality as a condition or further trigger.

you can only have one trigger at a time so the idea of a ā€œfurther triggerā€ doesnā€™t make sense.

But based on what you are asking I would use a template trigger. And then set up the template to have the sun elevation set based on the different seasons. so for summer the elevation is x, then in winter the elevation is y, etc.

It isnā€™t clear what your end goal is. What are you trying to achieve? It almost sounds like you want the lights on at the same time regardless of the sunā€™s position. Using solar angle, I think that you should be getting the lights on at approximately the same level of solar illumination.

@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