Hi all, I am struggling with the logic of this and can’t figure it out so I would appreciate any help, please.
I am trying to use a BH1750 light sensore to control the brightness of a light. The light brightness range is 0 to 1, the BH1750 state range is higher so I need a way to map this. Currently I have the following:
I think the sensor outputs in lux, which is a linear scale and the sensor goes to 65K or so. The eye’s response to light isn’t linear but more logarithmic. So what exactly are you trying to do?
The BH1750 is to be used indoors only so I do not expect to need the full range available (I expect a lower top end) and I want to be able to map that to the 0.0 - 1.0 range. I saw this snippet posted somewhere but have not been able to get it to work yet.
It gives this error when I try to install it (just key part copied):
/config/esphome/input-office-tft.yaml: In lambda function:
/config/esphome/input-office-tft.yaml:612:34: error: 'brightness' was not declared in this scope
return id(back_light).turn_on(brightness: dynamic_brightness);
Enjoy, but don’t ever trust. You will get whatever shit out from “him”.
Your problem seems to be not mathematic but more personal experience.
You could map the sensor output simply using filter like calibrate_polynomial or calibrate_linear with method: exact.
That says a likely upper level is 1000 lux, unless of course your sensor has a clear view of outside and you live in Arizona (where 10K lux would not be unreasonable).
If you do a linear translation you will likely be unhappy. So think more exactly of what you want the translation to be. What is the purpose of the led? Is it an indicator or is it trying to correct for the deficiency in light or something completely different?
Thanks again, useful information. The sensor is slightly recessed so I will need to work with observations based on real-world sampling. The LED is for a display panel so it only has to look ‘right’ for the purpose and I can easily tweak the output to achieve that.
Because of my day job, I trust but verify. I’ve done that for decades with humans and computers - and apply the same approach to AI.
In this case, the search took about 30 seconds, and I had it working within about 3 minutes total. It may not be the most elegant approach or the most efficient but it worked - and quickly.
I will now iterate from there - as I have a working version, I can now experiment, tweak and tune at my leisure.
It occurred to me that I use the history graph to track my outside illuminance. You could adapt this to your indoor sensor to see the lux range of your environment:
Thanks, yes, I have done that with the unit after installing the config above. It seems to be working perfectly, with approx 1,200 lux maximum light level today where it is mounted - on a very sunny day here in southern England.