Forgive the novice question…I have admittedly not taken the time to learn scripting in Lua yet. But before I do, a question…
Can I use Lua code in one scene to enable or disable a timer event in another scene? Here’s my use-case:
I have a scene with timer that turns on “Evening” lighting every night just before sunset. However, when I’m not home (this is my weekend house), I don’t want that scene/timer to run. Conversely, when I’m at the weekend house, I do. I have two other scenes I use - one I run before I arrive at the house, and it sets the thermostat and turns on a bunch a A/V equipment, etc. The other scene I run when I leave the house, and it does the opposite. At present, I’m having to manually enable/disable that timer through FindVera everytime I arrive/leave my house. I’d like my pre-arrival & departure scenes to be able to enable/disable that timer in my other “Evening” scene instead. Doable?
I do something similar. I created a virtual device based on the D_MotionSensor1.xml file. After some period of time, this new device will show its UI in particular the ARM and BYPASS push buttons (it does take awhile). I lableled my device ‘We Are Gone’ and its nothing more than a binary flag. You will also get a device number.
Then in your timed scene(s), you add the following LUUP code. It returns false the virtual flag is BYPASSED, or true if its ARMED. You may want to reverse it. But the bottom line is the scene (where you have lights come on, etc.) will only run if this code returns true.
Good luck,
Brian
Oh, WAGDevice2 is the virtual device added above. WAG = We Are Gone
local WAGDevice2=17
local WAGStatus2 = luup.variable_get(“urn:micasaverde-com:serviceId:SecuritySensor1”,“Armed”,WAGDevice2)
if (WAGStatus2 == “0”) then
return false
end
return true
This is great - thank you. So my only follow-on question would be…
Do I have to actually define a virtual device? I do have a motion sensor in my network, and I do bypass it when I’m home and arm it when I’m gone, so theoretically, it provides the same flag as the virtual device in your code sample. Unless I’m missing something, I should be able to just refer to my HSM100 sensor status, rather than creating a virtual device, right?
Yes, that should work. The key is the ARM or BYPASS status of the device gets tested. Obviously you’d want to replace my ‘device 17’ with the appropriate device you use.
There are always many ways to get something done! I use the virtual device based on a binary switch, some use the version based on a motion sensor. To create your virtual device you will need the appropriate D_ and I_ files. Binary switch files can be found at Box. The first step is to download/unpack the files, then upload D_StateDevice.xml and I_StateDevice.xml to your Verde. On your Verde (UI4), click on the MiOS developers icon in the tool box, go to the Luup files tab. Scroll to the bottom and find a file upload option. The second step is to create your virtual device. Go to the “Create device” tab of the MiOS developers panel, enter a name in the Description field, D_StateDevice.xml in the UpnpDevFilename field, I_StateDevice.xml in the UpnpImplFilename field, pick a room (optional) then click “Create Device.” Verde might not create the device as an on/off switch right away, do a system recycle (the round arrows under the clock in the upper right) and after a minute or two Verde will refresh and the new virtual device should be operational.
Using the binary virtual device is similar to the motion sensor with two minor changes. The urn and variable name requested are different. Here’s the same line of code (provided in brsipaq’s example above) written to work with the StateDevice type virtual device.
local WAGStatus2 = luup.variable_get("urn:upnp-org:serviceId:SwitchPower1", "Status", WAGDevice2)
I use virtual devices for a variety of reasons, including suspending light and HVAC changes when there is a party (Party Mode), and running the second floor HVAC at a more comfortable level when we have overnight guests (Guest Mode).
Total noob here, but am trying to implement this idea:
I want to setup a Holiday schedule and a vacation schedule. The holiday schedule would have the days that we are do not have to go to work so that I can keep the thermostat at the correct “at home” level, lights, etc. The vacation mode would be the opposite - thermostat is held at a certain temp until we get back - lights don’t automatically turn on, etc.
So I’ve uploaded the statedevice files and created a new device in UI4 (with the new release). The device does get created, but there are no buttons on the device to turn it on or off or display it’s current status. Is that normal? I understand I can set the state from code, but I really need to at least be able to view the current state of the device from ui4 interface. Does anyone have any suggestions for me?
On my vacation scene (the scene that sets my vacation status), I also set back the thermostat to a specific temperature (57F for me). Then vacation return (I am back home) sets the thermostat back up to 62 (if tomorrow is a work day) or 63 (if tomorrow is a day off). My lower the thermostat temperature scene also interrogates the status (vacation/go to work/stay home) when setting the temperature down.
So I can tell by looking at my thermostat to see what Vera thinks is the current state.
Ok, just so I understand, there is no way to view the status of one of these switches from the dashboard, correct? I’m trying to figure out an easy way to know which “mode” i’m in (Home, Away, Vacation)
Works for me. Had to restart the Lua engine several times after installation to get it working (click the round arrows under the clock in the upper right).
Ok, I’ve tried restarting the lua engine 10 times, rebooting vera 2 twice, and still don’t see the on/off buttons. Is there something I’m missing? I’m using the latest release of the software.
Thanks for any and all help. I would really like to be able to see the status of this virtual device.
@sdfoiler, I too have the same issue, I’m able to create the device but am not able to get on/off buttons, I’ve restarted the lua engine multiple times event did the Ctrl F5 in the hopes of updating the device with no avail… Ok Ap15e what are we missing, when I look a the device I have a N/A for device options and a relatively simple advance tab with the devices as generic_device_file as D_Devicestate.xml and Impl_file as I_Devicestate.xml. Any help would be greatly apprieciated, looking at another thread there seems various Devicestate files?
Upload the [tt]D[/tt] and [tt]I[/tt] files, create a new device “SD” with [tt]D_StateDevice.xml[/tt], restart the Lua engine at least two times.
Test your installation:
Setup a scene with event “A device is turned on/off: On” for device “SD” and command “SD off”. Switch the “SD” device on, it should get switched off. Do the same for “Off”/“SD On”.
@Ap15e, many thanxs works wonderfully. Question in your post [font=Verdana]Test your installation:
Setup a scene with event “A device is turned on/off: On” for device “SD” and command “SD off”. Switch the “SD” device on, it should get switched off. Do the same for “Off”/“SD On”[/font]. I’m a little confused, if I set an event device: “SD” and What type of event is the trigger? “On/Off and Which mode” “Off” That would imply that when I toggle the SD to “off” position it triggers the device(s) that I selected in the Commands Tab to execute and this device should be set to the On position seems backward. I’m assuming that I have to make a second scene/Event that address SD “On” and the command tab device should be set to the “Off” position so that if I toggle SD from On to Off the selected device reacts accordingly? Next question can I use this SD to control scene(s) instead of devices? thanxs Mike
Appreciate all the virtual device pointer, but that seems to be a long way around when I have an ACTUAL device whose “state” is already being maintained. Inside S_SceneControllerLED1 there is the following state table:
Light
ui1
which I would imagine is tracking the state of each of the LEDs, as the scene controller device UI has the ability to set which scenes to run when button is turned “on” and “off”.
I have the following line of code that should extract the state of the light Im interested in, but it keeps returning nil;
local holiday_mode=luup.variable_get(“urn:micasaverde-com:serviceId:SceneControllerLED1”,“Light[4]”,11)
If there is something Im missing, or not doing properly in LUA (not really expert on LUA
coding), I’d be grateful if someone could point it out.
OK, I have a device called ‘virtual 1’ working properly using the instructions above.
The first step is to download/unpack the files, then upload D_StateDevice.xml and I_StateDevice.xml to your Verde. On your Verde (UI4), click on the MiOS developers icon in the tool box, go to the Luup files tab. Scroll to the bottom and find a file upload option. The second step is to create your virtual device. Go to the “Create device” tab of the MiOS developers panel, enter a name in the Description field, D_StateDevice.xml in the UpnpDevFilename field, I_StateDevice.xml in the UpnpImplFilename field, pick a room (optional) then click “Create Device.”
Question 1: can I create more virtual devices using the same, already uploaded D_StateDevice.xml and I_StateDevice.xml files? Can ‘virtual 1’, ‘virtual 2’, ‘virtual 3’, and so on ALL use the same original .xml files?
Question 2: How/where do I delete my user uploaded xml file if I ever need to?