question about timers

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

Moderator: leecollings

Post Reply
pvklink
Posts: 822
Joined: Wednesday 12 November 2014 15:01
Target OS: Raspberry Pi / ODroid
Domoticz version: latest b
Contact:

question about timers

Post by pvklink »

I have a question about timers.

When a switch is on for x minutes or must be set to off after x minutes, are these timers deleted when the same switch is manually set to off?

I have a switch hetregent which is set for a period of time and if in the period of time a sensor get's a new signal that it is raining the switch hetregent must be set to on for the new/latest period of time and the old period must be deleted.

Code: Select all


return {
    on      =    {devices = {'$tuinwatersensor'}},

    logging =   { 
                    level   = domoticz.LOG_DEBUG ,                  -- Uncomment to override the dzVents global logging setting
                    marker  = "Watermeting" 
                },
              
    data    =   {
                    raintable = { history = true,  maxHours = 1 },
                },
        
    execute = function(dz, device, info)
        
        local switch        = dz.devices('hetregent')

        local norm          = 5
        local DurTimer      = 800
        local huidwaarde    = device.state 
        local now           = os.time(os.date('*t'))      

        if huidwaarde == nil then               -- onderstaande checks moeten na de locals omdat ze deze ook gebruiken!
            dz.log("01 Sensor info         = Geen waarde opgehaald")
        else
            dz.data.raintable.add(huidwaarde)
        end

        local aantal = 0
        for i = dz.data.raintable.size,1,-1 do 
            aantal = aantal +1
            item = dz.data.raintable.get(i)
            dz.log("00 History data van " .. item.time.rawDate .. " " .. item.time.rawTime .. 
                                    " = " .. item.data)
        end

        dz.log("Deviceinfo---------------------------------------")
        dz.log("00 Sensor...........................= " .. device.name)
        dz.log("00 Switch-device....................= " .. switch.name)
        dz.log("00 Uitzetten.na(in.min).............= " .. DurTimer)
        dz.log("Sensor info-------------------------------------")
        dz.log("00 Aantal.norm......................= " .. norm)
        dz.log("00 Aantal gemeten...................= " .. aantal)
        dz.log("00 Aantal.huidige waarde............= " .. huidwaarde)
        dz.log("00 Notificatie.switch.laatste update= " .. tostring(switch.lastUpdate.rawTime)) -- deze is goed
        dz.log("-------------------------------------------------")

    if  aantal >= norm  then 

        if switch.state == 'Off' then
            switch.switchOn()
            switch.switchOff().afterMin(DurTimer)
        else
            switch.switchOff()
            switch.switchOn()
            switch.switchOff().afterMin(DurTimer)
        end

        dz.log('Script: ' .. info.scriptName .. ' Regendruppel signalen (' .. aantal .. ') is gelijk of boven de norm(' .. norm .. '), ' .. switch.name .. ' wordt geactiveerd voor ' .. tostring(DurTimer) .. ' Minuten ', dz.LOG_INFO)

    end

end
}
Raspberry (raspbian on rpi 3) , Domoticz Beta, dzVents , RFXtrx433e, P1, Hue, Yeelight, Zwave+, X10, ESP(easy), MQTT,Weather Underground, System Alive Checker, Domoticz Remote Server to RPI with Google Assistant,
Jablotron connection, Ikea
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: question about timers

Post by waaren »

pvklink wrote: Sunday 05 May 2019 11:03 When a switch is on for x minutes or must be set to off after x minutes, are these timers deleted when the same switch is manually set to off?
No, timer is not deleted by the On or Off commands. Use cancelQueuedCommands for that.
New code snippet would then look like:

Code: Select all

  if  aantal >= norm  then 
       switch.cancelQueuedCommands()
       switch.switchOn().checkFirst()
       switch.switchOff().afterMin(DurTimer)
        dz.log('Script: ' .. info.scriptName .. ' Regendruppel signalen (' .. aantal .. ') is gelijk of boven de norm(' .. norm .. '), ' .. switch.name .. ' wordt geactiveerd voor ' .. tostring(DurTimer) .. ' Minuten ', dz.LOG_INFO)
   end
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
pvklink
Posts: 822
Joined: Wednesday 12 November 2014 15:01
Target OS: Raspberry Pi / ODroid
Domoticz version: latest b
Contact:

Re: question about timers

Post by pvklink »

@waaren: your change works perfect!
thanks again!

My irrigationprogram is stopped now when:
Local weather is 'rain' or
my watersensor measures water...

good for the environment!
Raspberry (raspbian on rpi 3) , Domoticz Beta, dzVents , RFXtrx433e, P1, Hue, Yeelight, Zwave+, X10, ESP(easy), MQTT,Weather Underground, System Alive Checker, Domoticz Remote Server to RPI with Google Assistant,
Jablotron connection, Ikea
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest