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.

Staircase script with dimming option
#10
The same script works for me. Does 9/0/1 exist?
I've added some logging, check what you get in the Logs tab:
Code:
if not client then
  timers = {
    {
      input = '9/0/1', -- binary PIR status
      output = '1/1/7', -- dimmer control (0..100%)
      onvaluehigh = 90, -- high output value in %
      onvaluelow = 10, -- low output value in %
      timeout = 5, -- in seconds
    }
  }

  function setinputvalue(timer, event)
    local value = busdatatype.decode(event.datahex, dt.bool)

    if not value then
      return
    end

    log('pir trigger', timer.outvalue)

    if timer.outvalue < timer.onvaluelow then
      value = timer.onvaluelow
    elseif timer.outvalue < timer.onvaluehigh then
      value = timer.onvaluehigh
    else
      value = nil
    end

    if not timer.ticks and value then
      grp.write(timer.output, value, dt.scale)
    end

    timer.ticks = timer.timeout
  end

  function setoutputvalue(timer, event)
    timer.outvalue = busdatatype.decode(event.datahex, dt.scale)
    timer.ticks = nil -- stop timer
    log('output change', timer.outvalue)
  end

  for _, timer in ipairs(timers) do
    timer.outvalue = grp.getvalue(timer.output)
    log('timer init', timer.outvalue)
  end

  sender = 'tm'
  grp.sender = sender

  client = require('localbus').new(0.1)
  client:sethandler('groupwrite', function(event)
    if event.sender == sender then
      return
    end

    for _, timer in ipairs(timers) do
      if timer.input == event.dst then
        setinputvalue(timer, event)
      elseif timer.output == event.dst then
        setoutputvalue(timer, event)
      end
    end
  end)
end

client:loop(1)

for _, timer in ipairs(timers) do
  if timer.ticks then
    timer.ticks = timer.ticks - 1

    if timer.ticks == 0 then
      log('timer stop', timer.outvalue)
      grp.write(timer.output, timer.outvalue, dt.scale)
      timer.ticks = nil
    end
  end
end
Reply


Messages In This Thread
RE: Staircase script with dimming option - by admin - 15.06.2022, 09:44

Forum Jump: