Page 1 of 1

Lighting time Period and specific brightness [Solved]

Posted: Monday 18 February 2019 3:59
by alarm_guy1
Hi guys,
A kind soul provided me with this code, and it works fantastically.
However for one of my applications I require a twist, and have no clue where to begin, I have watched videos and read read stuff, but I personally cannot get a handle on either Lua or DZvents.

I would like to have Domoticz run this code as it is, but from say 23:00 hrs to 06:00 hrs when the "Bathroom MD Sensor" is activated the Dimmer "Bathroom" turns the light on at say 10% and at all other times outside of this the light will come on at around 90%

Many thanks

Code: Select all

return  {
            on          =   { devices           =  {  "Bathroom MD Sensor" }
                            },
            
            logging     =   {   
                                level           =   domoticz.LOG_DEBUG,
                                marker          =   "Bathroom Motion" 
                            },
                    
    execute = function(dz, item)

        local function logWrite(str,level)
            dz.log(str,level or dz.LOG_DEBUG)
        end

       -- local Lux = dz.devices("Bathroom MD Lux").lux
                local LuxDevice = dz.devices(450)                 -- <<<--- replace xxx by IDX of your Lux device
                local Lux = LuxDevice.lux
        -- local Lights = dz.devices("Bathroom")
                local Lights = dz.devices(440)                       -- <<<--- replace xxx by IDX of your Bathroom lights
                            
        logWrite(LuxDevice.name .. " ==>> Lux:   " .. Lux )
        logWrite(Lights.name ..    " ==>> State: " .. Lights.state)
        logWrite(item.name ..      " ==>> State: " .. item.state)
       
        if Lux < 100 and item.state == "On" then
            Lights.cancelQueuedCommands()
            Lights.switchOn().checkFirst()
        elseif item.state == "Off" and Lights.state == "On" then 
            Lights.switchOff().afterSec(300) 
        end
    end
}     

Re: Lighting time Period and specific brightness

Posted: Monday 18 February 2019 8:12
by waaren
alarm_guy1 wrote: Monday 18 February 2019 3:59 I would like to have Domoticz run this code as it is, but from say 23:00 hrs to 06:00 hrs when the "Bathroom MD Sensor" is activated the Dimmer "Bathroom" turns the light on at say 10% and at all other times outside of this the light will come on at around 90%
Can you try this ?

Code: Select all

return  {
            on          =   { 
								devices           =		{  
															"Bathroom MD Sensor",
														}
                            },
            
            logging     =   {   
                                level           =   domoticz.LOG_DEBUG,
                                marker          =   "Bathroom Motion" 
                            },
                    
    execute = function(dz, item)

        local function logWrite(str,level)
            dz.log(str,level or dz.LOG_DEBUG)
        end

       -- local Lux = dz.devices("Bathroom MD Lux").lux
                local LuxDevice = dz.devices(450)                 -- <<<--- replace xxx by IDX of your Lux device
                local Lux = LuxDevice.lux
        -- local Lights = dz.devices("Bathroom")
                local Lights = dz.devices(440)                       -- <<<--- replace xxx by IDX of your Bathroom lights
                            
							
        logWrite(LuxDevice.name .. " ==>> Lux:   " .. Lux )
        logWrite(Lights.name ..    " ==>> State: " .. Lights.state)
        logWrite(item.name ..      " ==>> State: " .. item.state)
       
        if Lux < 100 and item.state == "On" then
            Lights.cancelQueuedCommands()
            
			if dz.time.matchesRule("at 23:00-06:00") then
				Lights.dimTo(10)
			else
				Lights.dimTo(90)
			end
        elseif item.state == "Off" and Lights.state == "On" then 
            Lights.switchOff().afterSec(300) 
        end
    end
}     

Re: Lighting time Period and specific brightness

Posted: Monday 18 February 2019 19:14
by alarm_guy1
Hi many many thanks for this.

I will load it up and test over a few nights and see how it goes.

thankyou

Re: Lighting time Period and specific brightness

Posted: Tuesday 19 February 2019 20:47
by alarm_guy1
This works a treat, many many thanks. I wish I could get my head around Lua and Dzvents but with work and age and a dodgy memory it is a struglle.

but thanks again... the wife is chuffed.