Logic Machine Forum
dim up / down to percentage - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8)
+--- Thread: dim up / down to percentage (/showthread.php?tid=5026)



dim up / down to percentage - KoBra - 15.10.2023

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)



RE: dim up / down to percentage - Erwin van der Zwart - 15.10.2023

You probably run this as resident script at 0 sec correct?

Or do you have it as event based attached to 1/4/10?

If yes then you should change that as this way you run this script every 0.2 seconds..


RE: dim up / down to percentage - KoBra - 15.10.2023

Yep run it as resident and as long as I touch no button it is fine. When I change something everything gets slow


RE: dim up / down to percentage - admin - 16.10.2023

Use an event script with execution mode set to "Last instance only".
Code:
out = '32/0/25'

dimmer = event.getvalue()
step = bit.band(dimmer, 0x07)

if step == 0 then
  return
end

up = bit.band(dimmer, 0x08) ~= 0

vstep = up and 5 or -5
value = grp.getvalue(out)

while true do
  nvalue = value + vstep
  nvalue = math.min(nvalue, 100)
  nvalue = math.max(nvalue, 0)

  if nvalue ~= value then
    grp.write(out, nvalue)
    value = nvalue

    os.sleep(0.2)
  else
    break
  end
end

What do you mean by everything gets slow? The script sends 5 telegrams per second which is not a high load. You can lower this by increasing the sleep time. You might need to adjust the step size to keep the dimming speed the same as before.


RE: dim up / down to percentage - KoBra - 16.10.2023

Slow i mean TP Load goes to 100%


RE: dim up / down to percentage - admin - 16.10.2023

Connect ETS group monitor and see what you get there. If there's another KNX/IP interface on the same TP line you might get a loop where each message is repeated several times before the hop counter becomes 0.