global_data and matchrule

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

Moderator: leecollings

Post Reply
poudenes
Posts: 667
Joined: Wednesday 08 March 2017 9:42
Target OS: Linux
Domoticz version: 3.8993
Location: Amsterdam
Contact:

global_data and matchrule

Post by poudenes »

Hi All,

I want add some match rules into my global_data:

Code: Select all

domoticz.time.matchesRule 'on 01/12-05/01'
domoticz.time.matchesRule 'on 23/10-4/11'
domoticz.time.matchesRule 'on 11/05,19/08'
I tried follow to add them:

Code: Select all

xmas = function(domoticz)
            domoticz.time.matchesRule 'on 01/12-05/01'
        end,
        
        halloween = function(domoticz)
            domoticz.time.matchesRule 'on 23/10-4/11'
        end,
        
        bday = function(domoticz)
            domoticz.time.matchesRule 'on 11/05,19/08'
        end,
and in my script tried to use:

Code: Select all

-- HALLOWEEN
    if (domoticz.devices(TEST).active) then
        
        if (domoticz.helpers.halloween(domoticz)) then
        
            domoticz.helpers.RGB(domoticz,BulbDressoirAll,100,'Blue',nil)

-- X-MAS
       elseif (domoticz.helpers.xmas(domoticz)) then
        
            domoticz.helpers.RGB(domoticz,BulbDressoirAll,100,'White',nil)
         
-- REST VAN JAAR
        else
            domoticz.helpers.Kelvin(domoticz,BulbDressoirAll,nil,4000,nil)
        end

    else
    
        domoticz.helpers.TurnOff(domoticz,BulbDressoirAll,nil,nil)
    
    end
Changed some thing as well, but what i do i cant let it work.
Reason i want use helpers in a IF statement is when i need change the dates (and it will if my partner complain about the light color etc) then i only need them to change in global_data and all the script that use the helpers will automatic use the new value...
RPi3 B+, Debain Stretch, Domoticz, Homebridge, Dashticz, RFLink, Milight, Z-Wave, Fibaro, Nanoleaf, Nest, Harmony Hub, Now try to understand pass2php
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: global_data and matchrule

Post by waaren »

poudenes wrote: Tuesday 01 January 2019 20:33 I want add some match rules into my global_data:
Hope this helps ( I use "dz" everywhere possible where I refer to "domoticz" )

global_data.lua

Code: Select all

-- global_data.lua 
 
return {
    
        data = {
		                domoticzLocation                        = { initial = "Nederland" },
                  },

	helpers =   {
                    xmas = function(dz)
                        return dz.time.matchesRule('on 01/12-05/01')
                    end,
                    
                    halloween = function(dz)
                        return dz.time.matchesRule('on 23/10-4/11')
                    end,
            
                    birthday = function(dz)
                        return dz.time.matchesRule('on 11/5,19/8')
                    end,
                },
       }
script

Code: Select all

return {
    on      =   {   timer =  {"every minute" }},

    logging =   {   level   =   domoticz.LOG_DEBUG,
                    marker  =   "helper"               },
    
     
    execute = function(dz, item)
        
        local function logWrite(str,level)
            dz.log(tostring(str),level or dz.LOG_DEBUG)
        end

        logWrite("Return value from helper function X-mas     = ".. tostring(dz.helpers.xmas(dz)))
        logWrite("Return value from helper function Halloween = ".. tostring(dz.helpers.halloween(dz)))
        logWrite("Return value from helper function birthday  = ".. tostring(dz.helpers.birthday(dz)))

        -- HALLOWEEN
        if dz.helpers.halloween(dz)  then
            dz.helpers.RGB(dz,BulbDressoirAll,100,'Blue',nil)
        -- X-MAS
        elseif dz.helpers.xmas(dz) then
            dz.helpers.RGB(dz,BulbDressoirAll,100,'White',nil)
       -- REST VAN JAAR
        else
            dz.helpers.Kelvin(dz,BulbDressoirAll,nil,4000,nil)
        end
    end
}              
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
poudenes
Posts: 667
Joined: Wednesday 08 March 2017 9:42
Target OS: Linux
Domoticz version: 3.8993
Location: Amsterdam
Contact:

Re: global_data and matchrule

Post by poudenes »

Thanks. When I'm home after cremation ceremony of my mom today I will try this. Playing with script can clear my head a lot at the moment.


Verzonden vanaf mijn iPhone met Tapatalk Pro
RPi3 B+, Debain Stretch, Domoticz, Homebridge, Dashticz, RFLink, Milight, Z-Wave, Fibaro, Nanoleaf, Nest, Harmony Hub, Now try to understand pass2php
poudenes
Posts: 667
Joined: Wednesday 08 March 2017 9:42
Target OS: Linux
Domoticz version: 3.8993
Location: Amsterdam
Contact:

Re: global_data and matchrule

Post by poudenes »

It work!! Thanks
RPi3 B+, Debain Stretch, Domoticz, Homebridge, Dashticz, RFLink, Milight, Z-Wave, Fibaro, Nanoleaf, Nest, Harmony Hub, Now try to understand pass2php
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest