15.10.2023, 18:45
I run this script to change up/down dim to a percentage but when it runs the logic machine goes in overload (100%) Is there another/better way?
Code:
dimmer = grp.getvalue('1/3/10')
step = bit.band(dimmer, 0x07)
if step ~= 0 then
addr = '1/4/10'
up = bit.band(dimmer, 0x08) ~= 0
value = grp.getvalue(addr)
if up then
newvalue = value + 5
else
newvalue = value - 5
end
-- clamp between 0 and 100
newvalue = math.min(newvalue, 100)
newvalue = math.max(newvalue, 0)
if newvalue ~= value then
grp.write(addr, newvalue)
end
end
os.sleep(0.2)