Page 1 of 1

Run script 10 sec after device changed

Posted: Wednesday 23 October 2019 21:03
by HFman
It seems that DZvents sometimes already trigger a script on device change BEFORE domoticz has already updated the value of the device.

In my case i run a script to see the gasflow, so in case when it misses the updated value i get a zero, and the next update a double value.

So i look for a way that i can let a script run 10 sec AFTER it is trigger on a device change e.g.:

return {
on = {
devices = { 'Gas', after 10 sec }
},

Without having Domoticz stalled for 10 sec because it wait for the script....

Re: Run script 10 sec after device changed

Posted: Wednesday 23 October 2019 22:26
by elmortero
Have a look at the dzVents wiki.
Look for afterSec

Re: Run script 10 sec after device changed

Posted: Wednesday 23 October 2019 23:00
by BOverdevest
Look for afterSec
This will only work on a switch.

So, maybe use it a inbetween helper switch?
So use switchOn().AfterSec(10) to turn on a switch when the value you monitor changes
then use a 2nd event triggered by the helper switch?

[EDIT] see below, indeed a delay route via Uservariable is a cleaner solution vs adding another device

Re: Run script 10 sec after device changed

Posted: Wednesday 23 October 2019 23:06
by waaren
HFman wrote: Wednesday 23 October 2019 21:03 It seems that DZvents sometimes already trigger a script on device change BEFORE domoticz has already updated the value of the device.
Without having Domoticz stalled for 10 sec because it wait for the script....
I never saw this. Can you show me the script and the domoticz log of an example and the version where you see this ? Maybe there is something else causing this.

You cannot code a delayed reaction to a device update in the on section. With a delayedURL function you can do this
[EDIT] or indeed using a helper uservariable of device like @BOverdevest suggests

Code: Select all

-- Delayed Gas

local scriptVar = "delayedGas"

return {
    on      =   {   
                    devices      =      { 'Gas' },
                    httpResponses   =   { scriptVar },
                },

    logging =   {   
                    level     =   domoticz.LOG_DEBUG,
                    marker    =   scriptVar    
                },

    execute = function(dz, item)

        local function delayedURL(delay, callback, logMessage)
            callback = callback or scriptVar
            logMessage = dz.utils.urlEncode(logMessage or scriptVar)
            delay = delay or 60

            local  url= dz.settings['Domoticz url'] .. "/json.htm?type=command&param=addlogmessage&message=" .. logMessage
            dz.openURL({    
                            url = url,
                            method = "GET",
                            callback = callback 
                      }).afterSec(delay)                      
        end

        if item.isDevice then
            delayedURL(10)
        else
            dz.log('The value of Gas: ' .. dz.devices('Gas').sValue )
        end
    end
}

Re: Run script 10 sec after device changed

Posted: Thursday 24 October 2019 20:14
by HFman
Yes.. this is the way to go.. I will try and check if it solves my flow issues (0 or double valvue)