Lighting time Period and specific brightness [Solved]

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

Moderator: leecollings

Post Reply
alarm_guy1
Posts: 132
Joined: Tuesday 14 January 2014 0:03
Target OS: Linux
Domoticz version:
Contact:

Lighting time Period and specific brightness [Solved]

Post 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
}     
Last edited by alarm_guy1 on Wednesday 27 February 2019 4:30, edited 1 time in total.
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Lighting time Period and specific brightness

Post 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
}     
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
alarm_guy1
Posts: 132
Joined: Tuesday 14 January 2014 0:03
Target OS: Linux
Domoticz version:
Contact:

Re: Lighting time Period and specific brightness

Post 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
alarm_guy1
Posts: 132
Joined: Tuesday 14 January 2014 0:03
Target OS: Linux
Domoticz version:
Contact:

Re: Lighting time Period and specific brightness

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

Who is online

Users browsing this forum: No registered users and 1 guest