Page 1 of 1

to rookie to get it...

Posted: Monday 18 March 2019 19:34
by bozidar
Hi all

I have in rooms that are mainly controlled by PIR a need for more control.

I am trying to implement that spots dim to 50% light between 20:00 and 2300 and 30% between 23:00 and 5:30 .and 50% between 5:30 and 630

BUT the big issue is light switch need to be able to increase to 100% if pressed and overule dimming.

Light switches are "digital" and ON signal when pressed ,and otherwise off.

Is that even possible

Re: to rookie to get it...

Posted: Monday 18 March 2019 21:42
by waaren
bozidar wrote: Monday 18 March 2019 19:34 I have in rooms that are mainly controlled by PIR a need for more control.
I am trying to implement that spots dim to 50% light between 20:00 and 2300 and 30% between 23:00 and 5:30 .and 50% between 5:30 and 630
BUT the big issue is light switch need to be able to increase to 100% if pressed and overrule dimming.
Light switches are "digital" and ON signal when pressed ,and otherwise off.
Could be something like

Code: Select all

-- Time & Switch control

dim50Evening = "at 20:00"
dim30Night   = "at 23:00"
dim50Morning = "at 5:30"
Off          = "at 6:30"

return {
    on      =   {     timer =   {
                                    dim50Evening,
                                    dim30Night,
                                    dim50Morning,
                                    Off,
                                },
                
                devices     =   { 
                                    "your Switch", 
                                },
                },
    
    logging =   { level     =   domoticz.LOG_DEBUG, 
                  marker    =   "Time & Switch control" },
    
    data    = { dimLevel    =   { initial = 50 }},

    execute = function(dz,item)
        local light = dz.devices("your dimmable light")
        
        local function logWrite(str,level)
            dz.log(tostring(str),level or dz.LOG_DEBUG)
        end
        
        if item.isTimer then 
            if dz.time.matchesRule(dim50Evening) or dz.time.matchesRule(dim50Morning) then
                dz.data.dimLevel = 50
            elseif dz.time.matchesRule(dim30Night) then
                dz.data.dimLevel = 30
            else
                dz.data.dimLevel = 0
            end
            light.dimTo(dz.data.dimLevel)
        else					        	          -- triggered by Switch 
            if item.state == "On" then 	        	  -- Switch is On
                dz.data.dimLevel = light.level   	  -- store current Level
                light.dimTo(100)                  	          -- full Power to the light  
            else
                light.dimTo(dz.data.dimLevel)     -- Restore to old dimLevel  
            end
        end
    end
}