I find the “lived in look” is a required scenario for my house, rental and garage. Standard timers that turn lots of light on at one time just don’t cut it for me so I have been using Luup code to create the custom environment I need. I have ground floor lights randomly go on just after sunset and randomly go off at different times. Later on at night the bedroom and bathroom lights take their turn, randomly on/off.
The code I use has three settings; random turn on time, minimum on time and random off time. A scene is created but it only has Luup code, it does not necessarily need to turn anything on or off in the GUI. My scenes usually starts with a timer, as an example one of my bedrooms is set to activate the scene @ 9:50pm. Sunset in this case does not work as you will need to constantly adjust the time as the seasons change. In the code sample below I have added a few extra settings to make life easier, first I have a logical switch representing if I’m home or not. This switch changes states when I enter a door code (welcome Home) or press the exit button, On=home, off=away. If I’m home I don’t want the lights doing their thing plus I also check to make sure its dark out.
Here is the Luup code with comments added.
– Description: Light on within 20min of scene activation, stay on for 13m then off withing 10min
– Find the status of the logical “House occupied” switch
local house_occupied=luup.variable_get(“urn:upnp-org:serviceId:SwitchPower1”,“Status”,49)
– Exit if the house is occupied or it’s not night time
if (house_occupied == “1”) or not ( luup.is_night() ) then
return false
end
– Setup local variables for random time on & off (in seconds) plus the device to control
local Device1 = 15
local RandOnTime1 = 1200
local On1 = 800
local RandOffTime1 = 600
local RanNumbOn1 = (math.random() * RandOnTime1 )
local RanNumbOff1 = (math.random() * RandOffTime1 )
function DelayOn1()
luup.call_action(“urn:upnp-org:serviceId:Dimming1”,“SetLoadLevelTarget”,{ newLoadlevelTarget=“70” },Device1)
– Keep light on for preset time
luup.call_timer(“StayOn1”, 1, On1 , “”, “”)
end
function StayOn1()
– Start the random off timer for light 1
luup.call_timer(“DelayOff1”, 1, RanNumbOff1, “”, “”)
end
function DelayOff1()
– Turn light off
luup.call_action(“urn:upnp-org:serviceId:Dimming1”,“SetLoadLevelTarget”,{ newLoadlevelTarget=“0” },Device1)
end
– It all starts here - Start the random timing for light 1
luup.call_timer(“DelayOn1”, 1 , RanNumbOn1,“”,“”)
The Device1 number is the device number of the light you want to control. I have many variations of this code for example:
A scene is activated that turns on three lights, make each light turn on randomly then use the off from the scene settings - this avoids the all on at once scenario.
I can call another scene at the end of any of the three timers. Great for randomly controlling a second set of lights.
A simple cut/past and minor edit should work if you want to use this code.