All - I’m trying to set up a scene to control my Thermostat and Lights when I’m away from the house. And a Home Scene when i’m home.
From a different thread, i was advised how to program the Thermostat internally and placing it into Engergy Saving Mode. This works great. I click the away scene and sets the thermostat to EMS and Home Scene when i want the Thermostat to be in Normal Mode.
I would like to take the scene control one step farther. I would like multiple lights to turn on and off at preset times to simulate that I’m home. I have modules in my Entry Way, Study and Bedroom.
Do i need to create seperate scenes to do this or can I program in the one Away scene?
Here is what I want; Away Scene
Thermostat - EMS
Entry Light to turn on at 6pm and turn off at 9pm
Study lamp to turn on at 7pm and turn off at 10pm
Bedrrom lamp to turn on at 9pm and turn off at 11pm.
A scene is a way of combining a number of commands, events, timers into one “Action”. Being able to define basic scenes with multiple commands is the 1st step to having a powerful home automation setup.
For example, my “House Lockdown” scene:
[ul][li]sets all of my lights to off[/li]
[li]arms my motion sensors (after 5 minute delay)[/li]
[li]turns off the outlets that control my TV/Stereo/CableBox[/li]
[li]sets the Thermostat to ESM[/li]
[li]turns off the outlets that control my TV/Stereo/CableBox[/li]
[li]shuts off my Ooma Telo (phone)[/li]
[li]etc. etc. [/li][/ul]
I also have a Scene named Security Lights that turns on a few different lights X minutes after sunset, and then sets them back to their previous state after Y minutes. Each light has a different length of time it stays on. This Scene runs all by itself (because it’s triggered by an Event and/or Timers).
What you want to do is a bit complicated, but it can be done. For each separate time that you want an action to be done, you need to have a separate scene. I would create an on scene for each light and an off scene for each light. You could have them turn on at a certain time and turn off at some delta time. However, this is not 100% reliable. If you lose power to your Vera or it happens to reboot, the things that are delayed will not happen.
Next you need to use a virtual switch to indicate whether you are away or home. This is simply like a real switch but there is no actual switch attached to what shows in the dashboard. More about this later.
Now when your scenes are created, they will run every day. To allow them to run only when away, you turn the away virtual switch on. Add some luup code to each scene that you want to operate only in away mode:
local away
away = luup.variable_get(“urn:upnp-org:serviceId:SwitchPower1”,“Status”,nn)
if(away==“0”)then
return false
end
Where the nn appears above, insert the device ID of the virtual switch. This can be found on the top of the settings page of the virtual switch. This code will prevent the scene from doing anything if the virtual switch is in the off position.
For instructions on how to implement a virtual switch see replies 3 and 4 of:
wscannell: Pls don’t take this the wrong way, but I don’t understand why the recommendation to a clearly-brand-new-Vera-user would start with editing luup code and creating virtual switches. Yes, most of us do that, but then again we’re (stupid/crazy/obsessed/relentless?!?) experienced Vera users with scars to prove it.
IMHO, most of what he wants to do can be done via the standard Scenes, Commands, Timers and Events.
Let’s guide him, and others, to the 90% solution that doesn’t require 3 eyes of newt and a cauldron of boiling batwing!
All thanks for the help. I think i understand. I have used the d_ and I_ statedevice.xlm files ans created the virtual switch. I have created a scene with a timer to turn on a light. I’m a bit lost now on how to link the together. I’m not a programmer by any means, but can navigate through it with a little direction.
I will continue to figure this out. I appreciate all the help so far. The forum is full of great information; just finding what information can help is a bit difficult.
When you’ve created the scenes you want to run when you are “away” you need an indicator that shows when you are away. Thats where the virtual / state device comes into play.
We will assume when the state device is “On” you are home and when it’s 'Off" you are away. Only when the State device is off is when your away scenes will run.
Drop the code that @wscannell posted above into the Luup area of each “Away” scene and change the “nn” to that of the state devices device number:
away = luup.variable_get("urn:upnp-org:serviceId:SwitchPower1","Status",nn)
if(away=="0")then
return false
end
Click save on the Luup tab and then save on the dashboard.
Check the scenes. Turn the virtual device “Off” (you are away) and click run scene. The scene should run.
Turn the virtual device “On” (you are home) click run scene. The scene should not run.
Hope that helps.
*Edit. As oTi@ points out below, this scenario is the reverse of what was called for and is my “Home” setup not “Away” Please adjust your scene setup accordinly.
Is there a way to change "on" to read Away and "off" to read Home on the virtual buttons?
No, not currently, I believe. (@JOD was looking into it.)
I guess @JOD’s example may do the opposite of what was promised. It returns false when the state device has status 0, meaning the scene is aborted (i.e. the commands not executed) when the state device is off.
Of course it all depends on what you want, and what you want Home / Away to be.
Do check out @JimMac’s stuff too, as suggested; lots of info there.
Hey hey hey, I made no promises!! Actually I made assumptions.
But thats a typical scenario, you get a piece of code and you work with it and make adjustments. OR, as oTi@ points out you make the poster eat crow.
Ok, so if it’s inverted as to how you want the Virtual Device to display (the light is on but no one is home) then you could install the inverted D_ file which should give you the opposite effect.
*Edit. As oTi@ points out above, this scenario is the reverse of what was called for and is my “Home” setup not “Away” Please adjust your scene setup accordingly.
OR you can change the code from (away==“0”) to (away~=“0”)
Got it - The Virtual Switch Works Perfectly. The Lights are turning on / off with the timers based on the on / off on the switch.
Now my last question. I have two scene for the my Thermostat. One sets to EMS and the other sets to Normal. Can I link the Virtual Switch to those scenes? Is it possible to run the scene based on the input from the virtual switch?
You do not need any Luup code for the away thermostat scenes. Add an event to your scene in the event tab of the scene. Then select the virtual switch. Select event type “a device is turned on or off”. For the scene that you want to run when you go away, set the which mode to on and save.
The scene should run when you turn the virtual switch on. You can turn it on from the dashboard. I have something like this in my setup and I just tested it.
If that does not work, test the scene by clicking on the run button from the dashboard. See if it does the correct thing.
Err - Frustrating. I understand exactly what is being said. I also think it should work. I run the scenes “away” and it set my Thermostats at ESM, and run “Home” it set back to normal. The scenes are working.
I link the scenes to the Virtual Switch - “Energy Saving Mode” and nothing happens to the scenes. I have attached a couple screen shots of the Dashboard, My Virtual Switch Advanced Tab, Away Sceen Event Tab, Away Summary showing 2 commands and 1 event linked.
The two commands is for two thermostats.
The scenes work on their own when run, however do not trigger from the virtual switch. The other frustating bit is I have the virtual switch contoling three lights which are on timer scenes. When i press on, the lights follow the timers. At least i think they do, the lights come on like they should, i assume the timers are functioning.
What code do you have in the Luup tab of your scene? How are you toggling the state of your virtual switch?
Try toggling your “Energy Saving Mode” virtual switch using Luup code. I have had issues where switching it in the command section does not always work.
The best way to test this out is to keep it simple. Add the code below to the Luup tab in a new scene. Run the scene and observe the status of your “Energy Saving Mode” switch. It should change from off to on/on to off every time your run the scene. If this works then your virtual switch is working.
local Energy_Mode=luup.variable_get(“urn:upnp-org:serviceId:SwitchPower1”,“Status”,11)
if (Energy_Mode == “1”) then
luup.variable_set(“urn:upnp-org:serviceId:SwitchPower1”,“Status”,0,11)
else
luup.variable_set(“urn:upnp-org:serviceId:SwitchPower1”,“Status”,1,11)
end