10.12.2024, 19:32
Hi everyone,
I'm using a script found on this forum, by Daniel, I believe, which I've modified a little to suit my needs. The only problem I'm having is that every time a READ passes on the bus, the updatetime value is updated, so my timer doesn't work as expected. Do you have any ideas? Thanks in advance
I'm using a script found on this forum, by Daniel, I believe, which I've modified a little to suit my needs. The only problem I'm having is that every time a READ passes on the bus, the updatetime value is updated, so my timer doesn't work as expected. Do you have any ideas? Thanks in advance
Code:
timers = {
{
name = 'TEST',
input = '0/6/100',
inputValueForTrigger = false,
output = '14/0/202',
outputValue = true,
outputTimeMinutes = 6,
writeInverseValue = true
},
}
for _, timer in ipairs(timers) do
-- find required object
obj = grp.find(timer.input)
-- object exists and current state is "on"
if obj and obj.data == timer.inputValueForTrigger then
-- delta is in seconds
delta = os.time() - obj.updatetime
-- switch when timer expires
if delta >= timer.outputTimeMinutes * 60 then
grp.checkwrite(timer.output, timer.outputValue)
end
else
if obj then
if timer.writeInverseValue then
grp.checkwrite(timer.output, not timer.outputValue)
end
end
end
end