Dim lights as lumens increases

Hi all,
Just wanted to know if it’s possible to have some lights gradually dim as the lumens of a sensor increases?

I don’t mean that I want them to dim every 5/10min or anything. I just want my kitchen lights to change their brightness as the lumens in my kitchen increases or decreases.

Is there a way that I can do this with a template or something?

Hi @wjbeckett,

I think you can use the transitions parameters in the light.turn_on service, also you can use the brightness_step parameter which dims/increases the light by a certain amount :grinning:

Maybe this will help

An automation that is triggered on your light sensor and adjusts brightness is pretty well what you want.

Oh yeah, I know.
I was just looking for assistance on how to write the automation as a template maybe so I didn’t have a massive automation built in “steps”. Wanted to make it as smooth as possible really.

What range are your useful lumens reported in? ie 50 - 800? What light levels do you want to have as lowest and highest?

Interesting, wondering how to do this as well. You basically want the illuminance to stay within a certain range but the speed in which you increase the brightness of the lights depends on how often your light sensor is reporting. Wondering what @nickrout has in mind.

It is hard to model without knowing some figures. If @wjbeckett or someone else gives me some figures I will post something.

Sorry sorry.
Forgot to reply!
Give me a sec and I’ll get some lux values.

So right now I’ve got my lights coming on when the lumens are below 280 and they turn off when the lumens are above 280.
But I really could extend that you to 350lux.

Ideally the lights wouldn’t be very bright at 350lux , maybe 20%, and then as the lux decreases the brightness increases up to 100% when the lux is at 200. And then obviously the reverse as well.

OK lets call the luminance sensor sensor.lum and the light entity light.desk.

Ypur trigger is going to be a change of state of sensor.lum

Your condition is going to be what time of day you want this to operate (if needed)

Your action is going to be a template that calculates the brightness according to this formula: brightness = -3.36 * sensor.lum + 1196 (assuming brightness 0-255), and then calls the service to set the brightness of light.desk to that figure.

It is my bedtime, so I haven’t allowed for the

  1. the edge cases where sensor.lum is not within the range 280-350; or

  2. Actually writing the template,

But I hope that helps :slight_smile:

Just for my understanding, your light sensor isn’t actually measuring the light in your kitchen?

No, it is. I just want my lights in the kitchen to dynamically adjust depending on how much light the sensor is reading.

Thank for this. I’ll try and put something together.

@nickrout Are you able to let me know how you calculated this formula? It seems in one of the latest updates my lumens sensor has changed and the values are now completely different.
It now looks like the lumens range I need is now 0-500.

Here’s what I have done so far (haven’t finished the brightness template yet).

- id: dynamically_adjust_kitchen_lights
  alias: dynamically adjust kitchen lights
    platform: state
    entity_id: sensor.kitchen_sensor_illuminance_lux
    condition: time
    after: "06:00:00"
    before: "18:30:00"
    service: light.turn_on
      entity_id: light.kitchen_pendant_lights
      brightness: >
      -3.36 * state_attr(trigger.entity_id, 'illuminance_lux') + 1196

Obviously the brightness template isn’t finished but I can;t finish it until I can figure out how that calculation should be now given the new lumens range.

Any help would be greatly appreciated!

Thank you!

Actually I realise in reviewing this to explain it that I made an error earlier!

First of all visualise your data, It is a straight line as we only have two points.

ambient light = 280, brightness = 255
ambient light = 350, brightness = 51 (ie 20% of 255)

Plot it on a piece of paper.


Every straight line can be defined by the formula

y = (slope * x) + constant

so in this case

brightness = (slope * lux) + constant

Now the slope of the line is:

= -204/70
= -2.91 (I got -3.36 last time, don’t worry how, I just did, sorry bout dat)

To work out constant, take one of those points we know about and work it out. We’ll use the left hand point, lux = 280, brightness = 255

We know

brightness = (slope * lux) + constant
255 = (-2.91 * 280) + constant
255 = -814.8 + constant
so constant = 1069.8 (once again different to last time because of the wrong answer for slope)

Try it out for the other point, just to check:

lux = 350, brightness = 51

brightness = (-2.91 * lux) + 1069.8
51 should equal (-2.91*550) + 1069.8) (in fact it is .3 out because of rounding errors, but that is acceptable.

So in short

brightness = (-2.91 * lux) + 1069.8

Or just use this page :slight_smile:


On nice.
Okay, so here’s my plot after updating the values with new lux values.

Basically i’m still using the brightness values of 0 to 255, but the lux values have changed to be 50 to 500 (at 500 I basically want the lights off).

What i’m struggling with is how to template this equation. I’m still new to templating so it’s daunting for me.

I’ll have a play.

1 Like

I came up with this from the above slope.
{{ (-0.41 * states('sensor.kitchen_sensor_illuminance_lux')|int) +255 | round }}

Not sure if the math was right though.

But on the graph you posted above it should be

{{ (-0.57 * states('sensor.kitchen_sensor_illuminance_lux')|int) +283 | round }}

17/30 = .56666666 round to .57
850/3 = 283.3333 round to 283