10.12.2022, 07:56
(This post was last modified: 10.12.2022, 10:37 by josdegroot.)
Is this going to work? I would like to add a second timer with input 0/0/17 but to a different output.
Wondering if this is right?
Wondering if this is right?
Code:
if not client then
timers = {
['0/0/17'] = {
output = '0/0/24', -- binary output
delayon = 3 * 60, -- on delay time (seconds)
delayoff = 2, -- off delay time (seconds)
},
['0/0/17'] = {
output = '0/0/25', -- binary output
delayon = 2, -- on delay time (seconds)
delayoff = 2 * 60, -- off delay time (seconds)
}
}
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
local state = value > 0 and 'on' or 'off'
if timer.state ~= state then
timer.state = state
timer.ticks = timer['delay' .. state]
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
grp.checkwrite(timer.output, timer.state == 'on')
timer.state = nil
timer.ticks = nil
end
end
end