Lights on a security timer while away

Somebody please help, I can’t figure out how to do this. All I want to do is have a lamp turn on at 5pm and off at 11pm so that it looks like the house is occupied, just like a $10 programmable timer… only I want to be able to activate this macro when I push Button 1 on a Scene controller (i.e. when I leave the house) and deactivate the macro when I push Button 2 (i.e. when I come back home).

Is this really simple to do?? I can’t seem to figure out what I would do…

It is not simple to do - this would involve creating a “virtual switch”. The virtual switch would be turned on or off by your buttons. You would then need to add some Lua code to the scenes that turn on an off the light to prevent them from turning the light on when you are home. You can search for virtual switch here to find out how to create one. If you want to try this, post back.

WTH! That’s way too complicated! I have absolutely no idea how to do that. Is there some kind of plugin I can buy that will do this? Or a tutorial?

…or maybe I’m the only person who would like to have lights on a timer while I’m away…

Its a little complicated but to get you started, its best to do this step by step and test at each stage.

  • Go to apps and download the virtual switch plugin from there and make a note of its device number from its advanced tab once its installed.
  • Next create a scene that has your light turning on and off on a daily timer. Once you have your scene as working with the light that you have chosen, you then need to use the LUUP tab of that same scene, and paste in the following code:

autoscene = luup.variable_get("urn:upnp-org:serviceId:VSwitch1","Status",DeviceID) if(autoscene=="1")then return true else return false end

  • Where DeviceID is written in the code above, you will want to replace this with the number you noted in the first step.
  • Save

Once you have confirmed that toggling the virtual Switch disables the scene, you then need to create a new scene that toggles the state of the virtual switch from the scene controllers buttons.

  • Again create a new scene for each of these (one for on, and one for off if you want to use 2 buttons on your scene controller) and test that each of these scenes toggles the state of the virtual switch from on to off and visa versa from the dashboards “Run” button after saving.
    -Once you have that working (and assuming you have a scene controller), you then need to use the triggers tab of your on and off scenes that you just created and assign button 1 to your on scene, and button 2 in the off scene.

See how you get on with that!

You’re being facetious, but you might be the only person who occupies the intersection of (has a Vera), (wants lights on timers while you are away), and (doesn’t want to do programming to achieve it).

SETI people may liken this to the Drake Equation…

I guess I’m one of the few doing the “away” timer without lua programming. More out of lazyness than anything. My approach is to simply enable or disable the “turn on” timer for the “away” scene whenever I leave or come back. See the attached screengrab. Not pretty, but it does the trick.

[quote=“gasongasoff, post:3, topic:170893”]WTH! That’s way too complicated! I have absolutely no idea how to do that. Is there some kind of plugin I can buy that will do this? Or a tutorial?

…or maybe I’m the only person who would like to have lights on a timer while I’m away…[/quote]

You’re not the only one by a long shot, and it’s not that difficult. Follow strangely’s procedure to get the virtual switch working. Once you do you will likely find a lot of other uses for it.

[quote=“strangely, post:4, topic:170893”]autoscene = luup.variable_get("urn:upnp-org:serviceId:VSwitch1","Status",DeviceID) if(autoscene=="1")then return true else return false end[/quote]

I finally sacked up and implemented this code: It didn’t work for me. My virtual switch ID is:urn:schemas-upnp-org:device:BinaryLight:1 as opposed to urn:upnp-org:serviceId:VSwitch1. Although, one is a service ID and the other is a device. Not really sure if this is the problem or not. I downloaded the virtual switch from the wiki: http://forum.micasaverde.com/index.php?topic=6375.msg40051#msg40051

I believe this code is correct for the wiki version, but the app store one is what I posted.

No way is that a service ID. Probably it’s a Device Type, not the same thing. Do this to learn what your service ID is:

  1. Have your Virtual Switch off.
  2. Go to the advanced tab for the device. Scroll and find the row called “Status”. It will have a value of zero.
  3. Now leave the Advanced tab, turn the switch on. Go back to the advanced tab and find Status again, checking it has value 1.
  4. Hover the mouse pointer on the word “Status”. A string pops up. Copy this down exactly, case, colons and all.
  5. This is the service ID that you use in your Lua code.

[quote=“futzle, post:10, topic:170893”]No way is that a service ID. Probably it’s a Device Type, not the same thing. Do this to learn what your service ID is:

  1. Have your Virtual Switch off.
  2. Go to the advanced tab for the device. Scroll and find the row called “Status”. It will have a value of zero.
  3. Now leave the Advanced tab, turn the switch on. Go back to the advanced tab and find Status again, checking it has value 1.
  4. Hover the mouse pointer on the word “Status”. A string pops up. Copy this down exactly, case, colons and all.
  5. This is the service ID that you use in your Lua code.[/quote]

Worked like a champ! Thanks

[quote=“ufd108, post:7, topic:170893”][quote=“gasongasoff, post:3, topic:170893”]WTH! That’s way too complicated! I have absolutely no idea how to do that. Is there some kind of plugin I can buy that will do this? Or a tutorial?

…or maybe I’m the only person who would like to have lights on a timer while I’m away…[/quote]

You’re not the only one by a long shot, and it’s not that difficult. Follow strangely’s procedure to get the virtual switch working. Once you do you will likely find a lot of other uses for it.[/quote]

How about turning the lights in the scene on and off at random times between x:xx and x:xx

I want to disable all my daily scenes when I am away and run a special security scene during that time. I created a virtual Switch called ‘Security’ which is normally set to off. I then pasted this code into all my scenes so that the scene only runs if security switch is off:

autoscene = luup.variable_get("urn:upnp-org:serviceId:VSwitch1","Status",19)

if(autoscene==“0”)then

return true
else
return false
end

I then created a security scene and posted the opposite command there - if(autoscene==“1”)then

So when I go away I can just toggle the virtual switch and all scenes are disabled but the one(s) I want (do it from my droid)

Is there any flaw to this logic?

[quote=“resq93, post:13, topic:170893”]I want to disable all my daily scenes when I am away and run a special security scene during that time. I created a virtual Switch called ‘Security’ which is normally set to off. I then pasted this code into all my scenes so that the scene only runs if security switch is off:

autoscene = luup.variable_get("urn:upnp-org:serviceId:VSwitch1","Status",19)

if(autoscene==“0”)then

return true
else
return false
end

I then created a security scene and posted the opposite command there - if(autoscene==“1”)then

So when I go away I can just toggle the virtual switch and all scenes are disabled but the one(s) I want (do it from my droid)

Is there any flaw to this logic?[/quote]

Nope, I do the same thing for vacation mode

[quote=“resq93, post:13, topic:170893”]I want to disable all my daily scenes when I am away and run a special security scene during that time. I created a virtual Switch called ‘Security’ which is normally set to off. I then pasted this code into all my scenes so that the scene only runs if security switch is off:

autoscene = luup.variable_get("urn:upnp-org:serviceId:VSwitch1","Status",19)

if(autoscene==“0”)then

return true
else
return false
end

I then created a security scene and posted the opposite command there - if(autoscene==“1”)then

So when I go away I can just toggle the virtual switch and all scenes are disabled but the one(s) I want (do it from my droid)

Is there any flaw to this logic?[/quote]

i want to setup your luup code but i want it the other way; run my scenes when i am away so that the lights will turn on/off. so when i toggle the virtual swtch to ON, scenes will run. when i am home i want the virtual switch to be OFF so that these scenes are disabled and not turning lights on/off. i am not good at this luup codes. may i ask what is the “19” as in your “Status”,19? is this the device ID number?. thanks.

In this case, the 19 is the device number for the virtual switch. You’ll find it by clicking the wrench on the virtual switch, then look at the top of the settings tab.

… top of the [Advanced] tab …

[quote=“aschwalb, post:14, topic:170893”][quote=“resq93, post:13, topic:170893”]I want to disable all my daily scenes when I am away and run a special security scene during that time. I created a virtual Switch called ‘Security’ which is normally set to off. I then pasted this code into all my scenes so that the scene only runs if security switch is off:

autoscene = luup.variable_get("urn:upnp-org:serviceId:VSwitch1","Status",19)

if(autoscene==“0”)then

return true
else
return false
end

I then created a security scene and posted the opposite command there - if(autoscene==“1”)then

So when I go away I can just toggle the virtual switch and all scenes are disabled but the one(s) I want (do it from my droid)

Is there any flaw to this logic?[/quote]

Nope, I do the same thing for vacation mode[/quote]

i created a scene using this luup code to arm a window sensor when the virtual switch is on but did not work. it worked on all my lights scenes. any idea please.

the below luup code works for my VS #59. when my iphone leaves the house and after 200 meters, the VS turns off automatically (using geofence in iviri) and all my door/window sensors “armed” and several scenes activate (also using PLEG). when i go back home, VS #59 turns on 200 meters before reaching my driveway and all the sensors go into “bypass” mode. i created another VS #138 for my wife’s iphone. i tried adding “AND 138” after 59 but did not work. can you or anyone help me include the new VS #138 in the luup code below. or do you think i have to create another autoscene2? thanks.

[i][b]autoscene = luup.variable_get(“urn:upnp-org:serviceId:VSwitch1”,“Status”,59)

if(autoscene==“0”)then

return true
else
return false
end[/b][/i]

Personally I would use PLEG so you do not have to deal with ServiceIDs and DeviceIDs.
You still have to get the logic right,
But for LUUP here goes:

local me = luup.variable_get("urn:upnp-org:serviceId:VSwitch1","Status",59)
local wife = luup.variable_get("urn:upnp-org:serviceId:VSwitch1","Status",138)

Now there are multiple ways to combine two or more variables:

local both_home = (me == "1") and (wife == "1")
local both_gone = (me == "0") and (wife == "0")
local either_home (me == "0") or (wife == "0")

Depending on what you want to do you will use ONE of the following at the end of the LUUP to allow the scene to run:

[ul][li]return both_home[/li]
[li]return both_gone[/li]
[li]return either_home[/li][/ul]