property of active timer(name)

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:

property of active timer(name)

Post by pvklink »

Does dzvents has a property for the active timer, by example: Tuinirrigatie_gazon instead of the value of this timer

I like to shorten my script, by replacing all the IF ELSIF END by:
something like dz.devices(item.name).switchOn().checkFirst()
item.name must be: ' Tuinirrigatie_gazon' for example

Code: Select all

--local Tuinirrigatie_border_links        = 'at 19:00 on mon,tue,wed,thu,fri,sat,sun'
local Tuinirrigatie_border_rechts       = 'at 19:15 on mon,tue,wed,thu,fri,sat,sun'
local Tuinirrigatie_gazon               = 'at 20:05 on mon,tue,wed,thu,fri,sat,sun'
--local Tuinirrigatie_planten            = 'at 19:45 on mon,tue,wed,thu,fri,sat,sun'

return {
	on =    {timer = {Tuinirrigatie_border_links,Tuinirrigatie_border_rechts,Tuinirrigatie_gazon,Tuinirrigatie_planten}},
        
    logging =   { level   = domoticz.LOG_DEBUG ,                  
                  marker  = "Timers irrigatie"},
              
    execute = function(dz,item,info)

    if (item.trigger == Tuinirrigatie_border_links) then
        dz.devices('Tuinirrigatie_border_links').switchOn().checkFirst()  
    elseif (item.trigger == Tuinirrigatie_border_rechts) then
        dz.devices('Tuinirrigatie_border_rechts').switchOn().checkFirst()  
    elseif (item.trigger == Tuinirrigatie_gazon) then
        dz.devices('Tuinirrigatie_gazon').switchOn().checkFirst()  
    elseif (item.trigger == Tuinirrigatie_planten) then
        dz.devices('Tuinirrigatie_planten').switchOn().checkFirst()  
    end        

    dz.log("Script: " .. info.scriptName .. " is aangezet ", dz.LOG_INFO)

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: property of active timer(name)

Post by waaren »

pvklink wrote: Wednesday 10 April 2019 20:12 Does dzvents has a property for the active timer, by example: Tuinirrigatie_gazon instead of the value of this timer
No, the timer is a type String value. In your example contained in a local user variable.

but.. if you declare this user variable without preceding it with 'local ' it becomes a global user variable and as such part of the '_G' Global table.
Using this Global table you can access the variable names and contents.

This is not considered good programming for more then one reason but it can be done. See below script for an example.

Code: Select all

  
Tuinirrigatie_border_links    = 'at 09:02 on mon,tue,wed,thu,fri,sat,sun'
Tuinirrigatie_border_rechts   = 'at 09:03 on mon,tue,wed,thu,fri,sat,sun'
Tuinirrigatie_gazon           = 'at 08:56 on mon,tue,wed,fri,sat,sun'
Tuinirrigatie_planten         = 'at 08:58'

return {	
			on =    {
						timer = {
									Tuinirrigatie_border_links,
									Tuinirrigatie_border_rechts,
									Tuinirrigatie_gazon,
									Tuinirrigatie_planten
								}
					},
        
    logging =   { level   = domoticz.LOG_DEBUG ,                  
                  marker  = "Timers irrigatie"},
              
    execute = function(dz, item)
		
        local function getActiveTimerVarName()
            local counterG, counterF = 0,0
            for k,v in pairs(_G) do
                counterG = counterG + 1
                if tostring(v):find("at ") == 1 then 
                    counterF = counterF + 1
                    if dz.time.matchesRule(v) then
                        dz.log("Variable " .. k .. " is used as time trigger",dz.LOG_DEBUG)
                        dz.log(counterG .. " entries in _G considered",dz.LOG_DEBUG)
                        dz.log(counterF .. " vars starting with 'at ' found",dz.LOG_DEBUG)    
                        return k
                    end
                end
            end
            
        end 
        
        dz.devices(getActiveTimerVarName()).switchOn()
    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: property of active timer(name)

Post by pvklink »

Thanks, still learning!
After all your help, you have to see how all my devices(cams, alarms, x10, rfx, zwave, smoke/watersensors, switches, audio, chromecast, google home, weather comes together with dashtics.
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