Scaling Brightness Settings

In retrospect, I think this should have been mathematically obvious, but I wanted to give a heads up about brightness scaling.

I have bulbs in one are that have 2 separate controllers. Some are controlled via hubitat that uses a 0-100 scale. The others are controlled via Zigbee2mqtt that use a 0-255 scale.

I have a dashboard with an individual slider for each bulb and a common slider that changes them all to the same setting. In addition to sending the input to the appropriate controller, I also have my flow set up so that a change made by other means, updates the position of the slider for that bulb. For example Hubitat has its own dashboard.

My original implementation used the 0-255 scale for all of them and then scaled to 0-100 scale before sending to to the Hubitat bulbs. What I found is that by doing the scaling this way and then scaling back when I received info from Hubitat, I found that 2 math operations with either rounding or truncating the non integer portion would get feedback for some inputs that was either 1 more or 1 less than what was on the slider. This then fed back as a second unnecessary change of brightness.

Using a 0-100 scale for the sliders and then scaling the input to 0-255 for the Zigbee2mqtt bulbs never has this problem.

Lesson learned. When down scaling and then reupscaling you lose precision, but Up and then downscaling means that there are certain upscaled setting you will never reach, but you will non have the loss of precision in the slider.

1 Like