Lights on with sun elevation (keeps triggering)

Anyone info about this?

Just wondering: why would you want to use elevation instead of sunset time?

Because - personally - I think the sky in the winter and summer season isn’t equal if you compare it based on sunset.

In summer when the sunset is ongoing or done, the sky is brighter than in wintertime. So I play around with the elevation in those seasons.

I see, makes sense. Could you please share the elevation levels you are using? (as you are also from NL)

Please post whatever automation you are trying to insert this template into.

What I’ve got right now is

- id: '1617777084501'
  alias: Woonkamer - Lampen basis van zon
  description: ''
  trigger:
  - platform: numeric_state
    entity_id: sun.sun
    attribute: elevation
    below: '8.5'
  condition:
  - condition: state
    entity_id: binary_sensor.people_home
    state: 'on'
    for: 00:05:00
  action:
  - service: light.turn_on
    target:
      entity_id: light.tradfri_lamp_tv_meubel
    data:
      transition: 2
  - delay: 00:05:00
  - service: light.turn_on
    data: {}
    target:
      entity_id:
      - light.tradfri_spotje_schuifdeur_links
      - light.tradfri_spotje_schuifdeur_rechts
  mode: single

I’ve tried the below state with for example

"{{ states('input_number.sunset_for_automation') | float }}"
"{{ states('input_number.sunset_for_automation') | int }}"

both didn’t work.

mm this is what I use:

value_template: “{{ state_attr(‘sun.sun’, ‘elevation’) }}”

you can try it in developer tool template it will give the elevation.

But when I try

platform: numeric_state
entity_id: sun.sun
attribute: elevation
below: value_template: “{{ state_attr(input_number’, sunset_for_automation) }}”

I get
Message malformed: expected float for dictionary value @ data[‘below’]

may not be the best way, but I made a sensor out of it, so I do not need to reuse this template all the time but use the sensor output as value in triggers or conditions, thought it to be much easier. :grinning:

here is my sensor and it works as I did intend it,

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

there are some things wrong with that.

platform: numeric_state
entity_id: sun.sun
attribute: elevation
below: "{{ state_attr('input_number.some_entity_id_here’, 'sunset_for_automation') }}"

But only if the input_number entity has that attribute.

unless the entity_id is actually “sunset_for_automation” then it becomes:

platform: numeric_state
entity_id: sun.sun
attribute: elevation
below: "{{ states('input_number.sunset_for_automation') }}"