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

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:

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

Post 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
}
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: How to combine two script (on and off) based on active timer

Post 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
}
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: How to combine two script (on and off) based on active timer

Post by pvklink »

yesssss, it works!
i can kill lots of blockly scripts now!
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
pvklink
Posts: 822
Joined: Wednesday 12 November 2014 15:01
Target OS: Raspberry Pi / ODroid
Domoticz version: latest b
Contact:

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

Post 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?
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: How to combine two script (on and off) based on active timer  [Solved]

Post 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.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest