First Automation Help

I am trying to automate the turning on of lights depending on sun angle and time/day of week.

I have this started and cannot seem to find the correct combination to get this to function.

sensor:

  - platform: template
    sensors:
      solar_angle:
        friendly_name: "Sun angle"
        unit_of_measurement: 'degrees'
        value_template: "{{ state_attr('sun.sun', 'elevation') }}"

automation:

  - alias: 'Day Care Entry'
    trigger:
      platform: time
      at: '06:40:00'
      weekday:
        - mon
        - tue
        - wed
        - thu
        - fri
    condition:
      condition: and
      conditions:
        - condition: numeric_state
          entity_id: 'sensor.solar_angle'
          below: 0
    action:
      - service: homeassistant.turn_on
        data_template: 
          entity_id: >
              light.day_care_area_light
              light.day_care_single_light
              light.day_care_patio_light

Can someone please guide me to the correct code to get this to function?
Thanks,

  - alias: 'Day Care Entry'
    trigger:
      platform: time
      at: '06:40:00'
    condition:
      - condition: time
        weekday:
          - mon
          - tue
          - wed
          - thu
          - fri
      - condition: numeric_state
        entity_id: sensor.solar_angle
        below: 0
    action:
      service: homeassistant.turn_on
      entity_id:
        - light.day_care_area_light
        - light.day_care_single_light
        - light.day_care_patio_light
1 Like

What Marc said will work. You also don’t need the template sensor if you replace the numeric state condition and use something like this instead:

- condition: template
  value_template: "{{ state_attr('sun.sun', 'elevation') < 0 }}"

Either works, just wanted to share.

1 Like

and just to be safe and follow good practices you should force the state to an int (or float if you prefer) in the template. so…

- condition: template
  value_template: "{{ state_attr('sun.sun', 'elevation') | int  < 0 }}"
2 Likes

Ah thank you. Note that int will always round down even if the actual decimal is .5 or above.

2 Likes