The "Lived-in" look; lighting timer randomness available?


I have a pending customer wondering if the lighting timers can be varied with some sort of randomness to make the home look especially lived-in… is this a feature of the current Vera?

If not, can it be added to a future Vera firmware update?

Thank you for your help, both current Vera users and Vera employees :slight_smile:

I asked this question a while ago and never got an answer from MV.

Only way to achieve something like this right now is to make the light on and off relative to sunset/sunrise. It then has differing times each day, but relative to sunrise/sunset is fixed.

I have no idea if it works, but the Lua language does have a “math” library that contains a random function. Call is math.random(), and is supposed to return a random number (fraction) between 0 and 1. The documentation indicates there are other options for what random returns as well.

You could write a scene with Lua code that fires every couple of minutes during the window that you want the scene to run, and does a random number lookup, and if the returned number is within a certain range (say > .9 for example), turns on the light (I would add a fail safe that turns on the light at the end of the time “window”, just in case).

I found the string library functions kind of work, but there are a couple of issues. I have not tried any of the math functions.

Hope this helps

Here’s some stuff to get you a few steps closer. I had written this a few weeks back, but never got it completed (was heading out on vacation and ran out of time).

It was intended as an example to help illustrate what the functionality could look like if “Timers” were augmented, and to find out what worked best for parameters, so it’s very rought.

It has a bunch of parameters controlling the minimum time (IntervalLower), maximum time (IntervalUpper) to wait before making a choice along with the on/percentage weighting (eg 30% chance of setting state to “on”) at the decision point.

The code waits for a “random” period of time between intervalLower and intervalUpper (in minutes), and then it does an evaluation of whether to turn the Scene event “on” or “off”.

It uses the OnPercentage “weighting” to determine whether to set the light to an “on” state or an “off” state at that decision point.

I had it running solo, not controlling anything, but hadn’t gotten to getting it correctly working in scenes just yet.

Someone might like to try it as a project…


This is great stuff. What are the problems you are having?

Also, could you post the S_ file?


Sorry about that Brian, I’ve amended the post above to include the S_Randomizer.xml file.

What are the problems you are having?

Mostly, time to write it, I was leaving on vacation the next morning :wink: I had it ticking over, flipping “states”, but I wasn’t getting it to work when I attached a Lamp/Appliance Module to it’s Scene definitions.

In testing, I would set the min/max to 1 (minute) so it would poll quickly, but I couldn’t work out the kinks in Scenes.

After that, I had planned to add an “Enabled/Disabled” (better than “Armed/Disarmed”) flags that I’d control with regular Timer Scenes.

ie. At 6:00pm set Randomizer “Enabled”, at 10:00pm set Randomizer “Disabled”

Where I’d have the Randomizer idle it’s state down to “off” after some [random] period after it’s diabled.

I was also doing it to see if we could work out “how” we wanted these things to behave, to pilot a better [built in] behaviour of the Timers… since otherwise you’d need to setup a who bunch of different Randomizer Devices.

On a longer term/larger scale note…
It would be better to be able to “record” user behavior, and then playback. Unfortunately Vera’s Device Luup dont have the capability to see all the requests in order to “Record” them. The Device hooks to “play back” are, but there’s no point unless you can “record”.

ie. Record/Playback combined with the Lua XML and Socket libs I’ve asked for in another thread, and you can read/write a Google Calendar (CalDAV) to control the whole shooting match.

…perhaps I’ve had too much quality time with the low level CalDAV protocol lately :wink:


Ive have some experience with the panasonic adapted pluggin to control Foscam PT ipcam pluggin and the Fuztle’s Caddx one too, i’ll be interesting to look in your randomize pluggin and make some efforts trying to complete it. Can you give me some directions first to save some time before ??


While I’d really like to see a working random scene, I just created a bunch of “Vacation” scenes (I think 12 of them) and set them to run at different times on different days on different lights and let them run over each other. So I might have a Mon - Tues - Fri scene that runs the front door lights and foyer from 7 pm - 9:15 and a Tues - Wed - Sat scene that runs the dining room and stairs from 7:45 - 11:20pm and just kept building like that. It’s not truly random but it appears random enough from the outside for a week or so and it’s very easy to set up. plus you can easily expand or contract it. Once the Puck is easy to use, I’ll probably add a TV on setting every now and then at night too.

It’s worth looking at this thread as well:

AP15e is working on a plugin there. In the mean time, I’ve got a little snippet of luup code I use to randomize the time a light comes on within a specified time period.

I really just don’t worry about the randomness. If someone is watching my house closely enough to realize the light turns on and off at the same time each day, then I feel I am already in trouble.

Given that @Ap15e’s work is active, probably best to add details to that implementation to get it to do what people need.

Mine started life in UI2, so there’s no .json file, it doesn’t yet have the logic to enable/disable, etc, etc. All relatively easy to add, if you’re willing to “borrow” snippets of code from things like:

a) [tt]D_MotionSensor1.json[/tt] (for the Scene/Event presence, and a UI to control the “On/Off” nature),
… or from @woodsby’s code D_RFIDTransmitter.json – ActiveRFID

b) Add code to handle Actions in the [tt][/tt]
…for when users interact with the JSON-based UI, similar to this snippet from @woodsby’s code I_ActiveRFID.xml – ActiveRFID

At the end of that, you could basically use it declaratively (no code) as the “event” to drive two scenes (one for on, one for off) via the Standard scene creation/editing UI.

Again, probably best to get the ideas and fold them into one implementation. I provide the above info just in case someone wants to learn more about Luup programming, since it’s often easier to start with a stub, and go from there.

Any news about this. I think it could represent a major improvement in z-wave / Vera functionality

I came to the conclusion that the best way to implement a ‘lived-in’ look would be to record a whole day and play back the recording with a user-defined (or random) timeshift.

The recording functionality is there (, but it lacks the recording of timestamps:

I do this using before sunrise & after sunset, but then add a different ‘off’ timer for each day of the week. Each off timer is, by example, around 11:00 pm but then varies by +/- 25 minutes from day to day. Monday could be 10:40, Tuesday 11:05, Wed 10:50, etc… This is as random as currently possible and would require a significant amount of survellience to figure it out. I often go in monthly and shufle the times by day around just in case.

Having lights go on and off randomly is not necessary. It’s only the lights going on and off that makes any difference. Just create a few scenes that turn various lights on or off at different times. The fact that it’s the same every night won’t make any difference.

If you think bad guys have the patience to watch your house night after night to detect patterns in the cycles, you’re giving them way to much credit.

I agree @Ap15e considering that most of us have a combination of lights turning On/Off on via various schedules and the random manual On/Off lights it would be nice to capture a weekday vs weekend scenario and then add a random +/-25 mins to each if possible.

I see from earlier thread post that @Guessed was going down the path with his initial code but did not finish, is there someway to combine @Ap15e recording methodology and @guess code to make a prototype “Lived-In” scene? It seem strange that for a “Home automation” solution that to date we don’t have a plug-in for this. Mike

I Agree with Michael. The random feature is in almost every Home Automation solution out there. I also agree that this could be accomplished using scenes and other features already in Vera.
But, wouldn’t be nicer and easier to have a function specifically designed for that. The more simple the better. I imagine a plugin in which you assign which lights will be part of the scene, max/min time for each and maybe max/min number of lights that could be on at a time.
Then you could use normal scenes to activate / deactivate the function.

I have been using things like “off at sunset +6 hours” etc… its not random
but at least the off time is a slowly moving target…

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

– 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 , “”, “”)

function StayOn1()
– Start the random off timer for light 1
luup.call_timer(“DelayOff1”, 1, RanNumbOff1, “”, “”)

function DelayOff1()
– Turn light off
luup.call_action(“urn:upnp-org:serviceId:Dimming1”,“SetLoadLevelTarget”,{ newLoadlevelTarget=“0” },Device1)

– 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.