Dim lights according to the sun

I made automations that dim the lights up when the sun rises and dim the lights down when it sets.
I wanted them to work regardless of the lights being on when the automations start, so the automation works by toggling the light with a set percentage and right after toggling it again with same set percentage. It works quite well.
However, if i manually set the percentage for a light and wait for the automation to trigger, then it doesn’t change the percentage.
How come?

That seems back-to-front. You need less artificial light during the day and more at night.

The way I do it is with a template sensor. This calculates the required brightness depending on the outside lux level.

I use this sensor to set the brightness whenever I turn a light on, and continuously in some places.

This template is specific to my lights and my light sensor so won’t work for you. But here’s the idea:

template:
  - sensor:
      - name: 'Calculated Light Brightness'
        unique_id: ec93bfc9-9b35-4281-a1da-7907469766e7
        unit_of_measurement: "Int"
        state: >
          {{ ( [0, (-0.1785 * states('sensor.outside_light_level')|float(0) + 298.35 )|int(0), 255]|sort )[1] }}
        availability: "{{ states('sensor.outside_light_level')|is_number }}"
  action:
  - service: light.turn_on
    entity_id: light.kitchen_downlights
    data:
      brightness: "{{ states('sensor.calculated_light_brightness')|int(0) }}"
      transition: 5
      kelvin: 4000

If you don’t have a lux sensor you could make one.

Thanks for the quick reply!

No, i actually have it right. I’m quite sensitive to light, so i want it dimmed down at night and especially during the morning when i get up. Then when the sun rises, everything gets gradually brighter, then my lights are also allowed to get brighter right until the sun sets again.

I haven’t really been using anything but the automations section (the web UI/frontend) to make automations, so the code you send doesn’t make 100% sense to me, but i’ll try to see if i can make something work.

I have some Aqara motion sensors, i guess i could take the lux level from them and apply it to the automation.

Can you recommend any guide or video for learning to both understand and make automations the “coding” way?

1 Like

Thanks, i’ll look into it right away!

Instead I’m making a sensor this will also work quite well: GitHub - pnbruckner/ha-illuminance: Home Assistant Illuminance Sensor