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

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.

@JimMac, thanks for code, question is the house occupied device 49 aka your house lock? also how does the logical switch work; if I use the exit button on my lock what differation from a normal lock vs vacation lock? I'm assuming that the welcome home is a unique key that turns off the thsi Luup code? Mike

Device 49 is my virtual device switch (see this forum on how to create a virtual device switch) It looks like a switch but it is only virtual no real switch exists. Just think of it as a flag. My Welcome home scene turns it on and my exit scene turns it off. All my Luup code in my lighting scenes check the state of this switch and either executes the away lighting or skips it if we're home (same for my alarm scenes). I find that toggling a virtual switch is best done with Luup coding not through the scene devices. The day I found out how to do this my system became much easier to live with.

JimMac, re-reading you virtual switch you indicate that your welcome home scene turns it on and my exit scene turns it off.. The logic seems reverse I would have thought that the welcome home would turn your random code off and Off would indicate that your not home. With help of Ap15e, I was able to create a SD and created a test scene to turn on a specific light when the SD was switched "On", I then created another test scene to turn off the specific light again triggered by the SD state when switched to "Off". I can see the advantage but am trying to get my head around how to best use it. Also I'm assuming that previous random code goes into a scene that drives a single light if I want it to turn on other scene how is this possible? thanxs Mike

My welcome home turns it on, exit off, I like to think that someone is home when the lights are on. The state of the switch does not matter as long as you test for the correct condition.If you create lots of away lighting scenes you only want these lights doing their thing when your away so have Lup code in each scene that test if your home, if you are home don't run the scene otherwise run them. Another example is I have multiple scenes that detect motion at night and turn on various lights at 10% so you can see your way. These scenes activate lights when we're home BUT if we are not then instead of turning on lights it activates my alarm siren and strobe lights. This is all done using the same scene. One more example, I have a rental cabin, if it is occupied the water heater is turned on otherwise it is kept off all by using a logical switch as a test flag.

I exit the first scene once I call the second scene (#9) without executing any commands in the original scene but I don't have to do this. I can exit "true" or remove the "return false" if I want to proceed with all the commands in scene 1 as well. I use this technique often since it can reduce the number of independent scenes and simplifies the order and way of executing them with advance boollean logic.

Many thanks, I will have to read this a few times to get my head around the concept (a little slow ). I can see the advantage, just needed a few pointers (which you provided) to proceed. I would have thought there would have been a "How to for dummies" somewhere e.g wiki. It seems that some of us Lua challenged folks are trying to piece meal via the many related thread with limited success (Ok I'll stop my whinning) again thanks for the comeback.

I realize that many people are not programmers that is why I have added many comments in my codding to help you break down what each section or line of code does. There are so many different things you can do with Lua coding and I try to make it as simple as cut/paste + minor edit for everyone. I have been on this forum for many years and have found that not too many people are willing to share codding with others. Maybe it causes too many questions, I'm not sure. There are the exceptions and thanks to those people who do post as they have helped me and others in learning the language. You can find those people in the Luup and Development section.

The code for programming is available, the only thing that is not supplied is imagination and the need.

1) I'm assuming if I want more than one device to turn on that I would simply add additional command statements with each device Id identified e.g Just Confirmed that I canluup.call_action("urn:upnp-org:serviceId:Dimming1","SetLoadLevelTarget",{ newLoadlevelTarget="70" },Device1)luup.call_action("urn:upnp-org:serviceId:Dimming1","SetLoadLevelTarget",{ newLoadlevelTarget="70" },Device2)luup.call_action("urn:upnp-org:serviceId:Dimming1","SetLoadLevelTarget",{ newLoadlevelTarget="70" },Device3)

2) Also on my logical switch (device 49) do I have to have any scene(s) associated with the switch, I would have thought that simply turning it On for Home and Off for Away would be the simple flag or no flag situation that each device would react as Home vs Away? with the;

local house_occupied=luup.variable_get("urn:upnp-org:serviceId:SwitchPower1","Status",49)

3) In your recent post you have code that turns on the logical switch (device 49)

I realize that many people are not programmers that is why I have added many comments in my codding to help you break down what each section or line of code does.

The coding goes along way to adding those finishing touches to an installation. I wish there were more examples in the scripting wiki..http://wiki.micasaverde.com/index.php/Scripts_for_scenesPersonally I've only just learned "return luup.is_night()" and that there is no "return luup.is_day()" so, thank you for contributing.

JOD.

Logged

I'm sorry, my responses are limited. You must ask the right questions.