Logic Machine Forum
Simple Staircase Timer - 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: Simple Staircase Timer (/showthread.php?tid=4193)



Simple Staircase Timer - Rauschentofft - 16.08.2022

Hi.

I need help with a simple staircase timer script. Staircase with after dimming with two step.

When the trigger gets true 1/1/1, Timer 1 and Timer 2 starts and Set Value High to 1/1/2 Output.

After ten minutes the Set Value Low is set to 1/1/2 Output. If the time runs out it should write Set Value Off.

But every time the trigger recive true the timer 1 and 2 is retrigged.

If timer 2 is active and the trigger recive true it should set 90%.


1/1/1 Trigger Staircase 1bit
1/1/2 Output 1byte
Set Value High 90%
Set Value Low 20%
Set Value Off 0%
Set Timer 1 = 10min
Set Timer 2 = 20min

Br


RE: Simple Staircase Timer - admin - 17.08.2022

Resident script with 0 sleep time. Adjust timers table as needed. This script can handle multiple timers.
Code:
if not client then
  timers = {
    ['1/1/1'] = {
      output = '1/1/2', -- dimmer control (0..100%)
      onvaluehigh = 90, -- high output value in %
      onvaluelow = 20, -- low output value in %
      timeouthigh = 10 * 60, -- time to keep high value (in seconds)
      timeoutlow = 10 * 60, -- time to keep low value (in seconds)
    }
  }

  function timersetstate(timer, state)
    grp.checkwrite(timer.output, timer['onvalue' .. state] or 0)
    timer.state = state
    timer.ticks = timer['timeout' .. state]
  end

  function timertimeout(timer)
    local state = timer.state == 'high' and 'low' or 'off'
    timersetstate(timer, state)
  end

  for _, timer in ipairs(timers) do
    timer.state = 'off'
  end

  grp.sender = 'tm'

  client = require('localbus').new(0.1)
  client:sethandler('groupwrite', function(event)
    local timer = timers[ event.dst ]
    if timer and event.sender ~= grp.sender then
      local value = tonumber(event.datahex, 16) or 0
      if value == 1 then
        timersetstate(timer, 'high')
      end
    end
  end)
end

client:loop(1)

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

    if timer.ticks == 0 then
      timertimeout(timer)
    end
  end
end



RE: Simple Staircase Timer - Rauschentofft - 17.08.2022

Thank you very much for the help.

Hi again.

Is it possible to have a slave input to retrigger the timer when it is active?

1/1/1 Trigger Staircase 1bit
1/1/2 Output 1byte
1/1/3 Slave Input
Set Value High 90%
Set Value Low 20%
Set Value Off 0%
Set Timer 1 = 10min
Set Timer 2 = 20min


RE: Simple Staircase Timer - Rauschentofft - 02.04.2023

Hi,

if i only want the staircase timer to send 90% when its trigged, and the time is out it send 10%


RE: Simple Staircase Timer - admin - 03.04.2023

Remove timeoutlow and the timer won't go into off state.
Code:
timers = {
  ['1/1/1'] = {
    output = '1/1/2', -- dimmer control (0..100%)
    onvaluehigh = 90, -- high output value in %
    onvaluelow = 10, -- low output value in %
    timeouthigh = 10 * 60, -- time to keep high value (in seconds)
  }
}



RE: Simple Staircase Timer - Rauschentofft - 03.04.2023

Thank you very much for the help.