Ignore repeated Z-Wave updates?  [Solved]

Easy to use, 100% Lua-based event scripting framework.

Moderator: leecollings

Post Reply
doh
Posts: 82
Joined: Monday 01 December 2014 13:28
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: London, UK
Contact:

Ignore repeated Z-Wave updates?

Post 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
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

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

Post 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
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
doh
Posts: 82
Joined: Monday 01 December 2014 13:28
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: London, UK
Contact:

Re: Ignore repeated Z-Wave updates?

Post by doh »

That's perfect - thank you!
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest