![]() |
|
Timer - How to improve - Printable Version +- LogicMachine 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: Timer - How to improve (/showthread.php?tid=5785) |
Timer - How to improve - Fcs - 10.12.2024 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 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
endRE: Timer - How to improve - admin - 11.12.2024 Map an event script to the input object and save the current timestamp in storage: Code: key = 'updatetime_' .. event.dst
time = os.time()
storage.set(key, time)Then modify your timer script: Code: key = 'updatetime_' .. timer.input
time = storage.get(key, 0)
delta = os.time() - timeRE: Timer - How to improve - Fcs - 12.12.2024 Thanks you, this is the solution I wanted to avoid, I find it very comfortable to have all the timers in one file. I don't yet know how “localbus” works, but couldn't I manage to create a kind of write capture? Is there a place where I can find documentation? RE: Timer - How to improve - admin - 13.12.2024 You can modify one of these scripts to suit your needs: https://kb.logicmachine.net/scripting/staircase-timer/ https://forum.logicmachine.net/showthread.php?tid=5664&pid=36530#pid36530 https://forum.logicmachine.net/showthread.php?tid=5700&pid=36717#pid36717 RE: Timer - How to improve - Fcs - 19.12.2024 Thanks you, I was able to do what I wanted |