N00b First Time Sun Automation

Hello. First post, and apologies for what I assume is basic knowledge for the educated. I assume there are many topics on this already, but I am so new that I am not really sure what keywords to use or search for help.

I have an automation setup. I want to turn lights on based on the elevation of the sun. I have read some documents but keep getting confused. I built the automation and when I run the action I do get the intended outcome of the light turning on along with the feedback on the dashboard that my shelly relay is functioning.

I generated this YAML from the configuration editor but the automation did not execute. I fiddled with the elevation status to test new code multiple times but, it is still a no go.

Any help?


alias: Turn Front Lights on @ Dusk
description: ''
trigger:
  - platform: state
    entity_id:
      - sun.sun
    attribute: elevation
    from: '-4'
    to: '-89'
condition: []
action:
  - type: turn_on
    device_id: 6ce08099af5e1d5dcaadc0ab9dcacd7f
    entity_id: switch.outside_front_lights
    domain: switch
mode: single

The way you have the trigger the attribute has to change from exactly -4 to exactly -89. That can’t ever happen.

Ty for the reply. I still do not really get it though. I did change the code and this appears to work. I had to make two automations. One for on and one for off. Not sure if that is correct if they could be combined or not.

alias: Turn Front Lights Off @ Dawn
description: ''
trigger:
  - platform: numeric_state
    entity_id: sun.sun
    attribute: elevation
    below: '-89'
condition: []
action:
  - type: turn_off
    device_id: 6ce08099af5e1d5dcaadc0ab9dcacd7f
    entity_id: switch.entry_lights
    domain: switch
mode: single

and

alias: Turn Front Lights on @ Dusk
description: ''
trigger:
  - platform: numeric_state
    entity_id: sun.sun
    attribute: elevation
    below: '-4'
condition: []
action:
  - type: turn_on
    device_id: 6ce08099af5e1d5dcaadc0ab9dcacd7f
    entity_id: switch.entry_lights
    domain: switch
mode: single

This appears to work, but there has to be a better way.

The time that it takes to go from -4 to -89 is constant, no? Why not just turn the lights on when the sun is at -4, then put a wait timer on it until the same time that -89 typically occurs?

I don’t know if it’s actually “better” or not but it’ll definitely be more complicated if you use the two triggers in one automation and then use a ‘choose’ in the action to decide if you want it to turn on or off.

alias: Turn Front Lights Off @ Dawn
trigger:
  - platform: numeric_state
    entity_id: sun.sun
    attribute: elevation
    below: '-89'
    id: 'off'
    - platform: numeric_state
    entity_id: sun.sun
    attribute: elevation
    below: '-4'
    id: 'on'
action:
  choose:
    - conditions:
        - {{ trigger.id == 'off' }}
      sequence:
        - service: switch.turn_off
          entity_id: switch.entry_lights
    - conditions:
        - {{ trigger.id == 'on' }}
      sequence:
        - service: switch.turn_on
          entity_id: switch.entry_lights
mode: single

I think it varies based on time of the year. I may be very wrong tho.

Ah, super simple to understand. I agree, perhaps its more complicated this way. Tradeoffs for sure.