question about dzvents / myscript  [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:

question about dzvents / myscript

Post by pvklink »

Hi i have a question about dzvents / myscript.
This is THE script that manage all my events, so very important (and it works more then perfect).
And now my situation, in the corona-period, some events are outdated.
for example when a event like "local timer_opstaan_on1" is not active for a certain time i like to disable it.
What is the best way to do this in my script,
by disabling with the local timer with -- signs or something else ?
I can imagine that when adding -- to a timer, the on statement has problems with an non-existent timer...

Code: Select all

-- dit script bevat de timers voor de Schakelgroepen
-- motion aan uit in verschillende scripts...nakijken .
-- motion 10 seconds timeout omdat nas niet beschikbaar is?

--------------------------------------------------------------------------------------------------------------------------------------------------
local timer_avond_huis_on   = '25 minutes before sunset on mon,tue,wed,thu,fri,sat,sun'         -- AVOND HUIS SFEERVERLICHTING AAN hele week
local timer_avond_tuin_on   = '15 minutes after sunset on mon,tue,wed,thu,fri,sat,sun'          -- AVOND TUIN SFEERVERLICHTING AAN hele week

local timer_avond_huis_off1 = 'at 23:00 on mon,tue,wed,thu,sun'                                 -- AVOND SFEERVERLICHTING UIT werkw
local timer_avond_huis_off2 = 'at 23:45 on fri,sat'                                             -- AVOND SFEERVERLICHTING UIT weekend
--------------------------------------------------------------------------------------------------------------------------------------------------
local timer_slapen_on1      = 'at 23:05 on mon,tue,wed,thu,sun'                                 -- SLAPEN AAN werkw
local timer_slapen_on2      = 'at 23:50 on fri,sat'                                             -- SLAPEN AAN weekend

local timer_check           = 'at 24:00 on mon,tue,wed,thu,fri,sat,sun'                         -- CHECKS UITVOEREN

local timer_slapen_off1     = 'at 06:08 on mon,tue,thu,fri'                                     -- SLAPEN UIT werkw peter
local timer_slapen_off2     = 'at 07:08 on mon,tue,wed,thu,fri'                                 -- SLAPEN UIT werkw MO
local timer_slapen_off3     = 'at 08:55 on sat,sun'                                             -- SLAPEN UIT weekend
--------------------------------------------------------------------------------------------------------------------------------------------------
--local timer_opstaan_on1     = 'at 06:10 on mon,tue,thu,fri'                                     -- OPSTAAN AAN werkw peter
local timer_opstaan_on2     = 'at 07:10 on mon,tue,wed,thu,fri'                                 -- OPSTAAN AAN werkw mo
local timer_opstaan_on3     = 'at 09:00 on sat,sun'                                             -- OPSTAAN AAN weekend

--local timer_opstaan_off1    = 'at 06:15 on mon,tue,thu,fri'                                     -- OPSTAAN EINDE werkw peter  
local timer_opstaan_off2    = 'at 07:25 on mon,tue,wed,thu,fri'                                 -- OPSTAAN EINDE werkw mo
local timer_opstaan_off3    = 'at 09:15 on sat,sun'                                             -- OPSTAAN EINDE weekend
--------------------------------------------------------------------------------------------------------------------------------------------------
local timer_zon_on          = '2 minutes after sunrise on mon,tue,wed,thu,fri,sat,sun'          -- ZON OP 

local timer_zon_off         = '2 minutes after sunset on mon,tue,wed,thu,fri,sat,sun'           -- ZON ONDER
--------------------------------------------------------------------------------------------------------------------------------------------------
local timer_ontbijten_on1   = 'at 06:13 on mon,tue,thu,fri'                                     -- ONTBIJTEN AAN werkw PETER
local timer_ontbijten_on2   = 'at 07:20 on mon,tue,wed,thu,fri'                                 -- ONTBIJTEN AAN werkw MO
local timer_ontbijten_on3   = 'at 09:20 on sat,sun'                                             -- ONTBIJTEN AAN WEEKEND

local timer_ontbijten_off1  = 'at 06:44 on mon,tue,thu,fri'                                     -- ONTBIJTEN UIT werkw PETER
local timer_ontbijten_off2  = 'at 08:00 on mon,tue,wed,thu,fri'                                 -- ONTBIJTEN UIT werkw MO
local timer_ontbijten_off3  = 'at 11:00 on sat,sun'                                             -- ONTBIJTEN UIT WEEKEND
--------------------------------------------------------------------------------------------------------------------------------------------------
local timer_rolluik_omhoog1 = 'at 09:00 on mon,tue,wed,thu,fri'                                 -- ZONWERING OMHOOG werkweek NIELS (geen vakantie)
local timer_rolluik_omhoog2 = 'at 11:00 on mon,tue,wed,thu,fri'                                 -- ZONWERING OMHOOG werkweek NIELS (vakantie)
local timer_rolluik_omhoog3 = 'at 11:00 on sat,sun'                                             -- ZONWERING OMHOOG weekend NIELS (geen vakantie)

local timer_rolluik_omlaag1 = 'at 13:00 on mon,tue,wed,thu,fri,sat,sun'                         -- ZONWERING OMLAAG iedere dag NIELS deze niet als t buiten koud is
local timer_rolluik_omlaag2 = 'at sunset on mon,tue,wed,thu,fri,sat,sun'                        -- ZONWERING OMLAAG iedere dag NIELS 
--------------------------------------------------------------------------------------------------------------------------------------------------
local Timer_dellog          = 'at 10:00 on mon,wed,fri,sun'                                     -- SCHONEN VAN DE LOGFILE

return {
    on = {  timer = {timer_avond_huis_on, timer_avond_tuin_on, timer_slapen_on1, timer_slapen_on2, timer_check, timer_opstaan_on1, timer_opstaan_on2, timer_opstaan_on3, timer_zon_on, timer_ontbijten_on1, timer_ontbijten_on2, timer_ontbijten_on3, 
            timer_rolluik_omhoog1,timer_rolluik_omhoog2,timer_rolluik_omhoog3,timer_avond_huis_off1, timer_avond_huis_off2, timer_slapen_off1, timer_slapen_off2, timer_slapen_off3, timer_opstaan_off1, timer_opstaan_off2, timer_opstaan_off3, timer_zon_off, timer_ontbijten_off1, 
            timer_ontbijten_off2, timer_ontbijten_off3,timer_rolluik_omlaag1,timer_rolluik_omlaag2,Timer_dellog,}
        },
        
    logging =   { 
                level   = domoticz.LOG_ERROR,                 
                },
              
    execute = function(dz,item,info)
    _G.logMarker = _G.moduleLabel -- marker wordt scriptnaam, _G.logMarker = info.scriptName is idem

    local messageTable = {}

    -- HIER START DE EXECUTIE 
       
    if  (dz.devices('Schakelklok').state == 'uit') then                                                                              -- GEEN SCHAKELINGEN
        dz.helpers.globalMessage2(dz,item,info,messageTable,'add', ' SCHAKELKLOK: staat UIT, er worden geen automatische schakelingen uitgevoerd...') 
    elseif  (dz.devices('Schakelklok').state ~= 'uit')  then                         -- WEL autom timer SCHAKELINGEN
    
        if  (item.trigger == timer_avond_huis_on) then                                                                                  -- AVOND HUIS AAN: HUIS sfeerverlichting binnen                                              
                dz.devices('Avond').switchSelector('huis')

        elseif  (item.trigger == timer_avond_tuin_on) then                                                                              -- AVOND TUIN AAN: TUIN sfeerverlichting buiten
                dz.devices('Avond').switchSelector('tuin')

        elseif  (item.trigger == timer_slapen_off1 or item.trigger == timer_slapen_off2 or item.trigger == timer_slapen_off3) then      -- SLAPEN UIT
                dz.devices('Slapen').switchOff()

        elseif (item.trigger == timer_opstaan_off1 or item.trigger == timer_opstaan_off2 or item.trigger == timer_opstaan_off3) then        -- OPSTAAN UIT
                dz.devices('Opstaan').switchOff()

        elseif (item.trigger == timer_ontbijten_off1 or item.trigger == timer_ontbijten_off2 or item.trigger == timer_ontbijten_off3) then  -- ONTBIJTEN UIT
                dz.devices('Ontbijten').switchOff()

        elseif  (item.trigger == timer_zon_on) then                                                                                     -- ZON OP
                dz.devices('Zon op').switchOn()

        elseif  (item.trigger == timer_zon_off) then                                                                                    -- ZON ONDER
                dz.devices('Zon op').switchOff()

        elseif  (item.trigger    == Timer_dellog) then                                                                                  -- CLEAN LOG
                dz.devices('clear_log').switchOn()

        elseif  (item.trigger    == timer_check) then                                                                                  -- CHECK STUFF
                if dz.time.isNightTime then
                    if  (dz.devices('Zon op').state == 'On') then  
                        dz.devices('Zon op').switchOff()
                        dz.helpers.globalMessage2(dz,item,info,messageTable,'add', ' SCHAKELKLOK: CHECK, status ZON OP klopt niet: is aangepast!...') 
                    end
                else -- daytime
                    if  (dz.devices('Zon op').state == 'Off') then  
                        dz.devices('Zon op').switchOn()
                        dz.helpers.globalMessage2(dz,item,info,messageTable,'add', ' SCHAKELKLOK: CHECK, status ZON OP klopt niet: is aangepast!...') 
                    end
                end
        elseif  (item.trigger == timer_rolluik_omhoog1 or item.trigger == timer_rolluik_omhoog2 or item.trigger == timer_rolluik_omhoog3) then      -- ZONWERING OMHOOG
                
                if      (item.trigger == timer_rolluik_omhoog1 and dz.devices('Schakelklok').state ~= 'vakantie')   then                                                              
                    dz.devices('Niels rolluik').switchOff()
                elseif  (item.trigger == timer_rolluik_omhoog2 and dz.devices('Schakelklok').state == 'vakantie')   then                                                              
                    dz.devices('Niels rolluik').switchOff()
                elseif  (item.trigger == timer_rolluik_omhoog3)   then                                                             
                    dz.devices('Niels rolluik').switchOff()
                end

        elseif  (item.trigger == timer_rolluik_omlaag1) then 
                grenstmp_zonwering = 18     -- als het boven deze temp is mag t rolluik in de middag omlaag om hitte te voorkomen
                huidigtmp = dz.devices('Strijp_temp').temperature

                if huidigtmp > grenstmp_zonwering then
                    dz.devices('Niels rolluik').switchOn()
	            end

        elseif  (item.trigger == timer_rolluik_omlaag2) then      
                dz.devices('Niels rolluik').switchOn()

        end
        
        if  (dz.devices('Schakelklok').state == 'visite')   then                                                                    -- VISITE
            dz.helpers.globalMessage2(dz,item,info,messageTable,'add', ' SCHAKELKLOK: staat op VISITE, er worden beperkt automatische schakelingen uitgevoerd...') 

        else                                                                                                                            -- ALS ER GEEN VISITE IS DAN GEWOON AVONDVERLICHTING UIT EN SLAPEN AAN 
            dz.helpers.globalMessage2(dz,item,info,messageTable,'add', ' SCHAKELKLOK: staat op AUTOMATISCH, er worden automatische schakelingen uitgevoerd...') 
    
            if  (item.trigger == timer_avond_huis_off1 or item.trigger == timer_avond_huis_off2) then                                   -- AVOND UIT:
                dz.devices('Avond').switchSelector('uit')

            elseif  (item.trigger == timer_slapen_on1 or item.trigger == timer_slapen_on2) then                                         -- SLAPEN AAN
                dz.devices('Slapen').switchOn()
            end

        end

        if  (dz.devices('Thuis').state == 'On') then                                                                                            -- HUIS VAN ALARM AF, ER IS IEMAND THUIS

            if (item.trigger == timer_opstaan_on1 or item.trigger == timer_opstaan_on2 or item.trigger == timer_opstaan_on3) then               -- OPSTAAN AAN en GEEN VAKANTIE
                    dz.devices('Opstaan').switchOn()

            elseif (item.trigger == timer_ontbijten_on1 or item.trigger == timer_ontbijten_on2 or item.trigger == timer_ontbijten_on3) then     -- ONTBIJTEN AAN als iemand thuis en zon onder ....
                if dz.devices('Zon op').state == 'Off' and (dz.devices('Schakelklok').state ~= 'vakantie') then                                 -- zon is nog niet op en geen vakantie !                                                                 -- CHECK ZON OP/ONDER
                        dz.devices('Ontbijten').switchOn()

                else
                        --globalMessage(add, ' ONTBIJTEN wordt niet uitgevoerd, de zon is op ....',logcode) 
                        dz.helpers.globalMessage2(dz,item,info,messageTable,'add', ' ONTBIJTEN wordt niet uitgevoerd, de zon is op of vakantie staat aan....') 
    
                end
            end
        else                                                                                                                        -- HUIS OP ALARM, ER IS NIEMAND THUIS
            dz.helpers.globalMessage2(dz,item,info,messageTable,'add', ' OPSTAAN en ONTBIJTEN scripts worden niet uitgevoerd, er is niemand...') 

        end
        
    else -- ONBEKENDE WAARDE
        dz.helpers.globalMessage2(dz,item,info,messageTable,'add', ' SCHAKELKLOK: heeft een onbekende waarde ...') 

    end
    dz.helpers.globalMessage2(dz,item,info,messageTable,'chg')

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
pvklink
Posts: 822
Joined: Wednesday 12 November 2014 15:01
Target OS: Raspberry Pi / ODroid
Domoticz version: latest b
Contact:

Re: question aabout dzvents / myscript

Post by pvklink »

Is something possible like:

1. Timers =
{
{timer_avond_huis_on: '25 minutes before sunset on mon,tue,wed,thu,fri,sat,sun', enabled}
{timer_avond_tuin_off: '15 minutes after sunset on mon,tue,wed,thu,fri,sat,sun',disabled}
}

2. Function get_active_timer (timers)
read array timers and give back all the timers that are enabled
end

3. on = { timer = get_active_timers()}
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 aabout dzvents / myscript

Post by waaren »

pvklink wrote: Monday 11 January 2021 17:55 by disabling with the local timer with -- signs or something else ?
That will work as expected. dzVents will skip all commented timers without issues, even if all are commented.
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 aabout dzvents / myscript

Post by pvklink »

ok! what a great script language ! :-)
is my second solution (on timer with a function also a way to go , or a dummy way...
Just to check if i design good solutions :-)
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 aabout dzvents / myscript

Post by waaren »

pvklink wrote: Monday 11 January 2021 18:45 Is something possible like:
This will work.

Code: Select all

local Timers = 
{
    { 'timer_avond_huis_on' , '25 minutes before sunset on mon,tue,wed,thu,fri,sat,sun', true },
    { 'timer_avond_tuin_off', '15 minutes after sunset on mon,tue,wed,thu,fri,sat,sun', false},          
    { 'allways',   'every minute', true},
}


local function get_active_timers(Timers) 
    local activeTimers = {}
    for _, record in ipairs(Timers) do
        if record[3] == true then
            table.insert(activeTimers, record[2])
        end
    end
    return activeTimers
end

return
{
    on = 
    { 
        timer = get_active_timers(Timers),
    },

    logging = 
    {
        level = domoticz.LOG_DEBUG,
        marker = 'Why do it the easy way'
    },
    
    execute = function(dz, item)
        dz.log(item.trigger,dz.LOG_DEBUG)
    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 aabout dzvents / myscript

Post by pvklink »

I am gonna try that :-)
Case closed :D
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: question aabout dzvents / myscript

Post by pvklink »

hi @waaren
I adjust the script with the functions. No errors ! :-) and it looks great!
But the script does not execute the different timers anymore.
I think that is because the timernames are not there anymore...like
if (item.trigger == timer_zon_on (timer_zon_on) is not there anymore

Can you look at my script and do some advises to make it work and more managable.
I like the fact that i can enable/disable events easy now!

Is it an idea that dzvents can also adress a timer_name during execution. Not only the time data, so that during executing you can use the time, day etc and the timer_id/name. Suppose you have two timed events on the same time with different execution, then an id/name would be helpfull

Code: Select all

-- dit script bevat de timers voor de Schakelgroepen

--------------------------------------------------------------------------------------------------------------------------------------------------
local Timers = 
{
    { 'timer_avond_huis_on','25 minutes before sunset on mon,tue,wed,thu,fri,sat,sun', true },         
    { 'timer_avond_tuin_on','15 minutes after sunset on mon,tue,wed,thu,fri,sat,sun', true },
    { 'timer_avond_huis_off1','at 23:00 on mon,tue,wed,thu,sun', true },  
    { 'timer_avond_huis_off2','at 23:45 on fri,sat', true },                        
    { 'timer_slapen_on1','at 23:05 on mon,tue,wed,thu,sun', true },                               
    { 'timer_slapen_on2','at 23:50 on fri,sat', true },                       
    { 'timer_check','at 24:00 on mon,tue,wed,thu,fri,sat,sun', true },
    { 'timer_slapen_off1','at 06:08 on mon,tue,thu,fri', true },                  
    { 'timer_slapen_off2','at 07:08 on mon,tue,wed,thu,fri', true },                          
    { 'timer_slapen_off3','at 08:55 on sat,sun', true },                     
    { 'timer_opstaan_on1','at 06:10 on mon,tue,thu,fri', false },
    { 'timer_opstaan_on2','at 07:10 on mon,tue,wed,thu,fri', true },                      
    { 'timer_opstaan_on3','at 09:00 on sat,sun', true },                        
    { 'timer_opstaan_off1','at 06:15 on mon,tue,thu,fri', false },
    { 'timer_opstaan_off2','at 07:25 on mon,tue,wed,thu,fri', true },                          
    { 'timer_opstaan_off3','at 09:15 on sat,sun', true },                       
    { 'timer_zon_on','2 minutes after sunrise on mon,tue,wed,thu,fri,sat,sun', true },
    { 'timer_zon_off','2 minutes after sunset on mon,tue,wed,thu,fri,sat,sun', true }, 
    { 'timer_ontbijten_on1','at 06:13 on mon,tue,thu,fri', false },          
    { 'timer_ontbijten_on2','at 07:20 on mon,tue,wed,thu,fri', true },                          
    { 'timer_ontbijten_on3','at 09:20 on sat,sun', true },                       
    { 'timer_ontbijten_off1','at 06:44 on mon,tue,thu,fri', false },                                    
    { 'timer_ontbijten_off2','at 08:00 on mon,tue,wed,thu,fri', true },                          
    { 'timer_ontbijten_off3','at 11:00 on sat,sun', true },                       
    { 'timer_rolluik_omhoog1','at 09:00 on mon,tue,wed,thu,fri', true },
    { 'timer_rolluik_omhoog2','at 11:00 on mon,tue,wed,thu,fri', true },                        
    { 'timer_rolluik_omhoog3','at 11:00 on sat,sun', true },                       
    { 'timer_rolluik_omlaag1','at 13:00 on mon,tue,wed,thu,fri,sat,sun', true },                         
    { 'timer_rolluik_omlaag2','at sunset on mon,tue,wed,thu,fri,sat,sun', true },                
    { 'Timer_dellog','at 10:00 on mon,wed,fri,sun', true },
}
--------------------------------------------------------------------------------------------------------------------------------------------------
local function get_active_timers(Timers) 
    local activeTimers = {}
    for _, record in ipairs(Timers) do
        if record[3] == true then
            table.insert(activeTimers, record[2])
        end
    end
    return activeTimers
end

return {
    on = 
        { 
        timer = get_active_timers(Timers),
        },

    logging =
        { 
        level   = domoticz.LOG_ERROR,                 
        },
              
    execute = function(dz,item,info)
    _G.logMarker = _G.moduleLabel -- marker wordt scriptnaam, _G.logMarker = info.scriptName is idem

    local messageTable = {}

    -- HIER START DE EXECUTIE 
       
    if  (dz.devices('Schakelklok').state == 'uit') then                                                                              -- GEEN SCHAKELINGEN
        dz.helpers.globalMessage2(dz,item,info,messageTable,'add', ' SCHAKELKLOK: staat UIT, er worden geen automatische schakelingen uitgevoerd...') 
    elseif  (dz.devices('Schakelklok').state ~= 'uit')  then                         -- WEL autom timer SCHAKELINGEN
    
        if  (item.trigger == timer_avond_huis_on) then                                                                                  -- AVOND HUIS AAN: HUIS sfeerverlichting binnen                                              
                dz.devices('Avond').switchSelector('huis')

        elseif  (item.trigger == timer_avond_tuin_on) then                                                                              -- AVOND TUIN AAN: TUIN sfeerverlichting buiten
                dz.devices('Avond').switchSelector('tuin')

        elseif  (item.trigger == timer_slapen_off1 or item.trigger == timer_slapen_off2 or item.trigger == timer_slapen_off3) then      -- SLAPEN UIT
                dz.devices('Slapen').switchOff()

        elseif (item.trigger == timer_opstaan_off1 or item.trigger == timer_opstaan_off2 or item.trigger == timer_opstaan_off3) then        -- OPSTAAN UIT
                dz.devices('Opstaan').switchOff()

        elseif (item.trigger == timer_ontbijten_off1 or item.trigger == timer_ontbijten_off2 or item.trigger == timer_ontbijten_off3) then  -- ONTBIJTEN UIT
                dz.devices('Ontbijten').switchOff()

        elseif  (item.trigger == timer_zon_on) then                                                                                     -- ZON OP
                dz.devices('Zon op').switchOn()

        elseif  (item.trigger == timer_zon_off) then                                                                                    -- ZON ONDER
                dz.devices('Zon op').switchOff()

        elseif  (item.trigger    == Timer_dellog) then                                                                                  -- CLEAN LOG
                dz.devices('clear_log').switchOn()

        elseif  (item.trigger    == timer_check) then                                                                                  -- CHECK STUFF
                if dz.time.isNightTime then
                    if  (dz.devices('Zon op').state == 'On') then  
                        dz.devices('Zon op').switchOff()
                        dz.helpers.globalMessage2(dz,item,info,messageTable,'add', ' SCHAKELKLOK: CHECK, status ZON OP klopt niet: is aangepast!...') 
                    end
                else -- daytime
                    if  (dz.devices('Zon op').state == 'Off') then  
                        dz.devices('Zon op').switchOn()
                        dz.helpers.globalMessage2(dz,item,info,messageTable,'add', ' SCHAKELKLOK: CHECK, status ZON OP klopt niet: is aangepast!...') 
                    end
                end
        elseif  (item.trigger == timer_rolluik_omhoog1 or item.trigger == timer_rolluik_omhoog2 or item.trigger == timer_rolluik_omhoog3) then      -- ZONWERING OMHOOG
                
                if      (item.trigger == timer_rolluik_omhoog1 and dz.devices('Schakelklok').state ~= 'vakantie')   then                                                              
                    dz.devices('Niels rolluik').switchOff()
                elseif  (item.trigger == timer_rolluik_omhoog2 and dz.devices('Schakelklok').state == 'vakantie')   then                                                              
                    dz.devices('Niels rolluik').switchOff()
                elseif  (item.trigger == timer_rolluik_omhoog3)   then                                                             
                    dz.devices('Niels rolluik').switchOff()
                end

        elseif  (item.trigger == timer_rolluik_omlaag1) then 
                grenstmp_zonwering = 18     -- als het boven deze temp is mag t rolluik in de middag omlaag om hitte te voorkomen
                huidigtmp = dz.devices('Strijp_temp').temperature

                if huidigtmp > grenstmp_zonwering then
                    dz.devices('Niels rolluik').switchOn()
	            end

        elseif  (item.trigger == timer_rolluik_omlaag2) then      
                dz.devices('Niels rolluik').switchOn()

        end
        
        if  (dz.devices('Schakelklok').state == 'visite')   then                                                                    -- VISITE
            dz.helpers.globalMessage2(dz,item,info,messageTable,'add', ' SCHAKELKLOK: staat op VISITE, er worden beperkt automatische schakelingen uitgevoerd...') 

        else                                                                                                                            -- ALS ER GEEN VISITE IS DAN GEWOON AVONDVERLICHTING UIT EN SLAPEN AAN 
            dz.helpers.globalMessage2(dz,item,info,messageTable,'add', ' SCHAKELKLOK: staat op AUTOMATISCH. Gebeurtenis:' .. item.trigger .. ', wordt uitgevoerd...') 
    
            if  (item.trigger == timer_avond_huis_off1 or item.trigger == timer_avond_huis_off2) then                                   -- AVOND UIT:
                dz.devices('Avond').switchSelector('uit')

            elseif  (item.trigger == timer_slapen_on1 or item.trigger == timer_slapen_on2) then                                         -- SLAPEN AAN
                dz.devices('Slapen').switchOn()
            end

        end

        if  (dz.devices('Thuis').state == 'On') then                                                                                            -- HUIS VAN ALARM AF, ER IS IEMAND THUIS

            if (item.trigger == timer_opstaan_on1 or item.trigger == timer_opstaan_on2 or item.trigger == timer_opstaan_on3) then               -- OPSTAAN AAN en GEEN VAKANTIE
                    dz.devices('Opstaan').switchOn()

            elseif (item.trigger == timer_ontbijten_on1 or item.trigger == timer_ontbijten_on2 or item.trigger == timer_ontbijten_on3) then     -- ONTBIJTEN AAN als iemand thuis en zon onder ....
                --if dz.devices('Zon op').state == 'Off' and (dz.devices('Schakelklok').state ~= 'vakantie') then                                 -- zon is nog niet op en geen vakantie !                                                                 -- CHECK ZON OP/ONDER
                        dz.devices('Ontbijten').switchOn()

                --else
                        --globalMessage(add, ' ONTBIJTEN wordt niet uitgevoerd, de zon is op ....',logcode) 
                   --     dz.helpers.globalMessage2(dz,item,info,messageTable,'add', ' ONTBIJTEN wordt niet uitgevoerd, de zon is op of vakantie staat aan....') 
    
                --end
            end
        else                                                                                                                        -- HUIS OP ALARM, ER IS NIEMAND THUIS
            dz.helpers.globalMessage2(dz,item,info,messageTable,'add', ' OPSTAAN en ONTBIJTEN scripts worden niet uitgevoerd, er is niemand...') 

        end
        
    else 
        dz.helpers.globalMessage2(dz,item,info,messageTable,'add', ' SCHAKELKLOK: heeft een onbekende waarde ...') 

    end
    dz.helpers.globalMessage2(dz,item,info,messageTable,'chg')

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 dzvents / myscript

Post by waaren »

pvklink wrote: Wednesday 13 January 2021 11:05 I adjust the script with the functions. No errors ! :-) and it looks great!
But the script does not execute the different timers anymore.
Below version should work.
Is it an idea that dzVents can also address a timer name during execution. Not only the time data, so that during executing you can use the time, day etc. and the timer id/name. Suppose you have two timed events on the same time with different execution, then an id/name would be helpful
Only one occurrence of the same script will be triggered at the request time. So the situation you describe can only happen with separate scripts. In that case it is quite easy to identify the script with _G.moduleLabel or you could set a local scriptVar.

Code: Select all

-- dit script bevat de timers voor de Schakelgroepen

--------------------------------------------------------------------------------------------------------------------------------------------------
local Timers =
{
    { 'timer_avond_huis_on','25 minutes before sunset on mon,tue,wed,thu,fri,sat,sun', true },
    { 'timer_avond_tuin_on','15 minutes after sunset on mon,tue,wed,thu,fri,sat,sun', true },
    { 'timer_avond_huis_off1','at 23:00 on mon,tue,wed,thu,sun', true },
    { 'timer_avond_huis_off2','at 23:45 on fri,sat', true },
    { 'timer_slapen_on1','at 23:05 on mon,tue,wed,thu,sun', true },   
    { 'timer_slapen_on2','at 23:50 on fri,sat', true },
    { 'timer_check','at 24:00 on mon,tue,wed,thu,fri,sat,sun', true },
    { 'timer_slapen_off1','at 06:08 on mon,tue,thu,fri', true },
    { 'timer_slapen_off2','at 07:08 on mon,tue,wed,thu,fri', true },
    { 'timer_slapen_off3','at 08:55 on sat,sun', true },
    { 'timer_opstaan_on1','at 06:10 on mon,tue,thu,fri', false },
    { 'timer_opstaan_on2','at 07:10 on mon,tue,wed,thu,fri', true },
    { 'timer_opstaan_on3','at 09:00 on sat,sun', true },
    { 'timer_opstaan_off1','at 06:15 on mon,tue,thu,fri', false },
    { 'timer_opstaan_off2','at 07:25 on mon,tue,wed,thu,fri', true },
    { 'timer_opstaan_off3','at 09:15 on sat,sun', true },
    { 'timer_zon_on','2 minutes after sunrise on mon,tue,wed,thu,fri,sat,sun', true },
    { 'timer_zon_off','2 minutes after sunset on mon,tue,wed,thu,fri,sat,sun', true },
    { 'timer_ontbijten_on1','at 06:13 on mon,tue,thu,fri', false },
    { 'timer_ontbijten_on2','at 07:20 on mon,tue,wed,thu,fri', true },
    { 'timer_ontbijten_on3','at 09:20 on sat,sun', true },
    { 'timer_ontbijten_off1','at 06:44 on mon,tue,thu,fri', false },        
    { 'timer_ontbijten_off2','at 08:00 on mon,tue,wed,thu,fri', true },
    { 'timer_ontbijten_off3','at 11:00 on sat,sun', true },
    { 'timer_rolluik_omhoog1','at 09:00 on mon,tue,wed,thu,fri', true },
    { 'timer_rolluik_omhoog2','at 11:00 on mon,tue,wed,thu,fri', true },
    { 'timer_rolluik_omhoog3','at 11:00 on sat,sun', true },
    { 'timer_rolluik_omlaag1','at 13:00 on mon,tue,wed,thu,fri,sat,sun', true },
    { 'timer_rolluik_omlaag2','at sunset on mon,tue,wed,thu,fri,sat,sun', true },
    { 'Timer_dellog','at 10:00 on mon,wed,fri,sun', true },
    { 'Allways','every minute', false }, -- for test
    { 'Never','never', false }, -- for test

}
--------------------------------------------------------------------------------------------------------------------------------------------------
local function get_active_timers(Timers)
    local activeTimers = {}
    for _, record in ipairs(Timers) do
        if record[3] == true then
            table.insert(activeTimers, record[2])
        end
    end
    return activeTimers
end

return {
    on =
        {
        timer = get_active_timers(Timers),
        },

    logging =
        {
        level   = domoticz.LOG_ERROR,
        },

    execute = function(dz,item,info)
    _G.logMarker = _G.moduleLabel -- marker wordt scriptnaam, _G.logMarker = info.scriptName is idem

    local messageTable = {}

    -- HIER START DE EXECUTIE
    for _, record in ipairs(Timers) do
        if record[3] == true and record[2] == item.trigger then
            item.trigger = record[1]
            break
        end
    end

    if  (dz.devices('Schakelklok').state == 'uit') then                                                                              -- GEEN SCHAKELINGEN
        dz.helpers.globalMessage2(dz,item,info,messageTable,'add', ' SCHAKELKLOK: staat UIT, er worden geen automatische schakelingen uitgevoerd...')
    elseif  (dz.devices('Schakelklok').state ~= 'uit')  then                         -- WEL autom timer SCHAKELINGEN

        if  (item.trigger == 'timer_avond_huis_on') then                                                                                  -- AVOND HUIS AAN: HUIS sfeerverlichting binnen                  
                dz.devices('Avond').switchSelector('huis')

        elseif  (item.trigger == 'timer_avond_tuin_on') then                                                                              -- AVOND TUIN AAN: TUIN sfeerverlichting buiten
                dz.devices('Avond').switchSelector('tuin')

        elseif  (item.trigger == 'timer_slapen_off1' or item.trigger == 'timer_slapen_off2' or item.trigger == 'timer_slapen_off3') then      -- SLAPEN UIT
                dz.devices('Slapen').switchOff()

        elseif (item.trigger == 'timer_opstaan_off1' or item.trigger == 'timer_opstaan_off2' or item.trigger == 'timer_opstaan_off3') then        -- OPSTAAN UIT
                dz.devices('Opstaan').switchOff()

        elseif (item.trigger == 'timer_ontbijten_off1' or item.trigger == 'timer_ontbijten_off2' or item.trigger == 'timer_ontbijten_off3') then  -- ONTBIJTEN UIT
                dz.devices('Ontbijten').switchOff()

        elseif  (item.trigger == 'timer_zon_on') then                                                                                     -- ZON OP
                dz.devices('Zon op').switchOn()

        elseif  (item.trigger == 'timer_zon_off') then                                                                                    -- ZON ONDER
                dz.devices('Zon op').switchOff()

        elseif  (item.trigger == 'Timer_dellog') then                                                                                  -- CLEAN LOG
                dz.devices('clear_log').switchOn()

        elseif  (item.trigger == 'timer_check') then                                                                                  -- CHECK STUFF
                if dz.time.isNightTime then
                    if  (dz.devices('Zon op').state == 'On') then
                        dz.devices('Zon op').switchOff()
                        dz.helpers.globalMessage2(dz,item,info,messageTable,'add', ' SCHAKELKLOK: CHECK, status ZON OP klopt niet: is aangepast!...')
                    end
                else -- daytime
                    if  (dz.devices('Zon op').state == 'Off') then
                        dz.devices('Zon op').switchOn()
                        dz.helpers.globalMessage2(dz,item,info,messageTable,'add', ' SCHAKELKLOK: CHECK, status ZON OP klopt niet: is aangepast!...')
                    end
                end
        elseif  (item.trigger == 'timer_rolluik_omhoog1' or item.trigger == 'timer_rolluik_omhoog2' or item.trigger == 'timer_rolluik_omhoog3') then      -- ZONWERING OMHOOG

                if      (item.trigger == 'timer_rolluik_omhoog1' and dz.devices('Schakelklok').state ~= 'vakantie')   then                                  
                    dz.devices('Niels rolluik').switchOff()
                elseif  (item.trigger == 'timer_rolluik_omhoog2' and dz.devices('Schakelklok').state == 'vakantie')   then                                  
                    dz.devices('Niels rolluik').switchOff()
                elseif  (item.trigger == 'timer_rolluik_omhoog3')   then                                 
                    dz.devices('Niels rolluik').switchOff()
                end

        elseif  (item.trigger == 'timer_rolluik_omlaag1') then
                grenstmp_zonwering = 18     -- als het boven deze temp is mag t rolluik in de middag omlaag om hitte te voorkomen
                huidigtmp = dz.devices('Strijp_temp').temperature

                if huidigtmp > grenstmp_zonwering then
                    dz.devices('Niels rolluik').switchOn()
                end

        elseif  (item.trigger == 'timer_rolluik_omlaag2') then
                dz.devices('Niels rolluik').switchOn()

        end

        if  (dz.devices('Schakelklok').state == 'visite')   then                                                                    -- VISITE
            dz.helpers.globalMessage2(dz,item,info,messageTable,'add', ' SCHAKELKLOK: staat op VISITE, er worden beperkt automatische schakelingen uitgevoerd...')

        else                                                                                                                            -- ALS ER GEEN VISITE IS DAN GEWOON AVONDVERLICHTING UIT EN SLAPEN AAN
            dz.helpers.globalMessage2(dz,item,info,messageTable,'add', ' SCHAKELKLOK: staat op AUTOMATISCH. Gebeurtenis:' .. item.trigger .. ', wordt uitgevoerd...')

            if  (item.trigger == 'timer_avond_huis_off1' or item.trigger == 'timer_avond_huis_off2') then                                   -- AVOND UIT:
                dz.devices('Avond').switchSelector('uit')

            elseif  (item.trigger == 'timer_slapen_on1' or item.trigger == 'timer_slapen_on2') then                                         -- SLAPEN AAN
                dz.devices('Slapen').switchOn()
            end

        end

        if  (dz.devices('Thuis').state == 'On') then                                                                                            -- HUIS VAN ALARM AF, ER IS IEMAND THUIS

            if (item.trigger == 'timer_opstaan_on1' or item.trigger == 'timer_opstaan_on2' or item.trigger == 'timer_opstaan_on3') then               -- OPSTAAN AAN en GEEN VAKANTIE
                    dz.devices('Opstaan').switchOn()

            elseif (item.trigger == 'timer_ontbijten_on1' or item.trigger == 'timer_ontbijten_on2' or item.trigger == 'timer_ontbijten_on3') then     -- ONTBIJTEN AAN als iemand thuis en zon onder ....
                --if dz.devices('Zon op').state == 'Off' and (dz.devices('Schakelklok').state ~= 'vakantie') then                                 -- zon is nog niet op en geen vakantie !                                                                 -- CHECK ZON OP/ONDER
                        dz.devices('Ontbijten').switchOn()

                --else
                        --globalMessage(add, ' ONTBIJTEN wordt niet uitgevoerd, de zon is op ....',logcode)
                   --     dz.helpers.globalMessage2(dz,item,info,messageTable,'add', ' ONTBIJTEN wordt niet uitgevoerd, de zon is op of vakantie staat aan....')

                --end
            end
        else                                                                                                                        -- HUIS OP ALARM, ER IS NIEMAND THUIS
            dz.helpers.globalMessage2(dz,item,info,messageTable,'add', ' OPSTAAN en ONTBIJTEN scripts worden niet uitgevoerd, er is niemand...')

        end

    else
        dz.helpers.globalMessage2(dz,item,info,messageTable,'add', ' SCHAKELKLOK: heeft een onbekende waarde ...')

    end
    dz.helpers.globalMessage2(dz,item,info,messageTable,'chg')

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 aabout dzvents / myscript

Post by pvklink »

I tried to solve it myself by adding an extra function to retrieve to eventname from the array, i use Timers again and match this with item.trigger

this part:
local function get_active_timer(Timers,trigger) -- PVK ADDED
local activeTimer = {}
for _, record in ipairs(Timers) do
if record[2] == trigger then
table.insert(activeTimer, record[1])
end
end
return activeTimer
end

-- HIER START DE EXECUTIE

activeTimerx = get_active_timer(Timers,item.trigger)
dz.helpers.globalMessage2(dz,item,info,messageTable,'add', ' SCHAKELKLOK: test activeTimer=' .. activeTimer[1])

but i get an error when showing the value of activeTimer[1]
2021-01-13 12:12:00.280 Error: dzVents: Error: (3.0.19) An error occurred when calling event handler DZ_schakelklok
2021-01-13 12:12:00.280 Error: dzVents: Error: (3.0.19) ...icz/scripts/dzVents/generated_scripts/DZ_schakelklok.lua:78: attempt to index a nil value (global 'activeTimer')
202

Code: Select all


-- dit script bevat de timers voor de Schakelgroepen

--------------------------------------------------------------------------------------------------------------------------------------------------
local Timers = 
{
    { 'timer_avond_huis_on','25 minutes before sunset on mon,tue,wed,thu,fri,sat,sun', true },         
    { 'timer_avond_tuin_on','15 minutes after sunset on mon,tue,wed,thu,fri,sat,sun', true },
    { 'timer_avond_huis_off1','at 23:00 on mon,tue,wed,thu,sun', true },  
    { 'timer_avond_huis_off2','at 23:45 on fri,sat', true },                        
    { 'timer_slapen_on1','at 23:05 on mon,tue,wed,thu,sun', true },                               
    { 'timer_slapen_on2','at 23:50 on fri,sat', true },                       
    { 'timer_check','at 24:00 on mon,tue,wed,thu,fri,sat,sun', true },
    { 'timer_slapen_off1','at 06:08 on mon,tue,thu,fri', true },                  
    { 'timer_slapen_off2','at 07:08 on mon,tue,wed,thu,fri', true },                          
    { 'timer_slapen_off3','at 08:55 on sat,sun', true },                     
    { 'timer_opstaan_on1','at 06:10 on mon,tue,thu,fri', false },
    { 'timer_opstaan_on2','at 07:10 on mon,tue,wed,thu,fri', true },                      
    { 'timer_opstaan_on3','at 09:00 on sat,sun', true },                        
    { 'timer_opstaan_off1','at 06:15 on mon,tue,thu,fri', false },
    { 'timer_opstaan_off2','at 07:25 on mon,tue,wed,thu,fri', true },                          
    { 'timer_opstaan_off3','at 09:15 on sat,sun', true },                       
    { 'timer_zon_on','2 minutes after sunrise on mon,tue,wed,thu,fri,sat,sun', true },
    { 'timer_zon_off','2 minutes after sunset on mon,tue,wed,thu,fri,sat,sun', true }, 
    { 'timer_ontbijten_on1','at 06:13 on mon,tue,thu,fri', false },          
    { 'timer_ontbijten_on2','at 07:20 on mon,tue,wed,thu,fri', true },                          
--    { 'timer_ontbijten_on3','at 09:20 on sat,sun', true },                       
    { 'timer_ontbijten_on3','at 12:03 on mon,tue,wed,thu,fri', true },          --test              
    { 'timer_ontbijten_off1','at 06:44 on mon,tue,thu,fri', false },                                    
    { 'timer_ontbijten_off2','at 08:00 on mon,tue,wed,thu,fri', true },                          
    { 'timer_ontbijten_off3','at 11:00 on sat,sun', true },                       
    { 'timer_rolluik_omhoog1','at 09:00 on mon,tue,wed,thu,fri', true },
    { 'timer_rolluik_omhoog2','at 11:00 on mon,tue,wed,thu,fri', true },                        
    { 'timer_rolluik_omhoog3','at 11:00 on sat,sun', true },                       
    { 'timer_rolluik_omlaag1','at 13:00 on mon,tue,wed,thu,fri,sat,sun', true },                         
    { 'timer_rolluik_omlaag2','at sunset on mon,tue,wed,thu,fri,sat,sun', true },                
    { 'Timer_dellog','at 10:00 on mon,wed,fri,sun', true },
}
--------------------------------------------------------------------------------------------------------------------------------------------------
local function get_active_timers(Timers) 
    local activeTimers = {}
    for _, record in ipairs(Timers) do
        if record[3] == true then
            table.insert(activeTimers, record[2])
        end
    end
    return activeTimers
end

return {
    on = 
        { 
        timer = get_active_timers(Timers),
        },

    logging =
        { 
        level   = domoticz.LOG_ERROR,                 
        },
              
    execute = function(dz,item,info)
    _G.logMarker = _G.moduleLabel -- marker wordt scriptnaam, _G.logMarker = info.scriptName is idem

    local messageTable = {}

    local function get_active_timer(Timers,trigger) -- PVK ADDED
        local activeTimer = {}
        for _, record in ipairs(Timers) do
            if record[2] == trigger then
                table.insert(activeTimer, record[1])
            end
        end
        return activeTimer
    end

    -- HIER START DE EXECUTIE 
    
    activeTimerx = get_active_timer(Timers,item.trigger)
    dz.helpers.globalMessage2(dz,item,info,messageTable,'add', ' SCHAKELKLOK: test activeTimer=' .. activeTimer[1]) 
    
       
    if  (dz.devices('Schakelklok').state == 'uit') then                                                                              -- GEEN SCHAKELINGEN
        dz.helpers.globalMessage2(dz,item,info,messageTable,'add', ' SCHAKELKLOK: staat UIT, er worden geen automatische schakelingen uitgevoerd...') 
    elseif  (dz.devices('Schakelklok').state ~= 'uit')  then                         -- WEL autom timer SCHAKELINGEN
    
        if  (item.trigger == timer_avond_huis_on) then                                                                                  -- AVOND HUIS AAN: HUIS sfeerverlichting binnen                                              
                dz.devices('Avond').switchSelector('huis')

        elseif  (item.trigger == timer_avond_tuin_on) then                                                                              -- AVOND TUIN AAN: TUIN sfeerverlichting buiten
                dz.devices('Avond').switchSelector('tuin')

        elseif  (item.trigger == timer_slapen_off1 or item.trigger == timer_slapen_off2 or item.trigger == timer_slapen_off3) then      -- SLAPEN UIT
                dz.devices('Slapen').switchOff()

        elseif (item.trigger == timer_opstaan_off1 or item.trigger == timer_opstaan_off2 or item.trigger == timer_opstaan_off3) then        -- OPSTAAN UIT
                dz.devices('Opstaan').switchOff()

        elseif (item.trigger == timer_ontbijten_off1 or item.trigger == timer_ontbijten_off2 or item.trigger == timer_ontbijten_off3) then  -- ONTBIJTEN UIT
                dz.devices('Ontbijten').switchOff()

        elseif  (item.trigger == timer_zon_on) then                                                                                     -- ZON OP
                dz.devices('Zon op').switchOn()

        elseif  (item.trigger == timer_zon_off) then                                                                                    -- ZON ONDER
                dz.devices('Zon op').switchOff()

        elseif  (item.trigger    == Timer_dellog) then                                                                                  -- CLEAN LOG
                dz.devices('clear_log').switchOn()

        elseif  (item.trigger    == timer_check) then                                                                                  -- CHECK STUFF
                if dz.time.isNightTime then
                    if  (dz.devices('Zon op').state == 'On') then  
                        dz.devices('Zon op').switchOff()
                        dz.helpers.globalMessage2(dz,item,info,messageTable,'add', ' SCHAKELKLOK: CHECK, status ZON OP klopt niet: is aangepast!...') 
                    end
                else -- daytime
                    if  (dz.devices('Zon op').state == 'Off') then  
                        dz.devices('Zon op').switchOn()
                        dz.helpers.globalMessage2(dz,item,info,messageTable,'add', ' SCHAKELKLOK: CHECK, status ZON OP klopt niet: is aangepast!...') 
                    end
                end
        elseif  (item.trigger == timer_rolluik_omhoog1 or item.trigger == timer_rolluik_omhoog2 or item.trigger == timer_rolluik_omhoog3) then      -- ZONWERING OMHOOG
                
                if      (item.trigger == timer_rolluik_omhoog1 and dz.devices('Schakelklok').state ~= 'vakantie')   then                                                              
                    dz.devices('Niels rolluik').switchOff()
                elseif  (item.trigger == timer_rolluik_omhoog2 and dz.devices('Schakelklok').state == 'vakantie')   then                                                              
                    dz.devices('Niels rolluik').switchOff()
                elseif  (item.trigger == timer_rolluik_omhoog3)   then                                                             
                    dz.devices('Niels rolluik').switchOff()
                end

        elseif  (item.trigger == timer_rolluik_omlaag1) then 
                grenstmp_zonwering = 18     -- als het boven deze temp is mag t rolluik in de middag omlaag om hitte te voorkomen
                huidigtmp = dz.devices('Strijp_temp').temperature

                if huidigtmp > grenstmp_zonwering then
                    dz.devices('Niels rolluik').switchOn()
	            end

        elseif  (item.trigger == timer_rolluik_omlaag2) then      
                dz.devices('Niels rolluik').switchOn()

        end
        
        if  (dz.devices('Schakelklok').state == 'visite')   then                                                                    -- VISITE
            dz.helpers.globalMessage2(dz,item,info,messageTable,'add', ' SCHAKELKLOK: staat op VISITE, er worden beperkt automatische schakelingen uitgevoerd...') 

        else                                                                                                                            -- ALS ER GEEN VISITE IS DAN GEWOON AVONDVERLICHTING UIT EN SLAPEN AAN 
            dz.helpers.globalMessage2(dz,item,info,messageTable,'add', ' SCHAKELKLOK: staat op AUTOMATISCH. Gebeurtenis:' .. item.trigger .. ', wordt uitgevoerd...') 
    
            if  (item.trigger == timer_avond_huis_off1 or item.trigger == timer_avond_huis_off2) then                                   -- AVOND UIT:
                dz.devices('Avond').switchSelector('uit')

            elseif  (item.trigger == timer_slapen_on1 or item.trigger == timer_slapen_on2) then                                         -- SLAPEN AAN
                dz.devices('Slapen').switchOn()
            end

        end

        if  (dz.devices('Thuis').state == 'On') then                                                                                            -- HUIS VAN ALARM AF, ER IS IEMAND THUIS

            if (item.trigger == timer_opstaan_on1 or item.trigger == timer_opstaan_on2 or item.trigger == timer_opstaan_on3) then               -- OPSTAAN AAN en GEEN VAKANTIE
                    dz.devices('Opstaan').switchOn()

            elseif (item.trigger == timer_ontbijten_on1 or item.trigger == timer_ontbijten_on2 or item.trigger == timer_ontbijten_on3) then     -- ONTBIJTEN AAN als iemand thuis en zon onder ....
                --if dz.devices('Zon op').state == 'Off' and (dz.devices('Schakelklok').state ~= 'vakantie') then                                 -- zon is nog niet op en geen vakantie !                                                                 -- CHECK ZON OP/ONDER
                        dz.devices('Ontbijten').switchOn()

                --else
                        --globalMessage(add, ' ONTBIJTEN wordt niet uitgevoerd, de zon is op ....',logcode) 
                   --     dz.helpers.globalMessage2(dz,item,info,messageTable,'add', ' ONTBIJTEN wordt niet uitgevoerd, de zon is op of vakantie staat aan....') 
    
                --end
            end
        else                                                                                                                        -- HUIS OP ALARM, ER IS NIEMAND THUIS
            dz.helpers.globalMessage2(dz,item,info,messageTable,'add', ' OPSTAAN en ONTBIJTEN scripts worden niet uitgevoerd, er is niemand...') 

        end
        
    else 
        dz.helpers.globalMessage2(dz,item,info,messageTable,'add', ' SCHAKELKLOK: heeft een onbekende waarde ...') 

    end
    dz.helpers.globalMessage2(dz,item,info,messageTable,'chg')

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
pvklink
Posts: 822
Joined: Wednesday 12 November 2014 15:01
Target OS: Raspberry Pi / ODroid
Domoticz version: latest b
Contact:

Re: question about dzvents / myscript  [Solved]

Post by pvklink »

This one works great !
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: question about dzvents / myscript

Post by pvklink »

For those who want to reuse this, here my master timer script (with many thanks to @waaren)
@waaren when you have sparetime :-) can you take a look if this scripti is modelled well, or if you can suggest some improvements?

I already have changed statements with if and or or or by using your wildcard construct, looks much better!
When this script is perfect i am gonna update all my scripts with events with this setup, like my irrigation timer script...

Peter

Code: Select all

- dit script bevat de timers voor de Schakelgroepen

--------------------------------------------------------------------------------------------------------------------------------------------------
local Timers =
{
    { 'timer_avond_huis_on','25 minutes before sunset on mon,tue,wed,thu,fri,sat,sun', true },
    { 'timer_avond_tuin_on','15 minutes after sunset on mon,tue,wed,thu,fri,sat,sun', true },
    { 'timer_avond_huis_off1','at 23:00 on mon,tue,wed,thu,sun', true },
    { 'timer_avond_huis_off2','at 23:45 on fri,sat', true },
    { 'timer_slapen_on1','at 23:05 on mon,tue,wed,thu,sun', true },   
    { 'timer_slapen_on2','at 23:50 on fri,sat', true },
    { 'timer_check','at 24:00 on mon,tue,wed,thu,fri,sat,sun', true },
    { 'timer_slapen_off1','at 06:08 on mon,tue,thu,fri', true },
    { 'timer_slapen_off2','at 07:08 on mon,tue,wed,thu,fri', true },
    { 'timer_slapen_off3','at 08:55 on sat,sun', true },
    { 'timer_opstaan_on1','at 06:10 on mon,tue,thu,fri', false },
    { 'timer_opstaan_on2','at 07:10 on mon,tue,wed,thu,fri', true },
    { 'timer_opstaan_on3','at 09:00 on sat,sun', true },
    { 'timer_opstaan_off1','at 06:15 on mon,tue,thu,fri', false },
    { 'timer_opstaan_off2','at 07:25 on mon,tue,wed,thu,fri', true },
    { 'timer_opstaan_off3','at 09:15 on sat,sun', true },
    { 'timer_zon_on','2 minutes after sunrise on mon,tue,wed,thu,fri,sat,sun', true },
    { 'timer_zon_off','2 minutes after sunset on mon,tue,wed,thu,fri,sat,sun', true },
    { 'timer_ontbijten_on1','at 06:13 on mon,tue,thu,fri', false },
    { 'timer_ontbijten_on2','at 07:20 on mon,tue,wed,thu,fri', true },
    { 'timer_ontbijten_on3','at 13:08 on mon,tue,wed,thu,fri', true },  -- TEST
    { 'timer_ontbijten_on3','at 09:20 on sat,sun', true },
    { 'timer_ontbijten_off1','at 06:44 on mon,tue,thu,fri', false },        
    { 'timer_ontbijten_off2','at 08:00 on mon,tue,wed,thu,fri', true },
    { 'timer_ontbijten_off3','at 11:00 on sat,sun', true },
    { 'timer_rolluik_omhoog1','at 09:00 on mon,tue,wed,thu,fri', false },
    { 'timer_rolluik_omhoog2','at 11:00 on mon,tue,wed,thu,fri', true },
    { 'timer_rolluik_omhoog3','at 11:00 on sat,sun', true },
    { 'timer_rolluik_omlaag1','at 13:00 on mon,tue,wed,thu,fri,sat,sun', true },
    { 'timer_rolluik_omlaag2','at sunset on mon,tue,wed,thu,fri,sat,sun', true },
    { 'Timer_dellog','at 10:00 on mon,wed,fri,sun', true },
    { 'Allways','every minute', false },
    { 'Never','never', false },

}
--------------------------------------------------------------------------------------------------------------------------------------------------
local function get_active_timers(Timers)
    local activeTimers = {}
    for _, record in ipairs(Timers) do
        if record[3] == true then
            table.insert(activeTimers, record[2])
        end
    end
    return activeTimers
end

return {
    on =
        {
        timer = get_active_timers(Timers),
        },

    logging =
        {
        level   = domoticz.LOG_ERROR,
        },

    execute = function(dz,item,info)
    -- HIER START DE EXECUTIE
    _G.logMarker = _G.moduleLabel -- marker wordt scriptnaam, _G.logMarker = info.scriptName is idem
    local messageTable = {}

    for _, record in ipairs(Timers) do  -- de eventnaam ophalen en item.trigger inhoud geven van opgehaalde eventnaam
        if record[3] == true and record[2] == item.trigger then
            item.trigger = record[1]
            break
        end
    end

    if  (dz.devices('Schakelklok').state == 'uit') then                                         -- GEEN SCHAKELINGEN
        dz.helpers.globalMessage2(dz,item,info,messageTable,'add', ' SCHAKELKLOK: staat UIT, er worden geen automatische schakelingen uitgevoerd...')
    elseif  (dz.devices('Schakelklok').state ~= 'uit')  then                                    -- WEL autom timer SCHAKELINGEN

        if  (item.trigger == 'timer_avond_huis_on') then                                        -- AVOND HUIS AAN: HUIS sfeerverlichting binnen                  
                dz.devices('Avond').switchSelector('huis')

        elseif  (item.trigger == 'timer_avond_tuin_on') then                                    -- AVOND TUIN AAN: TUIN sfeerverlichting buiten
                dz.devices('Avond').switchSelector('tuin')

        elseif dz.helpers.matchesWildCardedString(dz,item.trigger, 'timer_slapen_off*') then    -- SLAPEN UIT
                dz.devices('Slapen').switchOff()

        elseif dz.helpers.matchesWildCardedString(dz,item.trigger, 'timer_opstaan_off*') then   -- OPSTAAN UIT
                dz.devices('Opstaan').switchOff()

        elseif dz.helpers.matchesWildCardedString(dz,item.trigger, 'timer_ontbijten_off*') then -- ONTBIJTEN UIT
                dz.devices('Ontbijten').switchOff()

        elseif  (item.trigger == 'timer_zon_on') then                                           -- ZON OP
                dz.devices('Zon op').switchOn()

        elseif  (item.trigger == 'timer_zon_off') then                                          -- ZON ONDER
                dz.devices('Zon op').switchOff()

        elseif  (item.trigger == 'Timer_dellog') then                                           -- CLEAN LOG
                dz.devices('clear_log').switchOn()

        elseif  (item.trigger == 'timer_check') then                                            -- CHECK STUFF
                if dz.time.isNightTime then
                    if  (dz.devices('Zon op').state == 'On') then
                        dz.devices('Zon op').switchOff()
                        dz.helpers.globalMessage2(dz,item,info,messageTable,'add', ' SCHAKELKLOK: CHECK, status ZON OP klopt niet: is aangepast!...')
                    end
                else -- daytime
                    if  (dz.devices('Zon op').state == 'Off') then
                        dz.devices('Zon op').switchOn()
                        dz.helpers.globalMessage2(dz,item,info,messageTable,'add', ' SCHAKELKLOK: CHECK, status ZON OP klopt niet: is aangepast!...')
                    end
                end

        elseif dz.helpers.matchesWildCardedString(dz,item.trigger, 'timer_rolluik_omhoog*') then -- ZONWERING OMHOOG


                if      (item.trigger == 'timer_rolluik_omhoog1' and dz.devices('Schakelklok').state ~= 'vakantie')   then                                  
                    dz.devices('Niels rolluik').switchOff()
                elseif  (item.trigger == 'timer_rolluik_omhoog2' and dz.devices('Schakelklok').state == 'vakantie')   then                                  
                    dz.devices('Niels rolluik').switchOff()
                elseif  (item.trigger == 'timer_rolluik_omhoog3')   then                                 
                    dz.devices('Niels rolluik').switchOff()
                end

        elseif  (item.trigger == 'timer_rolluik_omlaag1') then
                grenstmp_zonwering = 18     -- als het boven deze temp is mag t rolluik in de middag omlaag om hitte te voorkomen
                huidigtmp = dz.devices('Strijp_temp').temperature

                if huidigtmp > grenstmp_zonwering then
                    dz.devices('Niels rolluik').switchOn()
                end

        elseif  (item.trigger == 'timer_rolluik_omlaag2') then
                dz.devices('Niels rolluik').switchOn()

        end

        if  (dz.devices('Schakelklok').state == 'visite')   then                                    -- VISITE, dan geen AVOND uit en geen SLAPEN aan
            dz.helpers.globalMessage2(dz,item,info,messageTable,'add', ' SCHAKELKLOK: staat op VISITE, er worden beperkt automatische schakelingen uitgevoerd...')

        else                                                                                        -- ALS ER GEEN VISITE IS DAN GEWOON AVONDVERLICHTING UIT EN SLAPEN AAN
            dz.helpers.globalMessage2(dz,item,info,messageTable,'add', ' SCHAKELKLOK: staat op AUTOMATISCH. Gebeurtenis:' .. item.trigger .. ', wordt uitgevoerd...')

            if dz.helpers.matchesWildCardedString(dz,item.trigger, 'timer_avond_huis_off*') then    -- AVOND UIT:
                dz.devices('Avond').switchSelector('uit')

            elseif dz.helpers.matchesWildCardedString(dz,item.trigger, 'timer_slapen_on*') then     -- SLAPEN AAN
                dz.devices('Slapen').switchOn()
            end

        end

        if  (dz.devices('Thuis').state == 'On') then                                                -- HUIS VAN ALARM AF, ER IS IEMAND THUIS

            if dz.helpers.matchesWildCardedString(dz,item.trigger, 'timer_opstaan_on*') then        -- OPSTAAN AAN EN BIJ INSTELLING VAKANTIE en wel THUIS ?
                    dz.devices('Opstaan').switchOn()

            elseif dz.helpers.matchesWildCardedString(dz,item.trigger, 'timer_ontbijten_on*') then  -- ONTBIJTEN AAN als iemand thuis en zon onder ....
                if dz.devices('Zon op').state == 'Off' and (dz.devices('Schakelklok').state ~= 'vakantie') then                                 -- zon is nog niet op en geen vakantie !
                    dz.devices('Ontbijten').switchOn()

                else
                   dz.helpers.globalMessage2(dz,item,info,messageTable,'add', ' ONTBIJTEN wordt niet uitgevoerd, de zon is op of vakantie staat aan....')

                end
            end
        else                                                                                        -- HUIS OP ALARM, ER IS NIEMAND THUIS
            dz.helpers.globalMessage2(dz,item,info,messageTable,'add', ' OPSTAAN en ONTBIJTEN scripts worden niet uitgevoerd, er is niemand...')

        end

    else
        dz.helpers.globalMessage2(dz,item,info,messageTable,'add', ' SCHAKELKLOK: heeft een onbekende waarde:' .. item.trigger)

    end
    dz.helpers.globalMessage2(dz,item,info,messageTable,'chg')

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 dzvents / myscript

Post by waaren »

pvklink wrote: Wednesday 13 January 2021 13:32 If you can suggest some improvements?
No real reason to change something. Your coding style is tailored to your taste. I would use another approach but that would not make it better or significant quicker.
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 dzvents / myscript

Post by pvklink »

Ok, based on my style an updated version for a main timer script.
All my devices are grouped and each group has an switch you can turn on/off managed by another script that handles only manual actions.
The below script handles events. and events turn one or more groups (via switches on/off)
I try to keep the rules as much as possible in the timer script..

Code: Select all

-- dit script bevat de timers voor de Schakelgroepen 

--------------------------------------------------------------------------------------------------------------------------------------------------
local Timers =
{
    { 'timer_avond_huis_on','25 minutes before sunset on mon,tue,wed,thu,fri,sat,sun', true },
    { 'timer_avond_tuin_on','15 minutes after sunset on mon,tue,wed,thu,fri,sat,sun', true },
    { 'timer_avond_huis_off1','at 23:00 on mon,tue,wed,thu,sun', true },
    { 'timer_avond_huis_off2','at 23:45 on fri,sat', true },
    { 'timer_slapen_on1','at 23:05 on mon,tue,wed,thu,sun', true },   
    { 'timer_slapen_on2','at 23:50 on fri,sat', true },
    { 'timer_check','at 24:00 on mon,tue,wed,thu,fri,sat,sun', true },
    { 'timer_slapen_off1','at 06:08 on mon,tue,thu,fri', true },
    { 'timer_slapen_off2','at 07:08 on mon,tue,wed,thu,fri', true },
    { 'timer_slapen_off3','at 08:55 on sat,sun', true },
    { 'timer_opstaan_on1','at 06:10 on mon,tue,thu,fri', false },
    { 'timer_opstaan_on2','at 07:10 on mon,tue,wed,thu,fri', true },
    { 'timer_opstaan_on3','at 09:00 on sat,sun', true },
    { 'timer_opstaan_off1','at 06:15 on mon,tue,thu,fri', false },
    { 'timer_opstaan_off2','at 07:25 on mon,tue,wed,thu,fri', true },
    { 'timer_opstaan_off3','at 09:15 on sat,sun', true },
    { 'timer_zon_on','2 minutes after sunrise on mon,tue,wed,thu,fri,sat,sun', true },
    { 'timer_zon_off','2 minutes after sunset on mon,tue,wed,thu,fri,sat,sun', true },
    { 'timer_ontbijten_on1','at 06:13 on mon,tue,thu,fri', false },
    { 'timer_ontbijten_on2','at 07:20 on mon,tue,wed,thu,fri', true },
    { 'timer_ontbijten_on3','at 16:21 on mon,tue,wed,thu,fri', false },  -- TEST activiteit waarvan je de tijd kan aanpassen
    { 'timer_ontbijten_on3','at 09:20 on sat,sun', true },
    { 'timer_ontbijten_off1','at 06:44 on mon,tue,thu,fri', false },        
    { 'timer_ontbijten_off2','at 08:00 on mon,tue,wed,thu,fri', true },
    { 'timer_ontbijten_off3','at 11:00 on sat,sun', true },
    { 'timer_rolluik_omhoog1','at 09:00 on mon,tue,wed,thu,fri', false },
    { 'timer_rolluik_omhoog2','at 11:00 on mon,tue,wed,thu,fri', true },
    { 'timer_rolluik_omhoog3','at 11:00 on sat,sun', true },
    { 'timer_rolluik_omlaag1','at 13:00 on mon,tue,wed,thu,fri,sat,sun', true },
    { 'timer_rolluik_omlaag2','at sunset on mon,tue,wed,thu,fri,sat,sun', true },
    { 'Timer_dellog','at 10:00 on mon,wed,fri,sun', true },
    { 'Allways','every minute', false },
    { 'Never','never', false },

}
--------------------------------------------------------------------------------------------------------------------------------------------------
local function get_active_timers(Timers)
    local activeTimers = {}
    for _, record in ipairs(Timers) do
        if record[3] == true then
            table.insert(activeTimers, record[2])
        end
    end
    return activeTimers
end

return 
{
    on ={timer = get_active_timers(Timers),},
    logging ={level   = domoticz.LOG_ERROR,},
    execute = function(dz,item,info)
    
    -- HIER START DE EXECUTIE
    
    _G.logMarker = _G.moduleLabel -- marker wordt scriptnaam, _G.logMarker = info.scriptName is idem
    local messageTable = {}
	local triggername = '';

    for _, record in ipairs(Timers) do  -- de eventnaam ophalen en triggername inhoud geven van opgehaalde eventnaam
        if record[3] == true and record[2] == item.trigger then
            triggername = record[1]
            break
        end
    end

    dz.helpers.globalMessage2(dz,item,info,messageTable,'add', ' SCHAKELKLOK: staat op: ' .. dz.devices('Schakelklok').state .. ' en gebeurtenis: ' .. triggername .. ' is geactiveerd om: ' .. item.trigger)

    if  (dz.devices('Schakelklok').state ~= 'uit')  then                                    -- WEL autom timer SCHAKELINGEN: auto, vakantie, visite
    
        if dz.helpers.matchesWildCardedString(dz,triggername, 'timer_avond_huis_on*') then      -- AVOND HUIS AAN: HUIS sfeerverlichting binnen                  
                dz.devices('Avond').switchSelector('huis')

        elseif dz.helpers.matchesWildCardedString(dz,triggername, 'timer_avond_tuin_on*') then -- AVOND TUIN AAN: TUIN sfeerverlichting buiten
                dz.devices('Avond').switchSelector('tuin')
                
        elseif dz.helpers.matchesWildCardedString(dz,triggername, 'timer_avond_huis_off*') then    -- AVOND UIT:
            if  (dz.devices('Schakelklok').state ~= 'visite')   then                                    -- VISITE, dan geen AVOND uit en geen SLAPEN aan
                dz.devices('Avond').switchSelector('uit')
            else
                dz.helpers.globalMessage2(dz,item,info,messageTable,'add', ' AVOND HUIS UIT wordt niet uitgevoerd, visite-mode staat aan....')
            end

        elseif dz.helpers.matchesWildCardedString(dz,triggername, 'timer_slapen_on*') then     -- SLAPEN AAN
            if  (dz.devices('Schakelklok').state ~= 'visite')   then                            -- VISITE, dan geen AVOND uit
                dz.devices('Slapen').switchOn()
            else
                dz.helpers.globalMessage2(dz,item,info,messageTable,'add', ' SLAPEN AAN wordt niet uitgevoerd, visite-mode staat aan....')
            end

        elseif dz.helpers.matchesWildCardedString(dz,triggername, 'timer_slapen_off*') then    -- SLAPEN UIT
                dz.devices('Slapen').switchOff()

        elseif dz.helpers.matchesWildCardedString(dz,triggername, 'timer_opstaan_on*') then     -- OPSTAAN AAN EN BIJ INSTELLING VAKANTIE en wel THUIS ?
            if  (dz.devices('Thuis').state == 'On') and (dz.devices('Schakelklok').state ~= 'vakantie') then                                            -- ER IS IEMAND THUIS en geen vakantie
                dz.devices('Opstaan').switchOn()
            else
                dz.helpers.globalMessage2(dz,item,info,messageTable,'add', ' OPSTAAN AAN wordt niet uitgevoerd, er is niemand thuis of vakantie-mode staat aan!...')
            end

        elseif dz.helpers.matchesWildCardedString(dz,triggername, 'timer_opstaan_off*') then   -- OPSTAAN UIT
                dz.devices('Opstaan').switchOff()

        elseif dz.helpers.matchesWildCardedString(dz,triggername, 'timer_ontbijten_on*') then  -- ONTBIJTEN AAN 
            if  (dz.devices('Thuis').state == 'On') and (dz.devices('Schakelklok').state ~= 'vakantie') and dz.devices('Zon op').state == 'Off' then    -- ER IS IEMAND THUIS, geen vakantie en het is nog donker
                dz.devices('Ontbijten').switchOn()
            else
                dz.helpers.globalMessage2(dz,item,info,messageTable,'add', ' ONTBIJTEN AAN wordt niet uitgevoerd, er is niemand thuis of vakantie-mode staat aan of de zon is al/nog op!...')
            end

        elseif dz.helpers.matchesWildCardedString(dz,triggername, 'timer_ontbijten_off*') then -- ONTBIJTEN UIT
                dz.devices('Ontbijten').switchOff()

        elseif dz.helpers.matchesWildCardedString(dz,triggername, 'timer_zon_on*') then        -- ZON OP
                dz.devices('Zon op').switchOn()

        elseif dz.helpers.matchesWildCardedString(dz,triggername, 'timer_zon_off*') then        -- ZON ONDER
                dz.devices('Zon op').switchOff()

        elseif  (triggername == 'Timer_dellog') then                                           -- CLEAN LOG
                dz.devices('clear_log').switchOn()

        elseif  (triggername == 'timer_check') then                                            -- CHECK STUFF
                if dz.time.isNightTime then
                    if  (dz.devices('Zon op').state == 'On') then
                        dz.devices('Zon op').switchOff()
                        dz.helpers.globalMessage2(dz,item,info,messageTable,'add', ' SCHAKELKLOK: CHECK, status ZON OP klopt niet: is aangepast!...')
                    end
                else -- daytime
                    if  (dz.devices('Zon op').state == 'Off') then
                        dz.devices('Zon op').switchOn()
                        dz.helpers.globalMessage2(dz,item,info,messageTable,'add', ' SCHAKELKLOK: CHECK, status ZON OP klopt niet: is aangepast!...')
                    end
                end

        elseif dz.helpers.matchesWildCardedString(dz,triggername, 'timer_rolluik_omhoog*') then -- ZONWERING OMHOOG

                if      (triggername == 'timer_rolluik_omhoog1' and dz.devices('Schakelklok').state ~= 'vakantie')   then                                  
                    dz.devices('Niels rolluik').switchOff()
                elseif  (triggername == 'timer_rolluik_omhoog2' and dz.devices('Schakelklok').state == 'vakantie')   then                                  
                    dz.devices('Niels rolluik').switchOff()
                elseif  (triggername == 'timer_rolluik_omhoog3')   then                                 
                    dz.devices('Niels rolluik').switchOff()
                end

        elseif dz.helpers.matchesWildCardedString(dz,triggername, 'timer_rolluik_omlaag*') then -- ZONWERING OMLAAG
            if  (triggername == 'timer_rolluik_omlaag1') then
                grenstmp_zonwering = 18     -- als het boven deze temp is mag t rolluik in de middag omlaag om hitte te voorkomen
                huidigtmp = dz.devices('Strijp_temp').temperature

                if huidigtmp > grenstmp_zonwering then
                    dz.devices('Niels rolluik').switchOn()
                end
            else
                dz.devices('Niels rolluik').switchOn()
            end
        else
            dz.helpers.globalMessage2(dz,item,info,messageTable,'add', ' SCHAKELKLOK: onbekende timers! ' .. triggername)
        end
    else
        dz.helpers.globalMessage2(dz,item,info,messageTable,'add', ' SCHAKELKLOK: staat uit. Er vinden geen schakelingen plaats! ' .. triggername)

    end
    dz.helpers.globalMessage2(dz,item,info,messageTable,'chg')

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
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest