We have moved at community.getvera.com

Author Topic: Using Lua code in a scene to enable/disable a timer in another scene  (Read 26270 times)

Offline Sig

  • Sr. Member
  • ****
  • Posts: 377
  • Karma: +2/-3
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?

Offline brsipaq

  • Jr. Member
  • **
  • Posts: 54
  • Karma: +1/-0
Re: Using Lua code in a scene to enable/disable a timer in another scene
« Reply #1 on: November 04, 2009, 10:02:56 am »
slackner,

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








« Last Edit: November 04, 2009, 10:21:36 am by brsipaq »
Controllers - Vera firmware 979 Dongle version 2.78 L:1, GE 45601 and 45608, HA07c, HA09c
Outlets/Switches - HA01c, (2) HA02c, (4) VRI06, (2) VRS15, HA04c (Not used yet) Sensor - HRDS1 Door/Window (garage door) Thermostat - WDTC-20 IP Camera - Linksys WVC54GCA

Offline Sig

  • Sr. Member
  • ****
  • Posts: 377
  • Karma: +2/-3
Re: Using Lua code in a scene to enable/disable a timer in another scene
« Reply #2 on: November 04, 2009, 02:57:00 pm »
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?

Offline brsipaq

  • Jr. Member
  • **
  • Posts: 54
  • Karma: +1/-0
Re: Using Lua code in a scene to enable/disable a timer in another scene
« Reply #3 on: November 04, 2009, 08:57:23 pm »
slackner,

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.

Brian
« Last Edit: November 04, 2009, 08:59:56 pm by brsipaq »
Controllers - Vera firmware 979 Dongle version 2.78 L:1, GE 45601 and 45608, HA07c, HA09c
Outlets/Switches - HA01c, (2) HA02c, (4) VRI06, (2) VRS15, HA04c (Not used yet) Sensor - HRDS1 Door/Window (garage door) Thermostat - WDTC-20 IP Camera - Linksys WVC54GCA

Offline HilH

  • Sr. Newbie
  • *
  • Posts: 25
  • Karma: +0/-0
Re: Using Lua code in a scene to enable/disable a timer in another scene
« Reply #4 on: January 15, 2011, 03:26:43 pm »
Is this still the best way to do this?

If so, how do I go about adding a virtual device in the current Vera2 system?

Offline Guard

  • Jr. Member
  • **
  • Posts: 58
  • Karma: +0/-0
Re: Using Lua code in a scene to enable/disable a timer in another scene
« Reply #5 on: January 15, 2011, 07:01:52 pm »
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 http://www.box.net/shared/nj26aa91h5.  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.

Code: [Select]
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).
Vera2, Cooper RF9518 x3; GE/Jasco 45609 x3, 45604 x5, 45603 x4, 45602, 45605 x3; 2Gig Thermostat x3

Offline sdfoiler

  • Newbie
  • *
  • Posts: 6
  • Karma: +0/-0
Re: Using Lua code in a scene to enable/disable a timer in another scene
« Reply #6 on: February 06, 2011, 11:07:24 pm »
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?

Thanks in advance!!!

Offline aa6vh

  • Hero Member
  • *****
  • Posts: 642
  • Karma: +15/-0
Re: Using Lua code in a scene to enable/disable a timer in another scene
« Reply #7 on: February 07, 2011, 11:10:10 am »
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.

Offline sdfoiler

  • Newbie
  • *
  • Posts: 6
  • Karma: +0/-0
Re: Using Lua code in a scene to enable/disable a timer in another scene
« Reply #8 on: February 08, 2011, 01:08:56 pm »
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)


Offline Ap15e

  • Beta Testers
  • Hero Member
  • *****
  • Posts: 1998
  • Karma: +12/-0
Re: Using Lua code in a scene to enable/disable a timer in another scene
« Reply #9 on: February 08, 2011, 02:39:04 pm »
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).
« Last Edit: February 08, 2011, 02:40:59 pm by Ap15e »

Offline sdfoiler

  • Newbie
  • *
  • Posts: 6
  • Karma: +0/-0
Re: Using Lua code in a scene to enable/disable a timer in another scene
« Reply #10 on: February 08, 2011, 11:06:43 pm »
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.


Offline MNB

  • Hero Member
  • *****
  • Posts: 689
  • Karma: +4/-9
Re: Using Lua code in a scene to enable/disable a timer in another scene
« Reply #11 on: April 03, 2011, 09:31:40 pm »
@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?
Edge-1.7.2607, VRI06-1LX Dimr (6), VS05-1LX Sw (4), GE ZW3002 Dimr (1), HA01C Outlet (12), HA02C Sw (6), HA04C Sw (4), GE Sw (2), HA05 Sw (3), MiniMote Contr (5), HSM200/100 Sensor (2), ZW100A Sensor (8), Nest thermostat (1) & Protect Fire/CO (6) Kwikset Locks (3), F18918W (1) & IP3M-9 (6) Cam's

Offline MNB

  • Hero Member
  • *****
  • Posts: 689
  • Karma: +4/-9
Re: Using Lua code in a scene to enable/disable a timer in another scene
« Reply #12 on: April 03, 2011, 09:41:12 pm »
Looking at the zip file content seems to have a Oct 09 creation date problem? it has the same date that the oct 09 Rar file has.
Edge-1.7.2607, VRI06-1LX Dimr (6), VS05-1LX Sw (4), GE ZW3002 Dimr (1), HA01C Outlet (12), HA02C Sw (6), HA04C Sw (4), GE Sw (2), HA05 Sw (3), MiniMote Contr (5), HSM200/100 Sensor (2), ZW100A Sensor (8), Nest thermostat (1) & Protect Fire/CO (6) Kwikset Locks (3), F18918W (1) & IP3M-9 (6) Cam's

Offline MNB

  • Hero Member
  • *****
  • Posts: 689
  • Karma: +4/-9
Re: Using Lua code in a scene to enable/disable a timer in another scene
« Reply #13 on: April 05, 2011, 12:02:42 pm »
@Ap15e can you help us.. why can't we get our Devicestate to produce on/off switches what are we missing?
Edge-1.7.2607, VRI06-1LX Dimr (6), VS05-1LX Sw (4), GE ZW3002 Dimr (1), HA01C Outlet (12), HA02C Sw (6), HA04C Sw (4), GE Sw (2), HA05 Sw (3), MiniMote Contr (5), HSM200/100 Sensor (2), ZW100A Sensor (8), Nest thermostat (1) & Protect Fire/CO (6) Kwikset Locks (3), F18918W (1) & IP3M-9 (6) Cam's

Offline Ap15e

  • Beta Testers
  • Hero Member
  • *****
  • Posts: 1998
  • Karma: +12/-0
Re: Using Lua code in a scene to enable/disable a timer in another scene
« Reply #14 on: April 06, 2011, 05:00:12 am »
What works for me (V2@1.1.1234):

Download denix' StateDevice files from http://forum.micasaverde.com/index.php?topic=5665.msg33010#msg33010.

Add

Code: [Select]
<staticJson>D_BinaryLight1.json</staticJson>

to D_StateDevice.xml:

Code: [Select]
[...]
<deviceType>urn:schemas-upnp-org:device:BinaryLight:1</deviceType>
<staticJson>D_BinaryLight1.json</staticJson>
<friendlyName>StateDevice</friendlyName>
[...]

Upload the D and I files, create a new device "SD" with D_StateDevice.xml, 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".