Hey all, I have a smart light on the living room wall that I’ve configured in Home Assistant to turn on if there’s excess energy from my solar panels and turn off if there isn’t. I do this by using a simple “Excess Energy” helper that subtracts power consumption from generated power and supplies a figure in Watts.
I then use two simple “If it’s above zero turn the light on” and “If it’s below zero turn the light off” automations to turn the smart light on or off, and it’s mostly seamless.
I’d like to enhance this by setting the brightness of the smartlight to indicate how much excess power there is. What I’m trying to work out is how to convert the above graph to brightness values ranging from 0-100%. The values on the Excess Energy helper range from a negative number (which would have to be 0% brightness) to somewhere just shy of 6000W (anything 6000 or above would be 100%)
So, my question is how do I perform that conversion mathematically to convert a value between, say, -8000 and +8000, bounded by 0 and +6000, into a percentage between 0 and 100 ?