Action between sun events

Hi,

With the data_template I have below, I try to make it so that the brightness in the kitchen is dependant on the time. However, this might be fine for now, but as the seasons change the code will not be updating with the sunsets/sunrises etc.
Is there a way to replace ‘time’ with ‘sun’ events?

action:
  service: light.turn_on
  entity_id: light.kitchen_main
  data_template:
    brightness: >
      {% if now().hour > 22 %}5
      {% elif now().hour < 8 %}5
      {% else %}180
      {% endif %}

Second question: currently there’s only 2 options: it’s either between 22 and 08, or it’s not. I’d like to, for instance, say that 16-17 brightness=10, 17=18 brightness=60, 18-20 brightness=140

thx!

The sun component exposes elevation: and azmuith: attributes that can be used.

Example of how I use it.

1 Like

awesome, you’re the best! Implemented it yesterday and it works. Only need to finetune the elevation value over the next few days.

Any suggestions for my second question?