Smart light dimmer - dim light depending on light sensor value

Introduction:
This is a blueprint that dims 1 or more lights based on the ambient light measured through a light sensor.

The user can set a maximum and minimum ambient light values between which the automation will run.
When the ambient light goes over the maximum value, the light will be turned off.

The user can also set a value for the lights brightness at the minimum and maximum ambient light values. This allows for flexibility to dim inverse to the ambient light value.

Example 1:

  • Max ambient: 400 (± sunset value)
  • Min ambient: 0 (nighttime)
  • Light value at max ambient: 0
  • Light value at min ambient: 255

→ The above example will start slowly turning up the light until full brightness when the ambient value drops from 400 to 0 (sunset to night).

Example 2:

  • Max ambient: 400
  • Min ambient: 50
  • Light value at max ambient: 191
  • Light value at min ambient: 107

→ This is how I use it in my office space.
It will turn on the light at 191/255 (~70%) when the ambient light drops under 400lx (for example when it’s cloudy outside during the day, or when the sun starts to set) and will actually dim the light down to 107/255 (~40%) around late sunset-nighttime so that there is not too much light, which might cause eye fatigue.
It will not dim further down than the set value at min ambient, even when the light value drops lower.


Credits:


Changelog:

28/03/2022 - Version 2.0 ( NEWEST )

Open your Home Assistant instance and show the blueprint import dialog with a specific blueprint pre-filled.

  • BREAKING: Updated brightness values to percentages to improve user experience.
    This version is not compatible with older ones. If you experience issues, please download the latest release and recreate the automations.

22/03/2022 - Version 1.3

Open your Home Assistant instance and show the blueprint import dialog with a specific blueprint pre-filled.

  • Simplified the code for the day condition

22/03/2022 - Version 1.2

  • BREAKING: Added day condition support.
    Please download the newest version and recreate the automations if you experience issues.

21/03/2022 - Version 1.1

  • BREAKING: Added start & stop time conditions
    Please download the newest version and recreate the automations if you experience issues.
  • Added versioning
  • Added source url

19/03/2021 - Version 1.0

Open your Home Assistant instance and show the blueprint import dialog with a specific blueprint pre-filled.

  • Original release

Code: (Latest version)

3 Likes

Lol I see from the date of the post you relied on that we were just in lockdown. No wonder I had time to post all that explanation. My usual response to “how did you work out that formula?” would be “I had a good maths teacher when I was 14”.

1 Like

Don’t be too humble, the explantion has helped a lot indeed.
I’ve added your teacher to the credits list :wink:

1 Like

That’s a super nice idea! My lux automation was way to complicated. Many thanks to AntonH for the great automation and to nickrout for the maths basics.

1 Like

New Release
21/03/2022 - Version 1.1

  • Added start & stop time conditions
  • Added versioning
  • Added source url

New Release
22/03/2022 - Version 1.2

  • BREAKING: Added day condition support.
    Please download version 1.2 and recreate the automations if you experience issues.

New Release
22/03/2022 - Version 1.3

Open your Home Assistant instance and show the blueprint import dialog with a specific blueprint pre-filled.

  • Simplified the code for the day condition

New Release

28/03/2022 - Version 2.0

Open your Home Assistant instance and show the blueprint import dialog with a specific blueprint pre-filled.

  • BREAKING: Updated brightness values to percentages to improve user experience.

This version is not compatible with older ones. If you experience issues, please download the latest release and recreate the automations.

Does this blueprint have function to deactivete when not home or no motion detected?

1 Like

Not yet, I’m testing that as we speak.
I run it in my home office space, so I don’t want it to run when i’m not home.

The problem with this is also that if you don’t want this condition, you cannot leave it blank because it will error out. So trial and error for now.

A non flexible solution would be to download the blueprint and then add the condition hardcoded if you want.
You could do something like this:

condition:
  - condition: state
    entity_id: input_boolean.PERSON_IS_HOME
    state: 'on'
1 Like

Super big thank you for publishing this blueprint!

I found it as a really great starting point for my own blueprint… I wanted to dim all the lights in the common areas of my main floor, but I wanted the automation to respect any lights that had been manually controlled.

To solve this, I allow the user to select to a list of light entities, and then the automation loops though them one at a time, checks that the brightness of each light matches the brightness of the previous automation run, and only then does the automation update the brightness of the light. It’s not an entirely foolproof solution, but it seems to work well with my usage.

You can check out my blueprint here.

I’m not done with the changes I intend to make; another thing I am considering is adding some kind of margin to the upper lux threshold, because I found the lux readings from my light sensor can fluctuate a little bit… for example, if I configure the automation to turn the lights on at 500lx - I might get readings like so: 540lx, 520lx, 490lx, 510lx, 475lx… causing the lights to turn on, off and on again. So I was thinking of adding a configurable margin so that when the lights are turned on at 500lx, they don’t turn off again until the lux reading reaches 550 or 600lx.

1 Like

You’re welcome.

The margin could be interesting in some use cases yes.
I have the maximum value set for my office around 350lx. So during a cloudy day it turn on and off regularly.
This is wanted behaviour for me, but I could see it being annoying to deal with for some.
The reason I don’t mind it is that my lights don’t actually switch on and off, but rather fade on and off (set as such in my KNX system), which makes the transitions smooth.

Thanks a lot for publishing this blueprint has worked well for me, one question on some of the lights I have this stops at 7PM if the lights are on they stay on I scheduled another automation to have it turn off after 7PM is there a way to just fit this in as an option? or does it already do this and I missed something? if not I understand either way thank you for your time!

1 Like

Hi,

The automation only turns on or off based on the light sensor value.
Time is not taken into account.

If you want to do this, it’s easiest to just add another automation to turn the light off.
You’ll need to add a condition to this blueprint that would prevent the automation from running after a specific time though, otherwise it might turn it back on.

I noticed you can use markdown in the description of a blueprint.

So I figured it’d be awesome to add a diagram to my blueprint so that the automation is easier to understand during configuration. I labelled the different points on the diagram, and then prefixed the input fields with those labels.

2 Likes

Is there a blueprint like this but to turn on light when motion is detected and then dim depending on light sensor value?

1 Like

You could just modify the trigger in this blueprint to a motion sensor.