Page 1 of 1

Ignore repeated Z-Wave updates?

Posted: Tuesday 07 May 2019 15:39
by doh
I have a script that is triggered on change/update of a Z-Wave device. However, for some reason (that I've never managed to resolve) Z-Wave sends multiple updates, which triggers the script multiple times - e.g.

Code: Select all

2019-05-07 14:33:34.786 (ZWave) Temp + Humidity (Cabin sensor temp humid)
2019-05-07 14:33:34.791 (ZWave) Temp + Humidity (Cabin sensor temp humid)
2019-05-07 14:33:34.873 (ZWave) Temp + Humidity (Cabin sensor temp humid)
2019-05-07 14:33:34.877 (ZWave) Temp + Humidity (Cabin sensor temp humid)
2019-05-07 14:33:35.079 Status: dzVents: Info: CabinTempUpdate: ------ Start external script: CabinTempUpdate.lua: Device: "Cabin sensor temp humid (ZWave)", Index: 241
2019-05-07 14:33:35.317 Status: dzVents: Info: CabinTempUpdate: ------ Start external script: CabinTempUpdate.lua: Device: "Cabin sensor temp humid (ZWave)", Index: 241
2019-05-07 14:33:35.541 Status: dzVents: Info: CabinTempUpdate: ------ Start external script: CabinTempUpdate.lua: Device: "Cabin sensor temp humid (ZWave)", Index: 241
2019-05-07 14:33:35.789 Status: dzVents: Info: CabinTempUpdate: ------ Start external script: CabinTempUpdate.lua: Device: "Cabin sensor temp humid (ZWave)", Index: 241
How could I get the Z-Wave script to ignore the repeated updates or just exit?

Thanks

Re: Ignore repeated Z-Wave updates?  [Solved]

Posted: Tuesday 07 May 2019 16:53
by waaren
doh wrote: Tuesday 07 May 2019 15:39 I have a script that is triggered on change/update of a Z-Wave device. However, for some reason (that I've never managed to resolve) Z-Wave sends multiple updates, which triggers the script multiple times. How could I get the dzVents script to ignore the repeated updates or just exit?
Could be something like

Code: Select all

return {
            on =    {   devices =    { 35 }},   -- idx or "name"of trigger device
                   
        logging =   {   level     =   domoticz.LOG_ERROR,
                        marker    =   "Ignore multiple calls"   },

        data    = { lastUsed = { initial = {}}},
        
    execute = function(dz, item)
         
        local function shouldScriptStop(id, minTimeBetweenExecution)
            if dz.data.lastUsed[id] then
                return ( tonumber(dz.data.lastUsed[id]) > ( dz.time.dDate - minTimeBetweenExecution ) )
            end
        end

        -- Check if script should continue
        if shouldScriptStop(item.id, 2) then  -- 2 is the amount of seconds that script need to ignore repeated calls. Change to the value you need 
            dz.log("Script will not continue",dz.LOG_FORCE )
            return
        else
            dz.data.lastUsed[item.idx] = dz.time.dDate
        end 
        
        -- payload of script
        dz.log("Script will do something useful now" ,dz.LOG_FORCE)
        
    end
}

Re: Ignore repeated Z-Wave updates?

Posted: Wednesday 08 May 2019 11:43
by doh
That's perfect - thank you!