Page 2 of 2

Re: 'General purpose' timers

Posted: Saturday 30 June 2018 15:19
by ash77
@Andyf66,
I like your idea. I think it could be further simplified to something like:

Code: Select all

on = {
    devices = {
      'Stairs Motion'
    }
  },

    execute = function(dz)
        -- Must be the motion sensor...
        domoticz.runInMins(5, function(dz)
            -- Execute my 5 minute tasks
        )
        domoticz.runInMins(10, function(dz)
            -- Execute my 10 minute tasks
        )
    end
This moves the new 'event' into the scripting engine and just exposes a callback to a lamba after a specified amount of time.

Re: 'General purpose' timers

Posted: Saturday 30 June 2018 22:57
by Andyf66
ash77 wrote: Saturday 30 June 2018 15:19 @Andyf66,
I like your idea. I think it could be further simplified to something like:


This moves the new 'event' into the scripting engine and just exposes a callback to a lamba after a specified amount of time.
Yep, even better. Was hoping that kind of construct was available but my Lua knowledge is basic at best.

Re: 'General purpose' timers

Posted: Sunday 01 July 2018 8:24
by dannybloe
No, that's not possible like this. dzVents doesn't have any state between script runs. It is started by Domoticz and when it is finished there is nothing that keeps running. So your delayed function doesn't live on when the script is finished (and the scope with all your variables is gone too). No, the only way this could happen is by making a round-trip through Domoticz. Just like with httpRequests.