Page 1 of 1

How to combine two script (on and off) based on active timer

Posted: Friday 18 January 2019 11:25
by pvklink
Hi,

How do i combine two scripts (group on and off) based on the active timer?
I like to switch the group on when timer 0 is active and when the other timers are active i like to switch it off.
I think a got all the rules and only need:
- an correction in my script to get the current timer
- my script does not execute

Code: Select all

local trigger0    = "at 12:00 on mon,tue,wed,thu,fri,sat, sun" -- for testing 
local trigger1    = "15 minutes before sunset on mon,tue,wed,thu,fri,sat,sun"
local trigger2    = "at 23:00 on mon,tue,wed,thu,sun"
local trigger3    = "at 23:45 on fri,sat"

return {
	on =  {
    timer = {
            trigger0,
            trigger1,
            trigger2,
            trigger3
            }},
        
    logging =   { level   = domoticz.LOG_DEBUG ,                  -- Uncomment to override the dzVents global logging setting
                  marker  = "Timers"},
              
    execute = function(dz,device, triggerInfo)
    local scriptnaam= 'DZ_avond_start' -- kan dit niet automatisch?
    --local activetimer= triggerInfo.trigger -- is this the active timertrigger ?
    local activetimer= device.trigger -- is this the active timertrigger ?

    if activetimer ~= trigger0 then                                -- als activetimer contains sunset then on
    	dz.groups('Sfeerverlichting').switchOn()
	    dz.groups('Buiten_sfeerverlichting').switchOn()
	else
    	dz.groups('Sfeerverlichting').switchOff()
	    dz.groups('Buiten_sfeerverlichting').switchOff()
	end
    dz.log("Script: " .. scriptnaam .. " groepen wordt uitgevoerd....", dz.LOG_INFO)

end
}

Re: How to combine two script (on and off) based on active timer

Posted: Friday 18 January 2019 13:00
by waaren
pvklink wrote: Friday 18 January 2019 11:25 How do i combine two scripts (group on and off) based on the active timer?
I like to switch the group on when timer 0 is active and when the other timers are active i like to switch it off.
I think a got all the rules and only need:
- an correction in my script to get the current timer
- my script does not execute
Try it with this (based on your initial code)

Code: Select all

local groupOnTimer      = '15 minutes before sunset on mon,tue,wed,thu,fri,sat,sun'
local groupOffTimer1    = 'at 23:00 on mon,tue,wed,thu,sun'
local groupOffTimer2    = 'at 23:45 on fri,sat'

return {
	on =    {
                timer = {
                            groupOnTimer , groupOffTimer1, groupOffTimer2  
                        }   
            },
        
    logging =   { level   = domoticz.LOG_DEBUG ,                  -- Uncomment to override the dzVents global logging setting
                  marker  = "Timers"},
              
    execute = function(dz,item,info)

        if item.trigger == groupOnTimer then                                -- als activetimer contains sunset then on
            dz.groups('Sfeerverlichting').switchOn()
            dz.groups('Buiten_sfeerverlichting').switchOn()
        else
            dz.groups('Sfeerverlichting').switchOff()
            dz.groups('Buiten_sfeerverlichting').switchOff()
        end
        dz.log("Script: " .. info.scriptName .. " groepen wordt uitgevoerd....", dz.LOG_INFO)

end
}

Re: How to combine two script (on and off) based on active timer

Posted: Friday 18 January 2019 13:10
by pvklink
yesssss, it works!
i can kill lots of blockly scripts now!

Re: How to combine two script (on and off) based on active timer

Posted: Friday 18 January 2019 13:22
by pvklink
Is it better to use
between 23:00 and 23:05 on mon,tue,wed,thu,sun
instead of
at 23:00 on mon,tue,wed,thu,sun

When my controldevice misses this script at 23:00 ?
Does the group will be set to on or off more than once in that case?

Re: How to combine two script (on and off) based on active timer  [Solved]

Posted: Friday 18 January 2019 13:28
by waaren
pvklink wrote: Friday 18 January 2019 13:22 Is it better to use
between 23:00 and 23:05 on mon,tue,wed,thu,sun
instead of
at 23:00 on mon,tue,wed,thu,sun

When my controldevice misses this script at 23:00 ?
Does the group will be set to on or off more than once in that case?
I never experienced that dzVents missed a time trigger yet. But as always YMMV.