03.02.2025, 12:53
Resident script with 0 sleep time. Modify input/output objects (0/0/1 and 0/0/3 in this example) and offvalue value as needed.
Code:
if not client then
timers = {
['0/0/1'] = {
output = '0/0/3', -- output value object
timeout = 300, -- timeout in seconds
onvalue = nil, -- value to send when timer is turned on (nil to disable)
offvalue = true, -- value to send when timer is turned off (nil to disable)
},
}
function timerset(timer, value, ticks)
timer.ticks = ticks
grp.write(timer.output, value)
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
timerset(timer, timer.onvalue, timer.timeout)
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
timerset(timer, timer.offvalue)
end
end
end