Staircase timer with LogicMachine #
Create a resident script with 0 sleep time. Modify the timers
table as needed.
Each timers
table key is an input group address (1/1/1
and 1/1/3
in this example).
Each timers
table value is a table containing the following fields:
output
group address,onvaluehigh
/onvaluelow
- HIGH / LOW output valuestimeouthigh
/timeoutlow
- HIGH / LOW timeout values in seconds
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)
},
['1/1/3'] = {
output = '1/1/4', -- dimmer control (0..100%)
onvaluehigh = 90, -- high output value in %
onvaluelow = 0, -- 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 pairs(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
Further assistance can be found in this forum thread