This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

Timer - How to improve
#1
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
 
end
Reply
#2
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() - time
Reply
#3
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?
Reply
#4
You can modify one of these scripts to suit your needs:
https://kb.logicmachine.net/scripting/staircase-timer/
https://forum.logicmachine.net/showthrea...0#pid36530
https://forum.logicmachine.net/showthrea...7#pid36717
Reply
#5
Thanks you, I was able to do what I wanted
Reply


Forum Jump: