I was sent the following code as an example of what I could do to calculate the watts being used by a hue light bulb, based on its model number and brightness level..
if hue_model == "LWB010" and hue_state == true then
if hue_level <= 0 then watt = 0.4 end
if (hue_level > 0 and hue_level <= 6) then watt = 1.6 end
if (hue_level > 6 and hue_level <= 13) then watt = 1.7 end
if (hue_level > 13 and hue_level <= 20) then watt = 1.8 end
if (hue_level > 20 and hue_level <= 26) then watt = 1.9 end
if (hue_level > 26 and hue_level <= 33) then watt = 2.2 end
if (hue_level > 33 and hue_level <= 40) then watt = 2.4 end
if (hue_level > 40 and hue_level <= 46) then watt = 2.7 end
if (hue_level > 46 and hue_level <= 53) then watt = 3.0 end
if (hue_level > 53 and hue_level <= 60) then watt = 3.5 end
if (hue_level > 60 and hue_level <= 66) then watt = 3.9 end
if (hue_level > 66 and hue_level <= 73) then watt = 4.5 end
if (hue_level > 73 and hue_level <= 80) then watt = 5.1 end
if (hue_level > 73 and hue_level <= 86) then watt = 5.5 end
if (hue_level > 86 and hue_level <= 93) then watt = 6.4 end
if (hue_level > 93) then watt = 6.7 end
print(watt)
else
print("light is off")
end
As the brightness range returned by the Hue API seems to have changed from 0-100 to 0-255, the above needs to be updated. And as part of that work, I’d like to make it more efficient (less code) and also more precise.
Logic suggests that when the light’s on full (255) it will be using 6.7w, and if it’s at 50% (127), that’ll drop to approx (3.35w)
Sadly after trying various thing, I keep failing badly, and find myself reverting back to something very long like the original look up type table above. Surely there’s a better/cleaner way ?
If so, please could someone share what they would do.
Many thanks..

