This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

dim up / down to percentage
#1
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)
Reply
#2
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..
Reply
#3
Yep run it as resident and as long as I touch no button it is fine. When I change something everything gets slow
Reply
#4
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.
Reply
#5
Slow i mean TP Load goes to 100%
Reply
#6
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.
Reply


Forum Jump: