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

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.

Well, it’s a tradeoff between effort and expected revenue … :slight_smile:

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

Michael_N_Blackwell
I forgot to tell you how to activate another scene from within an existing scene using Lup codding. Here is an example of calling another scene using Luup code from within a scene.

– This code turns on the “house is occupied” logical switch and if it is dark out call scene 9.

– Turn on logical switch device 49 - Are we home = yes
luup.variable_set(“urn:upnp-org:serviceId:SwitchPower1”,“Status”,1,49)

– If it is dark out call scene 9
if ( luup.is_night() ) then
luup.call_action(“urn:micasaverde-com:serviceId:HomeAutomationGateway1”,“RunScene”,{ SceneNum=“9” }, 0)
return False
end

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.

Hope this helps… ( This is part of my Welcome home scene @ night)

JimMac,

Many thanks, I will have to read this a few times to get my head around the concept (a little slow ;D). 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.

JimMac, additional questions;

  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 [glow=red,2,300]Just Confirmed that I can[/glow]
    luup.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)

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

luup.variable_set(“urn:upnp-org:serviceId:SwitchPower1”,“Status”,1,49)

Out of curiousty how are you using this, I know the previously I interact with the device 49 thru the GUI, while this statement is a scene to turn device On? thanxs for the insight. Mike

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_scenes
Personally I’ve only just learned “return luup.is_night()” and that there is no “return luup.is_day()” so, thank you for contributing.

JOD.

Answers as follows;

  1. Yes you can add other devices but in your example you will need to create a local variable called Device2 and Device3 so you would have something like this:

– Setup local variables for random time on & off (in seconds) plus the device(s) to control
local Device1 = 15
local Device2 = ?? - replace with second light device number
local Device3 = ?? - replace with third light device number

The only problem with this is that all lights will go on and off at the same time. You can modify the code to allow for each light to have independent random timing.

Also note that the dimmer in my example is set for 70%, you may want to change that value and also make sure you have the correct code for a on/off switch vs. a dimmer.

Also note that the timing can be changed by changing only the value of these local variables;
local RandOnTime1 = 1200
local On1 = 800
local RandOffTime1 = 600
You don’t need to change anything else.

  1. Not sure what your asking here? You don’t need any scenes associated with the switch unless you need to. I add the coding to toggle the state of the logical flag in my Welcome Home and Exit scenes, all other “Away lighting scenes” test the current state and logically react to it.

  2. To toggle the “Are_We_Home” flag I add this code to my “Welcome Home” scene:
    luup.variable_set(“urn:upnp-org:serviceId:SwitchPower1”,“Status”,1,49)

This turns on the flag indicating I’m home. Change the 1 to a 0 for the exit scene. I don’t use the command section to toggle the logical switch just add the codding to the Luup tab.

If you want an example of how to have more than one light using independent random code I will see if I can code one up for you.

JimMac again thank-you for taking the time to respond and explain.

The light bulb is starting glow (slightly) as I’m playing with the examples provided. One of the things I’ve began to do is keep a file with the various Code examples and associated notations as i start to use them. I’m slowly understanding the syntax structure and the difference between local and nonlocal variables. Is there a document with valid Verda Lua calls, monitor and ect… that one could review/advise?

Responses;

  1. Agree, I’ve seen the local variables used in another code example. However by simply copying the command and changing the device ID I was able to get the code do the same.
    2/3) The reason I was asking is that if I simply toggle the logical device from On to Off why would I need a Welcome home and Exit Scene, unless the scenes are doing something else that I’m missing? I noticed that when I use IVerde I have access to both the devices and scenes that why I’m inquiring.

You made mention that you have a scene that turns on your lights to 10% when someone walks at night providing that your “Welcome Home” scene is on if not it turn’s on your alarm would be intrested as to how accomplished that.

The Short answer in providing examples is “Yes please!”, as both yourself and JOD indicated, there seems to be a lack of Lau examples available and any guidance is greatly apprieciated and is mostly being viewed and used last time looked at this topic we had over 1200 views… Mike

Michael_N_Blackwell

My exit /home scenes do all sorts of things so it was convenient to add the code there.
The code for motion is made of two scenes that turns on three lights @ 10% when activated by my two motion sensors but in the Luup codging I have the condition that if my “Are_We_Home” is false skip the lights and instead turn on a plugin module that controls a siren and high intensity red/blue LED light bars in my window. Very simple to do:

– Find the status of the logical “House_occupied” switch
local house_occupied=luup.variable_get(“urn:upnp-org:serviceId:SwitchPower1”,“Status”,49)

– Alarm plug in module
Local AlarmPlug= 23

if ( house_occupied == “0” ) then

luup.call_action(“urn:upnp-org:serviceId:SwitchPower1”,“SetTarget”,{ newTargetValue=“1” },AlarmPlug)
return false
end

Probably best to add a 5 minute timer that shuts it off so the neighbors don’t complain.

I’m building a house so my time is limited but I will see what I can do for multiple random lighting but remember that I’m just starting to learn this code so I offer no guaranties plus I invite anyone who has a better way of doing things to jump in and offer suggestions. The easy way of doing this is to double the code but I want to see if I can create a counter that changes the variable names and counts the number of loops depending on how many lights are used.

Can somebody point me to the best place to learn about creating Virtual Devices? I can’t seem to find a good starting point.

http://forum.micasaverde.com/index.php?topic=6375.msg40051#msg40051 ?

Can somebody point me to the best place to learn about creating Virtual Devices? I can’t seem to find a good starting point.[/quote]
@JimMac’s info in this thread is great. Here’s another shorter thread. Please download version 0.1 in Reply #9 by @Henk (as @Ap15e pointed to as well); it works. :slight_smile:

Hmmm…I’m feeling sort of dense. Is there any fairly step-by-step instructions anywhere about how to create a virtual device? I have no experience in programming or scripting Lua code, so perhaps that is why I am so clueless about this.

If not, no problem. I’ll figure it out eventually!

Thanks,

David

[quote=“tripletdad, post:37, topic:165277”]Hmmm…I’m feeling sort of dense. Is there any fairly step-by-step instructions anywhere about how to create a virtual device? I have no experience in programming or scripting Lua code, so perhaps that is why I am so clueless about this.

If not, no problem. I’ll figure it out eventually!

Thanks,

David[/quote]

David,

Its more or less like creating all LUUP coded devices anf plugins and requires almost no coding experience.

I do hope you already downloaded the needed json and xml files?
—edit–

Please see this topic: http://forum.micasaverde.com/index.php?action=profile;u=11839;sa=showPosts

Henk

Henk,

I have now installed the files you referenced. I now have the option of creating virtual devices. Can you please point me in the right direction as to which fields to fill in and what to fill them in with, in order to create an “Away” virtual device?

-David