<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="http://wiki.mios.com/skins/common/feed.css?303"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>http://wiki.mios.com/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Solipsia</id>
		<title>MiOS - User contributions [en]</title>
		<link rel="self" type="application/atom+xml" href="http://wiki.mios.com/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Solipsia"/>
		<link rel="alternate" type="text/html" href="http://wiki.mios.com/index.php/Special:Contributions/Solipsia"/>
		<updated>2026-04-19T01:05:29Z</updated>
		<subtitle>User contributions</subtitle>
		<generator>MediaWiki 1.19.8</generator>

	<entry>
		<id>http://wiki.mios.com/index.php/Luup_Scenes_Events</id>
		<title>Luup Scenes Events</title>
		<link rel="alternate" type="text/html" href="http://wiki.mios.com/index.php/Luup_Scenes_Events"/>
				<updated>2012-09-09T12:23:40Z</updated>
		
		<summary type="html">&lt;p&gt;Solipsia: /* Switch on, and switch off 2 seconds later */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Adding Lua code to scenes and events  ==&lt;br /&gt;
&lt;br /&gt;
[[Image:SceneFlowchart.png]] &lt;br /&gt;
&lt;br /&gt;
You can add Lua script to scenes and events for simple tasks, like making a scene or event conditional. Conditional meaning &amp;quot;do something only '''if''' some condition is met&amp;quot;, such as attaching a condition to your &amp;quot;Come Home&amp;quot; scene so it is only run '''if''' the temperature is over 70 degrees. Basic conditional expressions are easy, and, if that's all you're looking to do, skip to the walk-through below. &lt;br /&gt;
&lt;br /&gt;
If you're more technically inclined you can also do very advanced things too. For an overview of all the advanced things you can do with Vera's Luup engine, and how scenes and events fit in, see the [[Luup Intro]] page. &lt;br /&gt;
&lt;br /&gt;
To add Lua code to a scene, create the [[Scenes]] and click 'Luup scene'. Fill in your Lua code in the input box. To do a simple condition, see the sample below. Or if you want to do advanced scripting you can use any [[http://lua.org Lua]] commands as described in the [[http://www.lua.org/manual/5.1/ Lua reference manual]] as well as the variables and functions that the Luup engine adds to Lua documented here: [[Luup Lua extensions]]. The Lua code will be run every time the scene is activated either by the user or a scene or a timer. The Lua code is run before the commands that you included in the scene. If your Lua code ends with this: &amp;quot;return false&amp;quot; then the commands in the scene will not be run. &lt;br /&gt;
&lt;br /&gt;
You can also add Lua code to an event by clicking 'Luup event'. Since events are attached to scenes anyway, there is usually little difference between adding the code to an event, or to the scene the event is part of. If the Lua code in an event returns false, then the event is aborted, meaning the scene that the event is attached to will not be triggered by the event. The main reason for attaching Lua code to an event is if you have multiple events to a scene. For example, you may have a scene called &amp;quot;Turn lights on in hallway&amp;quot; which is triggered by 2 events: 1) The front door opens, and 2) the motion sensor in the hallway is tripped. Perhaps whenever the front door opens you always want the scene to be activated, but you only want the motion sensor to activate the scene before 10:00. In this case, you would add Lua code to the motion sensor's event which does something like (pseudo-code): &amp;quot;if time&amp;amp;gt;10:00 return false&amp;quot;. That way the event from the motion sensor will be aborted if it's after 10:00, but the event from the front door will always activate the scene regardless. &lt;br /&gt;
&lt;br /&gt;
When you edit the Lua code in a scene or event you must click 'Save' before the code is saved. Then you can activate the scene or trigger the event to see what happens when your code is run. If you're doing some advanced scripting that you'll need to debug this can be tedious, but there are easy ways to test your Lua script immediately without saving first as explained in [[Lua Debugging]]. &lt;br /&gt;
&lt;br /&gt;
If you're doing advanced Lua scripting, you should note that all the Lua code in your scenes and events run in a single Lua instance, which is separate from any Lua plugins. This means if you set a global variable in one scene, or create a function inside the Lua code in a scene, then in another scene's Lua code you can use that global variable or call that function. You do not need to worry about conflicting with a Luup plugin, though, since they have their own Lua instance, meaning they have their own global variables and functions. &lt;br /&gt;
&lt;br /&gt;
== Walk-through #1 -- At 12 noon, turn off the interior lights if the temperature is over 80 degrees  ==&lt;br /&gt;
&lt;br /&gt;
Before you start, in Vera's setup interface go to 'Devices' and click the '+' button next to the thermostat. Make note of the Device #. &lt;br /&gt;
&lt;br /&gt;
In this walkthrough we'll assume it's Device #3, but use the actual device number of''your'' thermostat. Next, visit [[Luup Variables]] to get a list of all the variables for devices. A variable is a piece of information about the current state of a device, such as whether it's on or off, it's current temperature, etc. &lt;br /&gt;
&lt;br /&gt;
Look down at ''Thermostat'', and copy the name of the service/variable which corresponds to the current temperature, namely. In this case, it's &lt;br /&gt;
&lt;br /&gt;
  urn:upnp-org:serviceId:TemperatureSensor1 CurrentTemperature&lt;br /&gt;
&lt;br /&gt;
Notice that it states the &amp;lt;tt&amp;gt;CurrentTemperature&amp;lt;/tt&amp;gt; is in Celsius. So type in &amp;quot;80 degrees Fahrenheit to Celsius&amp;quot; in Google and you'll see that it's 26.6 degrees Celsius. &lt;br /&gt;
&lt;br /&gt;
Now, the first step is to create the scene that turns off the lights. In Vera's setup interface, click 'Scenes', and click 'Add Scene' to add a new scene to one of the rooms. It's not important which room you choose. Scenes are categorized in rooms just to help you keep track of them if you have a lot of scenes. You can also put the scene in 'Global Scenes', or, you can create dummy rooms on the 'Rooms' tab if you want to have more &amp;quot;rooms&amp;quot; to organize your scenes with. After you click 'Add Scene', type in a description to remember your scene by, such as &amp;quot;Lights off 12:00 if 80&amp;quot;. Under the 'Commands' area you'll see all the rooms. Click '+' next to the rooms that have lights you want to control, and choose &amp;quot;Off&amp;quot; in the pull-down. At this point, you have a normal scene, and, if you were to save your changes now, whenever you click the scene on the dashboard or on a remote control, the lights should turn off. &lt;br /&gt;
&lt;br /&gt;
Second, next to the scene's description click 'add timer'. You can give the timer a description too so that if you have multiple timers you can see in the logs which one is activating the scene. Choose &amp;quot;Day of week based&amp;quot;. If you want this scene to only run on certain days of the week, just check off which days you want this scene to run on. Otherwise, you can leave them all unchecked (or check them all) to do it every day. Leave the pull-down at &amp;quot;a certain time of day&amp;quot;, and choose 12&amp;amp;nbsp;: 00&amp;amp;nbsp;: 00 from the pull-downs. At this point, if you were to save your changes, the lights would turn off automatically at 12 noon. &lt;br /&gt;
&lt;br /&gt;
Third, the last step is to add the condition. To the right of the scene's description you'll see the button &amp;quot;Luup Scene&amp;quot;. Click it and in the code box, copy and paste the following: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
  local lul_temp = luup.variable_get(&amp;quot;urn:upnp-org:serviceId:TemperatureSensor1&amp;quot;,&amp;quot;CurrentTemperature&amp;quot;, 3)&lt;br /&gt;
  if (tonumber(lul_temp) &amp;lt; 26.6) then&lt;br /&gt;
    return false&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/source&amp;gt; &lt;br /&gt;
&lt;br /&gt;
Don't forget to change the &amp;quot;3&amp;quot; to whatever is the actual device number of your thermostat. Assign the result of &amp;lt;tt&amp;gt;luup.variable_get&amp;lt;/tt&amp;gt; to a variable first, rather than putting it directly in the &amp;lt;tt&amp;gt;tonumber()&amp;lt;/tt&amp;gt;, because &amp;lt;tt&amp;gt;luup.variable_get&amp;lt;/tt&amp;gt; actually returns 2 values: the value of the variable, and the time when the variable was modified. The '&amp;lt;tt&amp;gt;tonumber&amp;lt;/tt&amp;gt;' is needed because all of a device's variables are stored as plain text--not numbers--so if you want to do arithmetic or numeric comparison of a variable, you need to put &amp;lt;tt&amp;gt;tonumber()&amp;lt;/tt&amp;gt; around &amp;lt;tt&amp;gt;luup.variable_get&amp;lt;/tt&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;luup.variable_get&amp;lt;/tt&amp;gt; is documented in [[Luup Lua extensions]]. &lt;br /&gt;
&lt;br /&gt;
Now click 'Update', and then click 'Save' to save everything. The &amp;quot;return false&amp;quot; means &amp;quot;don't run this scene&amp;quot;. So if the current temperature is &amp;amp;lt;26.6, the scene will be aborted and won't run. The timer will make it trigger every day at 12 noon. &lt;br /&gt;
&lt;br /&gt;
To test it, you can click the scene button on the dashboard. The lights will turn off only if the temperature is over 80 degrees. If it's less than 80 degrees, the scene won't do anything. Since this scene is something that happens automatically and you probably won't execute manually, you can go to the scene again and check the &amp;quot;Hidden&amp;quot; box so the scene doesn't show up on&amp;amp;nbsp;Vera's 'Dashboard' and on your remote controls, like the iPhone. If you want to have a scene that turns off the lights which you can run whenever you want from 'Dashboard''or your remote control, you should create another scene that has the same commands and simply don't add the timers and Luup conditions, and don't check the &amp;quot;Hidden&amp;quot; box. '' &lt;br /&gt;
&lt;br /&gt;
You can substitute other service/variables and device ID's to make other types of conditions. The &amp;quot;if&amp;quot; statement above also supports nesting with ( and ), as well as the keywords 'and' and 'or'. So the following means the scene would abort if the temperature is &amp;amp;lt;26.6 and &amp;amp;gt;25, unless it's &amp;amp;lt;23: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
  local lul_temp = luup.variable_get(&amp;quot;urn:upnp-org:serviceId:TemperatureSensor1&amp;quot;,&amp;quot;CurrentTemperature&amp;quot;, 3)&lt;br /&gt;
  if ((tonumber(lul_temp) &amp;lt; 26.6&lt;br /&gt;
    and tonumber(lul_temp) &amp;gt; 25)&lt;br /&gt;
    or tonumber(lul_temp) &amp;lt; 23) then&lt;br /&gt;
      return false&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/source&amp;gt; &lt;br /&gt;
&lt;br /&gt;
If the scene doesn't run, it's possible&amp;amp;nbsp;there is&amp;amp;nbsp;a syntax error. The easiest way to test this is to copy the Lua code from the scene, then go to Devices, Luup Plugins, and &amp;quot;Test Luup code&amp;quot;. Paste the code in the box and click 'go'. If the info box above the 'go' button has a check and says &amp;quot;Message sent successful&amp;quot;, your code is okay. If there's an error, it says: &amp;quot;Code failed&amp;quot;. &lt;br /&gt;
&lt;br /&gt;
To see if that's true, use putty, or telnet or ssh to log-in to Vera, as explained in detail in [[Logon_Vera_SSH]] and [[Lua Debugging]], and type: &lt;br /&gt;
&lt;br /&gt;
   cd /var/log/cmh&lt;br /&gt;
 tail -f LuaUPnP.log | grep '^01'&lt;br /&gt;
&lt;br /&gt;
Now click 'Save' in Vera's setup page, even if it's gray, as that will cause Vera to restart the Luup engine and log any syntax errors. See: [[Lua Debugging]] for in-depth details on how to debug.&lt;br /&gt;
&lt;br /&gt;
== Walk-through #2 -- Only run the scene during the daytime  ==&lt;br /&gt;
&lt;br /&gt;
In the Luup tab for the scene paste this: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
  return luup.is_night() == false&lt;br /&gt;
&amp;lt;/source&amp;gt; &lt;br /&gt;
&lt;br /&gt;
That works because if the return is 'true' the scene runs, and if it's 'false' it doesn't. So during the daytime the expression is true. Or, an alternative long form: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
  if (luup.is_night()) then&lt;br /&gt;
     return false&lt;br /&gt;
  else&lt;br /&gt;
     return true&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/source&amp;gt; &lt;br /&gt;
&lt;br /&gt;
== Samples  ==&lt;br /&gt;
&lt;br /&gt;
This page is a wiki which anyone can edit. If you have some Lua code you think other users might find useful, feel free to add it here. &lt;br /&gt;
&lt;br /&gt;
=== Lighting and Switch Actions  ===&lt;br /&gt;
&lt;br /&gt;
Did you see the sample here already: http://wiki.micasaverde.com/index.php/Luup_Scenes_Events &lt;br /&gt;
&lt;br /&gt;
==== Turn an appliance switch or a Danfoss thermostat on for device #5  ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
  luup.call_action(&amp;quot;urn:upnp-org:serviceId:SwitchPower1&amp;quot;, &amp;quot;SetTarget&amp;quot;, {newTargetValue = &amp;quot;1&amp;quot;}, 5)&lt;br /&gt;
&amp;lt;/source&amp;gt; &lt;br /&gt;
&lt;br /&gt;
==== Turn an appliance switch or a Danfoss thermostat off  ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
  luup.call_action(&amp;quot;urn:upnp-org:serviceId:SwitchPower1&amp;quot;, &amp;quot;SetTarget&amp;quot;, {newTargetValue = &amp;quot;0&amp;quot;}, 5)&lt;br /&gt;
&amp;lt;/source&amp;gt; &lt;br /&gt;
&lt;br /&gt;
==== Do something if switch device #5 is on  ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
  local lul_tmp = luup.variable_get(&amp;quot;urn:upnp-org:serviceId:SwitchPower1&amp;quot;, &amp;quot;Status&amp;quot;, 5)&lt;br /&gt;
  if (lul_tmp == &amp;quot;1&amp;quot;) then&lt;br /&gt;
     --something to do goes here&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/source&amp;gt; &lt;br /&gt;
&lt;br /&gt;
==== Dim switch #6 to 30%  ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
  luup.call_action(&amp;quot;urn:upnp-org:serviceId:Dimming1&amp;quot;, &amp;quot;SetLoadLevelTarget&amp;quot;, {newLoadlevelTarget = &amp;quot;30&amp;quot;}, 6)&lt;br /&gt;
&amp;lt;/source&amp;gt; &lt;br /&gt;
&lt;br /&gt;
====Switch on, and switch off 2 seconds later ====&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
local device  = 29&lt;br /&gt;
-- Switch on device 29:&lt;br /&gt;
luup.call_action(&amp;quot;urn:upnp-org:serviceId:SwitchPower1&amp;quot;,&amp;quot;SetTarget&amp;quot;,{ newTargetValue=&amp;quot;1&amp;quot; },device)&lt;br /&gt;
luup.call_delay( 'switch_off', 2) -- Call the switch off function after a delay of 2 seconds&lt;br /&gt;
function switch_off()&lt;br /&gt;
   luup.call_action(&amp;quot;urn:upnp-org:serviceId:SwitchPower1&amp;quot;,&amp;quot;SetTarget&amp;quot;,{ newTargetValue=&amp;quot;0&amp;quot; },device)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Blinking lights (and how to delay for a number of seconds)  ====&lt;br /&gt;
&lt;br /&gt;
http://forum.micasaverde.com/index.php?topic=5127.0&lt;br /&gt;
&lt;br /&gt;
=== Motion Sensor Actions  ===&lt;br /&gt;
&lt;br /&gt;
==== Arm motion sensor #7  ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
  luup.variable_set(&amp;quot;urn:micasaverde-com:serviceId:SecuritySensor1&amp;quot;, &amp;quot;Armed&amp;quot;, &amp;quot;1&amp;quot;, 7)&lt;br /&gt;
&amp;lt;/source&amp;gt; &lt;br /&gt;
&lt;br /&gt;
==== Disarm motion sensor #7  ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
  luup.variable_set(&amp;quot;urn:micasaverde-com:serviceId:SecuritySensor1&amp;quot;, &amp;quot;Armed&amp;quot;, &amp;quot;0&amp;quot;, 7)&lt;br /&gt;
&amp;lt;/source&amp;gt; &lt;br /&gt;
&lt;br /&gt;
Note, arming and disarming isn't a concept within UPnP or Z-Wave. It's just a flag that the Luup engine uses, and is stored in a variable we created called &amp;quot;Armed&amp;quot;. &lt;br /&gt;
&lt;br /&gt;
=== Scene Actions  ===&lt;br /&gt;
&lt;br /&gt;
==== Run Scene #5  ====&lt;br /&gt;
&lt;br /&gt;
Thanks &amp;quot;denix&amp;quot; on the forum for the correct syntax. &amp;quot;Actually, the 4th parameter IS required, but it's not used. Otherwise the command fails with an error message&amp;quot; &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
  luup.call_action(&amp;quot;urn:micasaverde-com:serviceId:HomeAutomationGateway1&amp;quot;, &amp;quot;RunScene&amp;quot;, {SceneNum = &amp;quot;5&amp;quot;}, 0)&lt;br /&gt;
&amp;lt;/source&amp;gt; &lt;br /&gt;
&lt;br /&gt;
In this case we left the device number off (the 4th parameter to &amp;lt;tt&amp;gt;luup.call_action&amp;lt;/tt&amp;gt;), because the &amp;quot;&amp;lt;tt&amp;gt;RunScene&amp;lt;/tt&amp;gt;&amp;quot; action is handled by the Luup engine itself--not by some device within Z-Wave, etc. &lt;br /&gt;
&lt;br /&gt;
However, normally you don't need to &amp;lt;tt&amp;gt;luup.call_action&amp;lt;/tt&amp;gt; in Lua code. Rather, whatever actions, or commands, you want to run, you put into the scene itself, and the only Lua code is to simply check if some condition is true and abort the scene if the condition isn't met. &lt;br /&gt;
&lt;br /&gt;
=== Thermostat Actions  ===&lt;br /&gt;
&lt;br /&gt;
==== Change the Temperature on Thermostat (Cool) device #19  ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
  luup.call_action(&amp;quot;urn:upnp-org:serviceId:TemperatureSetpoint1_Cool&amp;quot;,&lt;br /&gt;
                   &amp;quot;SetCurrentSetpoint&amp;quot;, {NewCurrentSetpoint = &amp;quot;68&amp;quot;},&lt;br /&gt;
                   19)&lt;br /&gt;
&amp;lt;/source&amp;gt; &lt;br /&gt;
&lt;br /&gt;
==== Change the Temperature on a Thermostat (Heat) device #19  ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
  luup.call_action(&amp;quot;urn:upnp-org:serviceId:TemperatureSetpoint1_Heat&amp;quot;,&lt;br /&gt;
                   &amp;quot;SetCurrentSetpoint&amp;quot;, {NewCurrentSetpoint = &amp;quot;68&amp;quot;},&lt;br /&gt;
                   19)&lt;br /&gt;
&amp;lt;/source&amp;gt; &lt;br /&gt;
&lt;br /&gt;
==== Change the Thermostat Operating mode device #19  ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
luup.call_action(&amp;quot;urn:upnp-org:serviceId:HVAC_UserOperatingMode1&amp;quot;,&lt;br /&gt;
                 &amp;quot;SetModeTarget&amp;quot;, {NewModeTarget = &amp;quot;Off&amp;quot;},&lt;br /&gt;
                 19)&lt;br /&gt;
&amp;lt;/source&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt; &lt;br /&gt;
&lt;br /&gt;
=== Camera Actions  ===&lt;br /&gt;
&lt;br /&gt;
==== 'Privacy' mode for Foscam FI8908[w]  ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
  local IP_address = '&amp;lt;IP address of camera&amp;gt;'&lt;br /&gt;
  local username = '&amp;lt;username&amp;gt;'&lt;br /&gt;
  local password = '&amp;lt;password&amp;gt;'&lt;br /&gt;
  local timeout  = 5&lt;br /&gt;
 &lt;br /&gt;
  function move_up()&lt;br /&gt;
    luup.inet.wget('http://' .. IP_address .. '/decoder_control.cgi?command=0', timeout, username, password)&lt;br /&gt;
  end&lt;br /&gt;
 &lt;br /&gt;
  -- center the camera; takes some time, so we have to wait 2 minutes for the command to complete&lt;br /&gt;
 &lt;br /&gt;
  luup.inet.wget('http://' .. IP_address .. '/decoder_control.cgi?command=25', timeout, username, password)&lt;br /&gt;
 &lt;br /&gt;
  luup.call_delay('move_up', 120)&lt;br /&gt;
&amp;lt;/source&amp;gt; &lt;br /&gt;
&lt;br /&gt;
=== Misc Actions  ===&lt;br /&gt;
&lt;br /&gt;
==== Playing an announcement  ====&lt;br /&gt;
&lt;br /&gt;
http://forum.micasaverde.com/index.php?topic=5466.msg36405#msg36405 &lt;br /&gt;
&lt;br /&gt;
=== Calculate sunrise and sunset  ===&lt;br /&gt;
&lt;br /&gt;
See http://forum.micasaverde.com/index.php?topic=2073.msg8132#msg8132 &lt;br /&gt;
&lt;br /&gt;
... or use DAD: http://forum.micasaverde.com/index.php?topic=5466.0 &lt;br /&gt;
&lt;br /&gt;
=== Access the web  ===&lt;br /&gt;
&lt;br /&gt;
==== Invoke HTTP URL with &amp;lt;tt&amp;gt;GET&amp;lt;/tt&amp;gt; request (Method 1)  ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
  -- 5 Second timeout&lt;br /&gt;
  local status, result = luup.inet.wget(&amp;quot;http://www.yahoo.com&amp;quot;, 5)&lt;br /&gt;
&amp;lt;/source&amp;gt; &lt;br /&gt;
&lt;br /&gt;
==== Invoke HTTP URL with &amp;lt;tt&amp;gt;GET&amp;lt;/tt&amp;gt; request (Method 2)  ====&lt;br /&gt;
&lt;br /&gt;
Based on code by Jim/jgc94131 &amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
  require('ltn12')&lt;br /&gt;
  local http = require('socket.http')&lt;br /&gt;
&lt;br /&gt;
  -- 5 Second timeout&lt;br /&gt;
  socket.http.TIMEOUT = 5&lt;br /&gt;
&lt;br /&gt;
  local response_body = {}&lt;br /&gt;
  local request_body = ''&lt;br /&gt;
&lt;br /&gt;
  local r, c, h = socket.http.request{&lt;br /&gt;
    url = 'http://website/page?parameter1=value&amp;amp;parameter2=value',&lt;br /&gt;
    method = &amp;quot;GET&amp;quot;,&lt;br /&gt;
    port = 80,&lt;br /&gt;
    headers = {&lt;br /&gt;
      [&amp;quot;Content-Length&amp;quot;] = string.len(request_body),&lt;br /&gt;
      [&amp;quot;Content-Type&amp;quot;] = &amp;quot;application/x-www-form-urlencoded&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    source = ltn12.source.string(request_body),&lt;br /&gt;
    sink = ltn12.sink.table(response_body)&lt;br /&gt;
  }&lt;br /&gt;
&amp;lt;/source&amp;gt; &lt;br /&gt;
&lt;br /&gt;
==== Invoke HTTP URL with &amp;lt;tt&amp;gt;POST&amp;lt;/tt&amp;gt; request (Method 3)  ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
  local http = require(&amp;quot;socket.http&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
  -- 5 Second timeout&lt;br /&gt;
  http.TIMEOUT = 5&lt;br /&gt;
&lt;br /&gt;
  -- The return parameters are in a different order from luup.inet.wget(...)&lt;br /&gt;
  result, status = http.request(&amp;quot;http://192.168.0.113/runprocess.htm&amp;quot;, &amp;quot;run=run&amp;quot;)    &lt;br /&gt;
&amp;lt;/source&amp;gt; &lt;br /&gt;
&lt;br /&gt;
=== Access the current time  ===&lt;br /&gt;
&lt;br /&gt;
The Lua function &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
  os.date (format, time)&lt;br /&gt;
&amp;lt;/source&amp;gt; &lt;br /&gt;
&lt;br /&gt;
converts a time value `time` into a human readable date/time string, according to `format`. If you leave out the optional `time` parameter, it defaults to current time. The `format` parameter defaults to a fairly complete format. If you specify '*t' as the format, it will return a table instead of a formatted string. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
  t = os.date('*t')&lt;br /&gt;
  t = {year=2010, month=2, day=19, yday=50, wday=6, hour=22, min=45, sec=45, isdst=false}&lt;br /&gt;
&amp;lt;/source&amp;gt; &lt;br /&gt;
&lt;br /&gt;
The fields are year, month, day of month, day of year, day of week, hour in 24 hour clock, minutes, seconds and if it's Daylight Savings Time. &lt;br /&gt;
&lt;br /&gt;
Current hour: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
  os.date('*t').hour&lt;br /&gt;
&amp;lt;/source&amp;gt; &lt;br /&gt;
&lt;br /&gt;
Current minute: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
  os.date('*t').min&lt;br /&gt;
&amp;lt;/source&amp;gt; &lt;br /&gt;
&lt;br /&gt;
Current second: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
  os.date('*t').sec&lt;br /&gt;
&amp;lt;/source&amp;gt; &lt;br /&gt;
&lt;br /&gt;
Do something between 16:00 and 21:15: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
  local t = os.date('*t')&lt;br /&gt;
  local current_second = t.hour * 3600 + t.min * 60 + t.sec   -- number of seconds since midnight&lt;br /&gt;
  local min_time_in_seconds = 16 * 3600 +  0 * 60             -- 16:00&lt;br /&gt;
  local max_time_in_seconds = 21 * 3600 + 15 * 60             -- 21:15&lt;br /&gt;
 &lt;br /&gt;
  if (current_second &amp;gt; min_time_in_seconds) and (current_second &amp;lt; max_time_in_seconds) then&lt;br /&gt;
    -- do something&lt;br /&gt;
  else&lt;br /&gt;
    return false&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/source&amp;gt; &lt;br /&gt;
&lt;br /&gt;
See http://forum.micasaverde.com/index.php?topic=2015.0 and http://www.lua.org/manual/5.1/manual.html#5.8.&lt;br /&gt;
&lt;br /&gt;
=== Set Z-Wave parameters  ===&lt;br /&gt;
&lt;br /&gt;
See http://forum.micasaverde.com/index.php?topic=1937.msg7803#msg7803 &lt;br /&gt;
&lt;br /&gt;
=== a scene if the temperature is outside of a range  ===&lt;br /&gt;
&lt;br /&gt;
add snippets here... &lt;br /&gt;
&lt;br /&gt;
=== Reload Luup at 3 AM every day  ===&lt;br /&gt;
&lt;br /&gt;
1. Create a scene and set it to run daily at 3 AM. &lt;br /&gt;
&lt;br /&gt;
2. Add this code in the '''Luup code''' box: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;luup.call_action(&amp;quot;urn:micasaverde-com:serviceId:HomeAutomationGateway1&amp;quot;, &amp;quot;Reload&amp;quot;, {}, 0)&amp;lt;/source&amp;gt; &lt;br /&gt;
&lt;br /&gt;
3. Save.&lt;br /&gt;
&lt;br /&gt;
=== Thermostat conditioned by door/window ===&lt;br /&gt;
Turn off the thermostat if the door/window is left open for 5 minutes or more and back on if the door/window is closed for 10 minutes or more.&lt;br /&gt;
&lt;br /&gt;
'''1.''' Create a scene and set it to run when the door is opened.&lt;br /&gt;
&lt;br /&gt;
'''2.''' Add this code in the '''Luup code''' box:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
local SENSOR = 17    -- The door/window sensor device number&lt;br /&gt;
local THERMOSTAT = 3 -- The thermostat device number&lt;br /&gt;
local DELAY = 300    -- Seconds&lt;br /&gt;
&lt;br /&gt;
local SES_SID = &amp;quot;urn:micasaverde-com:serviceId:SecuritySensor1&amp;quot;&lt;br /&gt;
local HVACO_SID = &amp;quot;urn:upnp-org:serviceId:HVAC_UserOperatingMode1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
luup.call_delay( &amp;quot;turnOffAc&amp;quot;, DELAY)&lt;br /&gt;
&lt;br /&gt;
-- Turn off the thermostat if the sensor has been tripped for at least 5 minutes.&lt;br /&gt;
function turnOffAc()&lt;br /&gt;
    local tripped = luup.variable_get( SES_SID, &amp;quot;Tripped&amp;quot;, SENSOR) or &amp;quot;0&amp;quot;&lt;br /&gt;
    local lastTrip = luup.variable_get( SES_SID, &amp;quot;LastTrip&amp;quot;, SENSOR) or os.time()&lt;br /&gt;
    if (tripped == &amp;quot;1&amp;quot; and (os.time() - lastTrip &amp;gt;= DELAY)) then&lt;br /&gt;
        local modeStatus = luup.variable_get( HVACO_SID, &amp;quot;ModeStatus&amp;quot;, THERMOSTAT) or &amp;quot;Off&amp;quot;&lt;br /&gt;
        luup.variable_set( HVACO_SID, &amp;quot;LastModeStatus&amp;quot;, modeStatus, THERMOSTAT)&lt;br /&gt;
        luup.call_action( HVACO_SID, &amp;quot;SetModeTarget&amp;quot;, {NewModeTarget = &amp;quot;Off&amp;quot;}, THERMOSTAT)&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''3.''' Create another scene and set it to run when the door is closed.&lt;br /&gt;
&lt;br /&gt;
'''4.''' Add this code in the '''Luup code''' box:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
local SENSOR = 17    -- The door/window sensor device number&lt;br /&gt;
local THERMOSTAT = 3 -- The thermostat device number&lt;br /&gt;
local DELAY = 600    -- Seconds&lt;br /&gt;
&lt;br /&gt;
local SES_SID = &amp;quot;urn:micasaverde-com:serviceId:SecuritySensor1&amp;quot;&lt;br /&gt;
local HVACO_SID = &amp;quot;urn:upnp-org:serviceId:HVAC_UserOperatingMode1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
luup.call_delay( &amp;quot;turnOnAc&amp;quot;, DELAY)&lt;br /&gt;
&lt;br /&gt;
-- Turn on the thermostat if the sensor hasn't been tripped in the past 10 minutes.&lt;br /&gt;
function turnOnAc()&lt;br /&gt;
    local tripped = luup.variable_get( SES_SID, &amp;quot;Tripped&amp;quot;, DOOR_SENSOR) or &amp;quot;0&amp;quot;&lt;br /&gt;
    local lastTrip = luup.variable_get( SES_SID, &amp;quot;LastTrip&amp;quot;, DOOR_SENSOR) or os.time()&lt;br /&gt;
    if (tripped == &amp;quot;0&amp;quot; and (os.time() - lastTrip &amp;gt;= DELAY)) then&lt;br /&gt;
        local lastModeStatus = luup.variable_get( HVACO_SID, &amp;quot;LastModeStatus&amp;quot;, THERMOSTAT) or &amp;quot;Off&amp;quot;&lt;br /&gt;
        luup.call_action( HVACO_SID, &amp;quot;SetModeTarget&amp;quot;, {NewModeTarget = lastModeStatus}, THERMOSTAT)&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''5.''' Save.&lt;br /&gt;
&lt;br /&gt;
[[Category:Development]]&lt;/div&gt;</summary>
		<author><name>Solipsia</name></author>	</entry>

	<entry>
		<id>http://wiki.mios.com/index.php/Luup_Scenes_Events</id>
		<title>Luup Scenes Events</title>
		<link rel="alternate" type="text/html" href="http://wiki.mios.com/index.php/Luup_Scenes_Events"/>
				<updated>2012-09-09T12:23:02Z</updated>
		
		<summary type="html">&lt;p&gt;Solipsia: /* ==Switch on, and switch off 2 seconds later == */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Adding Lua code to scenes and events  ==&lt;br /&gt;
&lt;br /&gt;
[[Image:SceneFlowchart.png]] &lt;br /&gt;
&lt;br /&gt;
You can add Lua script to scenes and events for simple tasks, like making a scene or event conditional. Conditional meaning &amp;quot;do something only '''if''' some condition is met&amp;quot;, such as attaching a condition to your &amp;quot;Come Home&amp;quot; scene so it is only run '''if''' the temperature is over 70 degrees. Basic conditional expressions are easy, and, if that's all you're looking to do, skip to the walk-through below. &lt;br /&gt;
&lt;br /&gt;
If you're more technically inclined you can also do very advanced things too. For an overview of all the advanced things you can do with Vera's Luup engine, and how scenes and events fit in, see the [[Luup Intro]] page. &lt;br /&gt;
&lt;br /&gt;
To add Lua code to a scene, create the [[Scenes]] and click 'Luup scene'. Fill in your Lua code in the input box. To do a simple condition, see the sample below. Or if you want to do advanced scripting you can use any [[http://lua.org Lua]] commands as described in the [[http://www.lua.org/manual/5.1/ Lua reference manual]] as well as the variables and functions that the Luup engine adds to Lua documented here: [[Luup Lua extensions]]. The Lua code will be run every time the scene is activated either by the user or a scene or a timer. The Lua code is run before the commands that you included in the scene. If your Lua code ends with this: &amp;quot;return false&amp;quot; then the commands in the scene will not be run. &lt;br /&gt;
&lt;br /&gt;
You can also add Lua code to an event by clicking 'Luup event'. Since events are attached to scenes anyway, there is usually little difference between adding the code to an event, or to the scene the event is part of. If the Lua code in an event returns false, then the event is aborted, meaning the scene that the event is attached to will not be triggered by the event. The main reason for attaching Lua code to an event is if you have multiple events to a scene. For example, you may have a scene called &amp;quot;Turn lights on in hallway&amp;quot; which is triggered by 2 events: 1) The front door opens, and 2) the motion sensor in the hallway is tripped. Perhaps whenever the front door opens you always want the scene to be activated, but you only want the motion sensor to activate the scene before 10:00. In this case, you would add Lua code to the motion sensor's event which does something like (pseudo-code): &amp;quot;if time&amp;amp;gt;10:00 return false&amp;quot;. That way the event from the motion sensor will be aborted if it's after 10:00, but the event from the front door will always activate the scene regardless. &lt;br /&gt;
&lt;br /&gt;
When you edit the Lua code in a scene or event you must click 'Save' before the code is saved. Then you can activate the scene or trigger the event to see what happens when your code is run. If you're doing some advanced scripting that you'll need to debug this can be tedious, but there are easy ways to test your Lua script immediately without saving first as explained in [[Lua Debugging]]. &lt;br /&gt;
&lt;br /&gt;
If you're doing advanced Lua scripting, you should note that all the Lua code in your scenes and events run in a single Lua instance, which is separate from any Lua plugins. This means if you set a global variable in one scene, or create a function inside the Lua code in a scene, then in another scene's Lua code you can use that global variable or call that function. You do not need to worry about conflicting with a Luup plugin, though, since they have their own Lua instance, meaning they have their own global variables and functions. &lt;br /&gt;
&lt;br /&gt;
== Walk-through #1 -- At 12 noon, turn off the interior lights if the temperature is over 80 degrees  ==&lt;br /&gt;
&lt;br /&gt;
Before you start, in Vera's setup interface go to 'Devices' and click the '+' button next to the thermostat. Make note of the Device #. &lt;br /&gt;
&lt;br /&gt;
In this walkthrough we'll assume it's Device #3, but use the actual device number of''your'' thermostat. Next, visit [[Luup Variables]] to get a list of all the variables for devices. A variable is a piece of information about the current state of a device, such as whether it's on or off, it's current temperature, etc. &lt;br /&gt;
&lt;br /&gt;
Look down at ''Thermostat'', and copy the name of the service/variable which corresponds to the current temperature, namely. In this case, it's &lt;br /&gt;
&lt;br /&gt;
  urn:upnp-org:serviceId:TemperatureSensor1 CurrentTemperature&lt;br /&gt;
&lt;br /&gt;
Notice that it states the &amp;lt;tt&amp;gt;CurrentTemperature&amp;lt;/tt&amp;gt; is in Celsius. So type in &amp;quot;80 degrees Fahrenheit to Celsius&amp;quot; in Google and you'll see that it's 26.6 degrees Celsius. &lt;br /&gt;
&lt;br /&gt;
Now, the first step is to create the scene that turns off the lights. In Vera's setup interface, click 'Scenes', and click 'Add Scene' to add a new scene to one of the rooms. It's not important which room you choose. Scenes are categorized in rooms just to help you keep track of them if you have a lot of scenes. You can also put the scene in 'Global Scenes', or, you can create dummy rooms on the 'Rooms' tab if you want to have more &amp;quot;rooms&amp;quot; to organize your scenes with. After you click 'Add Scene', type in a description to remember your scene by, such as &amp;quot;Lights off 12:00 if 80&amp;quot;. Under the 'Commands' area you'll see all the rooms. Click '+' next to the rooms that have lights you want to control, and choose &amp;quot;Off&amp;quot; in the pull-down. At this point, you have a normal scene, and, if you were to save your changes now, whenever you click the scene on the dashboard or on a remote control, the lights should turn off. &lt;br /&gt;
&lt;br /&gt;
Second, next to the scene's description click 'add timer'. You can give the timer a description too so that if you have multiple timers you can see in the logs which one is activating the scene. Choose &amp;quot;Day of week based&amp;quot;. If you want this scene to only run on certain days of the week, just check off which days you want this scene to run on. Otherwise, you can leave them all unchecked (or check them all) to do it every day. Leave the pull-down at &amp;quot;a certain time of day&amp;quot;, and choose 12&amp;amp;nbsp;: 00&amp;amp;nbsp;: 00 from the pull-downs. At this point, if you were to save your changes, the lights would turn off automatically at 12 noon. &lt;br /&gt;
&lt;br /&gt;
Third, the last step is to add the condition. To the right of the scene's description you'll see the button &amp;quot;Luup Scene&amp;quot;. Click it and in the code box, copy and paste the following: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
  local lul_temp = luup.variable_get(&amp;quot;urn:upnp-org:serviceId:TemperatureSensor1&amp;quot;,&amp;quot;CurrentTemperature&amp;quot;, 3)&lt;br /&gt;
  if (tonumber(lul_temp) &amp;lt; 26.6) then&lt;br /&gt;
    return false&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/source&amp;gt; &lt;br /&gt;
&lt;br /&gt;
Don't forget to change the &amp;quot;3&amp;quot; to whatever is the actual device number of your thermostat. Assign the result of &amp;lt;tt&amp;gt;luup.variable_get&amp;lt;/tt&amp;gt; to a variable first, rather than putting it directly in the &amp;lt;tt&amp;gt;tonumber()&amp;lt;/tt&amp;gt;, because &amp;lt;tt&amp;gt;luup.variable_get&amp;lt;/tt&amp;gt; actually returns 2 values: the value of the variable, and the time when the variable was modified. The '&amp;lt;tt&amp;gt;tonumber&amp;lt;/tt&amp;gt;' is needed because all of a device's variables are stored as plain text--not numbers--so if you want to do arithmetic or numeric comparison of a variable, you need to put &amp;lt;tt&amp;gt;tonumber()&amp;lt;/tt&amp;gt; around &amp;lt;tt&amp;gt;luup.variable_get&amp;lt;/tt&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;luup.variable_get&amp;lt;/tt&amp;gt; is documented in [[Luup Lua extensions]]. &lt;br /&gt;
&lt;br /&gt;
Now click 'Update', and then click 'Save' to save everything. The &amp;quot;return false&amp;quot; means &amp;quot;don't run this scene&amp;quot;. So if the current temperature is &amp;amp;lt;26.6, the scene will be aborted and won't run. The timer will make it trigger every day at 12 noon. &lt;br /&gt;
&lt;br /&gt;
To test it, you can click the scene button on the dashboard. The lights will turn off only if the temperature is over 80 degrees. If it's less than 80 degrees, the scene won't do anything. Since this scene is something that happens automatically and you probably won't execute manually, you can go to the scene again and check the &amp;quot;Hidden&amp;quot; box so the scene doesn't show up on&amp;amp;nbsp;Vera's 'Dashboard' and on your remote controls, like the iPhone. If you want to have a scene that turns off the lights which you can run whenever you want from 'Dashboard''or your remote control, you should create another scene that has the same commands and simply don't add the timers and Luup conditions, and don't check the &amp;quot;Hidden&amp;quot; box. '' &lt;br /&gt;
&lt;br /&gt;
You can substitute other service/variables and device ID's to make other types of conditions. The &amp;quot;if&amp;quot; statement above also supports nesting with ( and ), as well as the keywords 'and' and 'or'. So the following means the scene would abort if the temperature is &amp;amp;lt;26.6 and &amp;amp;gt;25, unless it's &amp;amp;lt;23: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
  local lul_temp = luup.variable_get(&amp;quot;urn:upnp-org:serviceId:TemperatureSensor1&amp;quot;,&amp;quot;CurrentTemperature&amp;quot;, 3)&lt;br /&gt;
  if ((tonumber(lul_temp) &amp;lt; 26.6&lt;br /&gt;
    and tonumber(lul_temp) &amp;gt; 25)&lt;br /&gt;
    or tonumber(lul_temp) &amp;lt; 23) then&lt;br /&gt;
      return false&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/source&amp;gt; &lt;br /&gt;
&lt;br /&gt;
If the scene doesn't run, it's possible&amp;amp;nbsp;there is&amp;amp;nbsp;a syntax error. The easiest way to test this is to copy the Lua code from the scene, then go to Devices, Luup Plugins, and &amp;quot;Test Luup code&amp;quot;. Paste the code in the box and click 'go'. If the info box above the 'go' button has a check and says &amp;quot;Message sent successful&amp;quot;, your code is okay. If there's an error, it says: &amp;quot;Code failed&amp;quot;. &lt;br /&gt;
&lt;br /&gt;
To see if that's true, use putty, or telnet or ssh to log-in to Vera, as explained in detail in [[Logon_Vera_SSH]] and [[Lua Debugging]], and type: &lt;br /&gt;
&lt;br /&gt;
   cd /var/log/cmh&lt;br /&gt;
 tail -f LuaUPnP.log | grep '^01'&lt;br /&gt;
&lt;br /&gt;
Now click 'Save' in Vera's setup page, even if it's gray, as that will cause Vera to restart the Luup engine and log any syntax errors. See: [[Lua Debugging]] for in-depth details on how to debug.&lt;br /&gt;
&lt;br /&gt;
== Walk-through #2 -- Only run the scene during the daytime  ==&lt;br /&gt;
&lt;br /&gt;
In the Luup tab for the scene paste this: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
  return luup.is_night() == false&lt;br /&gt;
&amp;lt;/source&amp;gt; &lt;br /&gt;
&lt;br /&gt;
That works because if the return is 'true' the scene runs, and if it's 'false' it doesn't. So during the daytime the expression is true. Or, an alternative long form: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
  if (luup.is_night()) then&lt;br /&gt;
     return false&lt;br /&gt;
  else&lt;br /&gt;
     return true&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/source&amp;gt; &lt;br /&gt;
&lt;br /&gt;
== Samples  ==&lt;br /&gt;
&lt;br /&gt;
This page is a wiki which anyone can edit. If you have some Lua code you think other users might find useful, feel free to add it here. &lt;br /&gt;
&lt;br /&gt;
=== Lighting and Switch Actions  ===&lt;br /&gt;
&lt;br /&gt;
Did you see the sample here already: http://wiki.micasaverde.com/index.php/Luup_Scenes_Events &lt;br /&gt;
&lt;br /&gt;
==== Turn an appliance switch or a Danfoss thermostat on for device #5  ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
  luup.call_action(&amp;quot;urn:upnp-org:serviceId:SwitchPower1&amp;quot;, &amp;quot;SetTarget&amp;quot;, {newTargetValue = &amp;quot;1&amp;quot;}, 5)&lt;br /&gt;
&amp;lt;/source&amp;gt; &lt;br /&gt;
&lt;br /&gt;
==== Turn an appliance switch or a Danfoss thermostat off  ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
  luup.call_action(&amp;quot;urn:upnp-org:serviceId:SwitchPower1&amp;quot;, &amp;quot;SetTarget&amp;quot;, {newTargetValue = &amp;quot;0&amp;quot;}, 5)&lt;br /&gt;
&amp;lt;/source&amp;gt; &lt;br /&gt;
&lt;br /&gt;
==== Do something if switch device #5 is on  ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
  local lul_tmp = luup.variable_get(&amp;quot;urn:upnp-org:serviceId:SwitchPower1&amp;quot;, &amp;quot;Status&amp;quot;, 5)&lt;br /&gt;
  if (lul_tmp == &amp;quot;1&amp;quot;) then&lt;br /&gt;
     --something to do goes here&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/source&amp;gt; &lt;br /&gt;
&lt;br /&gt;
==== Dim switch #6 to 30%  ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
  luup.call_action(&amp;quot;urn:upnp-org:serviceId:Dimming1&amp;quot;, &amp;quot;SetLoadLevelTarget&amp;quot;, {newLoadlevelTarget = &amp;quot;30&amp;quot;}, 6)&lt;br /&gt;
&amp;lt;/source&amp;gt; &lt;br /&gt;
&lt;br /&gt;
====Switch on, and switch off 2 seconds later ====&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
local device  = 29&lt;br /&gt;
luup.call_action(&amp;quot;urn:upnp-org:serviceId:SwitchPower1&amp;quot;,&amp;quot;SetTarget&amp;quot;,{ newTargetValue=&amp;quot;1&amp;quot; },device)&lt;br /&gt;
luup.call_delay( 'switch_off', 2) -- Call this function after a delay of 2 seconds&lt;br /&gt;
function switch_off()&lt;br /&gt;
   luup.call_action(&amp;quot;urn:upnp-org:serviceId:SwitchPower1&amp;quot;,&amp;quot;SetTarget&amp;quot;,{ newTargetValue=&amp;quot;0&amp;quot; },device)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/source&amp;gt; &lt;br /&gt;
&lt;br /&gt;
==== Blinking lights (and how to delay for a number of seconds)  ====&lt;br /&gt;
&lt;br /&gt;
http://forum.micasaverde.com/index.php?topic=5127.0&lt;br /&gt;
&lt;br /&gt;
=== Motion Sensor Actions  ===&lt;br /&gt;
&lt;br /&gt;
==== Arm motion sensor #7  ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
  luup.variable_set(&amp;quot;urn:micasaverde-com:serviceId:SecuritySensor1&amp;quot;, &amp;quot;Armed&amp;quot;, &amp;quot;1&amp;quot;, 7)&lt;br /&gt;
&amp;lt;/source&amp;gt; &lt;br /&gt;
&lt;br /&gt;
==== Disarm motion sensor #7  ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
  luup.variable_set(&amp;quot;urn:micasaverde-com:serviceId:SecuritySensor1&amp;quot;, &amp;quot;Armed&amp;quot;, &amp;quot;0&amp;quot;, 7)&lt;br /&gt;
&amp;lt;/source&amp;gt; &lt;br /&gt;
&lt;br /&gt;
Note, arming and disarming isn't a concept within UPnP or Z-Wave. It's just a flag that the Luup engine uses, and is stored in a variable we created called &amp;quot;Armed&amp;quot;. &lt;br /&gt;
&lt;br /&gt;
=== Scene Actions  ===&lt;br /&gt;
&lt;br /&gt;
==== Run Scene #5  ====&lt;br /&gt;
&lt;br /&gt;
Thanks &amp;quot;denix&amp;quot; on the forum for the correct syntax. &amp;quot;Actually, the 4th parameter IS required, but it's not used. Otherwise the command fails with an error message&amp;quot; &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
  luup.call_action(&amp;quot;urn:micasaverde-com:serviceId:HomeAutomationGateway1&amp;quot;, &amp;quot;RunScene&amp;quot;, {SceneNum = &amp;quot;5&amp;quot;}, 0)&lt;br /&gt;
&amp;lt;/source&amp;gt; &lt;br /&gt;
&lt;br /&gt;
In this case we left the device number off (the 4th parameter to &amp;lt;tt&amp;gt;luup.call_action&amp;lt;/tt&amp;gt;), because the &amp;quot;&amp;lt;tt&amp;gt;RunScene&amp;lt;/tt&amp;gt;&amp;quot; action is handled by the Luup engine itself--not by some device within Z-Wave, etc. &lt;br /&gt;
&lt;br /&gt;
However, normally you don't need to &amp;lt;tt&amp;gt;luup.call_action&amp;lt;/tt&amp;gt; in Lua code. Rather, whatever actions, or commands, you want to run, you put into the scene itself, and the only Lua code is to simply check if some condition is true and abort the scene if the condition isn't met. &lt;br /&gt;
&lt;br /&gt;
=== Thermostat Actions  ===&lt;br /&gt;
&lt;br /&gt;
==== Change the Temperature on Thermostat (Cool) device #19  ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
  luup.call_action(&amp;quot;urn:upnp-org:serviceId:TemperatureSetpoint1_Cool&amp;quot;,&lt;br /&gt;
                   &amp;quot;SetCurrentSetpoint&amp;quot;, {NewCurrentSetpoint = &amp;quot;68&amp;quot;},&lt;br /&gt;
                   19)&lt;br /&gt;
&amp;lt;/source&amp;gt; &lt;br /&gt;
&lt;br /&gt;
==== Change the Temperature on a Thermostat (Heat) device #19  ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
  luup.call_action(&amp;quot;urn:upnp-org:serviceId:TemperatureSetpoint1_Heat&amp;quot;,&lt;br /&gt;
                   &amp;quot;SetCurrentSetpoint&amp;quot;, {NewCurrentSetpoint = &amp;quot;68&amp;quot;},&lt;br /&gt;
                   19)&lt;br /&gt;
&amp;lt;/source&amp;gt; &lt;br /&gt;
&lt;br /&gt;
==== Change the Thermostat Operating mode device #19  ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
luup.call_action(&amp;quot;urn:upnp-org:serviceId:HVAC_UserOperatingMode1&amp;quot;,&lt;br /&gt;
                 &amp;quot;SetModeTarget&amp;quot;, {NewModeTarget = &amp;quot;Off&amp;quot;},&lt;br /&gt;
                 19)&lt;br /&gt;
&amp;lt;/source&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt; &lt;br /&gt;
&lt;br /&gt;
=== Camera Actions  ===&lt;br /&gt;
&lt;br /&gt;
==== 'Privacy' mode for Foscam FI8908[w]  ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
  local IP_address = '&amp;lt;IP address of camera&amp;gt;'&lt;br /&gt;
  local username = '&amp;lt;username&amp;gt;'&lt;br /&gt;
  local password = '&amp;lt;password&amp;gt;'&lt;br /&gt;
  local timeout  = 5&lt;br /&gt;
 &lt;br /&gt;
  function move_up()&lt;br /&gt;
    luup.inet.wget('http://' .. IP_address .. '/decoder_control.cgi?command=0', timeout, username, password)&lt;br /&gt;
  end&lt;br /&gt;
 &lt;br /&gt;
  -- center the camera; takes some time, so we have to wait 2 minutes for the command to complete&lt;br /&gt;
 &lt;br /&gt;
  luup.inet.wget('http://' .. IP_address .. '/decoder_control.cgi?command=25', timeout, username, password)&lt;br /&gt;
 &lt;br /&gt;
  luup.call_delay('move_up', 120)&lt;br /&gt;
&amp;lt;/source&amp;gt; &lt;br /&gt;
&lt;br /&gt;
=== Misc Actions  ===&lt;br /&gt;
&lt;br /&gt;
==== Playing an announcement  ====&lt;br /&gt;
&lt;br /&gt;
http://forum.micasaverde.com/index.php?topic=5466.msg36405#msg36405 &lt;br /&gt;
&lt;br /&gt;
=== Calculate sunrise and sunset  ===&lt;br /&gt;
&lt;br /&gt;
See http://forum.micasaverde.com/index.php?topic=2073.msg8132#msg8132 &lt;br /&gt;
&lt;br /&gt;
... or use DAD: http://forum.micasaverde.com/index.php?topic=5466.0 &lt;br /&gt;
&lt;br /&gt;
=== Access the web  ===&lt;br /&gt;
&lt;br /&gt;
==== Invoke HTTP URL with &amp;lt;tt&amp;gt;GET&amp;lt;/tt&amp;gt; request (Method 1)  ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
  -- 5 Second timeout&lt;br /&gt;
  local status, result = luup.inet.wget(&amp;quot;http://www.yahoo.com&amp;quot;, 5)&lt;br /&gt;
&amp;lt;/source&amp;gt; &lt;br /&gt;
&lt;br /&gt;
==== Invoke HTTP URL with &amp;lt;tt&amp;gt;GET&amp;lt;/tt&amp;gt; request (Method 2)  ====&lt;br /&gt;
&lt;br /&gt;
Based on code by Jim/jgc94131 &amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
  require('ltn12')&lt;br /&gt;
  local http = require('socket.http')&lt;br /&gt;
&lt;br /&gt;
  -- 5 Second timeout&lt;br /&gt;
  socket.http.TIMEOUT = 5&lt;br /&gt;
&lt;br /&gt;
  local response_body = {}&lt;br /&gt;
  local request_body = ''&lt;br /&gt;
&lt;br /&gt;
  local r, c, h = socket.http.request{&lt;br /&gt;
    url = 'http://website/page?parameter1=value&amp;amp;parameter2=value',&lt;br /&gt;
    method = &amp;quot;GET&amp;quot;,&lt;br /&gt;
    port = 80,&lt;br /&gt;
    headers = {&lt;br /&gt;
      [&amp;quot;Content-Length&amp;quot;] = string.len(request_body),&lt;br /&gt;
      [&amp;quot;Content-Type&amp;quot;] = &amp;quot;application/x-www-form-urlencoded&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    source = ltn12.source.string(request_body),&lt;br /&gt;
    sink = ltn12.sink.table(response_body)&lt;br /&gt;
  }&lt;br /&gt;
&amp;lt;/source&amp;gt; &lt;br /&gt;
&lt;br /&gt;
==== Invoke HTTP URL with &amp;lt;tt&amp;gt;POST&amp;lt;/tt&amp;gt; request (Method 3)  ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
  local http = require(&amp;quot;socket.http&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
  -- 5 Second timeout&lt;br /&gt;
  http.TIMEOUT = 5&lt;br /&gt;
&lt;br /&gt;
  -- The return parameters are in a different order from luup.inet.wget(...)&lt;br /&gt;
  result, status = http.request(&amp;quot;http://192.168.0.113/runprocess.htm&amp;quot;, &amp;quot;run=run&amp;quot;)    &lt;br /&gt;
&amp;lt;/source&amp;gt; &lt;br /&gt;
&lt;br /&gt;
=== Access the current time  ===&lt;br /&gt;
&lt;br /&gt;
The Lua function &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
  os.date (format, time)&lt;br /&gt;
&amp;lt;/source&amp;gt; &lt;br /&gt;
&lt;br /&gt;
converts a time value `time` into a human readable date/time string, according to `format`. If you leave out the optional `time` parameter, it defaults to current time. The `format` parameter defaults to a fairly complete format. If you specify '*t' as the format, it will return a table instead of a formatted string. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
  t = os.date('*t')&lt;br /&gt;
  t = {year=2010, month=2, day=19, yday=50, wday=6, hour=22, min=45, sec=45, isdst=false}&lt;br /&gt;
&amp;lt;/source&amp;gt; &lt;br /&gt;
&lt;br /&gt;
The fields are year, month, day of month, day of year, day of week, hour in 24 hour clock, minutes, seconds and if it's Daylight Savings Time. &lt;br /&gt;
&lt;br /&gt;
Current hour: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
  os.date('*t').hour&lt;br /&gt;
&amp;lt;/source&amp;gt; &lt;br /&gt;
&lt;br /&gt;
Current minute: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
  os.date('*t').min&lt;br /&gt;
&amp;lt;/source&amp;gt; &lt;br /&gt;
&lt;br /&gt;
Current second: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
  os.date('*t').sec&lt;br /&gt;
&amp;lt;/source&amp;gt; &lt;br /&gt;
&lt;br /&gt;
Do something between 16:00 and 21:15: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
  local t = os.date('*t')&lt;br /&gt;
  local current_second = t.hour * 3600 + t.min * 60 + t.sec   -- number of seconds since midnight&lt;br /&gt;
  local min_time_in_seconds = 16 * 3600 +  0 * 60             -- 16:00&lt;br /&gt;
  local max_time_in_seconds = 21 * 3600 + 15 * 60             -- 21:15&lt;br /&gt;
 &lt;br /&gt;
  if (current_second &amp;gt; min_time_in_seconds) and (current_second &amp;lt; max_time_in_seconds) then&lt;br /&gt;
    -- do something&lt;br /&gt;
  else&lt;br /&gt;
    return false&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/source&amp;gt; &lt;br /&gt;
&lt;br /&gt;
See http://forum.micasaverde.com/index.php?topic=2015.0 and http://www.lua.org/manual/5.1/manual.html#5.8.&lt;br /&gt;
&lt;br /&gt;
=== Set Z-Wave parameters  ===&lt;br /&gt;
&lt;br /&gt;
See http://forum.micasaverde.com/index.php?topic=1937.msg7803#msg7803 &lt;br /&gt;
&lt;br /&gt;
=== a scene if the temperature is outside of a range  ===&lt;br /&gt;
&lt;br /&gt;
add snippets here... &lt;br /&gt;
&lt;br /&gt;
=== Reload Luup at 3 AM every day  ===&lt;br /&gt;
&lt;br /&gt;
1. Create a scene and set it to run daily at 3 AM. &lt;br /&gt;
&lt;br /&gt;
2. Add this code in the '''Luup code''' box: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;luup.call_action(&amp;quot;urn:micasaverde-com:serviceId:HomeAutomationGateway1&amp;quot;, &amp;quot;Reload&amp;quot;, {}, 0)&amp;lt;/source&amp;gt; &lt;br /&gt;
&lt;br /&gt;
3. Save.&lt;br /&gt;
&lt;br /&gt;
=== Thermostat conditioned by door/window ===&lt;br /&gt;
Turn off the thermostat if the door/window is left open for 5 minutes or more and back on if the door/window is closed for 10 minutes or more.&lt;br /&gt;
&lt;br /&gt;
'''1.''' Create a scene and set it to run when the door is opened.&lt;br /&gt;
&lt;br /&gt;
'''2.''' Add this code in the '''Luup code''' box:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
local SENSOR = 17    -- The door/window sensor device number&lt;br /&gt;
local THERMOSTAT = 3 -- The thermostat device number&lt;br /&gt;
local DELAY = 300    -- Seconds&lt;br /&gt;
&lt;br /&gt;
local SES_SID = &amp;quot;urn:micasaverde-com:serviceId:SecuritySensor1&amp;quot;&lt;br /&gt;
local HVACO_SID = &amp;quot;urn:upnp-org:serviceId:HVAC_UserOperatingMode1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
luup.call_delay( &amp;quot;turnOffAc&amp;quot;, DELAY)&lt;br /&gt;
&lt;br /&gt;
-- Turn off the thermostat if the sensor has been tripped for at least 5 minutes.&lt;br /&gt;
function turnOffAc()&lt;br /&gt;
    local tripped = luup.variable_get( SES_SID, &amp;quot;Tripped&amp;quot;, SENSOR) or &amp;quot;0&amp;quot;&lt;br /&gt;
    local lastTrip = luup.variable_get( SES_SID, &amp;quot;LastTrip&amp;quot;, SENSOR) or os.time()&lt;br /&gt;
    if (tripped == &amp;quot;1&amp;quot; and (os.time() - lastTrip &amp;gt;= DELAY)) then&lt;br /&gt;
        local modeStatus = luup.variable_get( HVACO_SID, &amp;quot;ModeStatus&amp;quot;, THERMOSTAT) or &amp;quot;Off&amp;quot;&lt;br /&gt;
        luup.variable_set( HVACO_SID, &amp;quot;LastModeStatus&amp;quot;, modeStatus, THERMOSTAT)&lt;br /&gt;
        luup.call_action( HVACO_SID, &amp;quot;SetModeTarget&amp;quot;, {NewModeTarget = &amp;quot;Off&amp;quot;}, THERMOSTAT)&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''3.''' Create another scene and set it to run when the door is closed.&lt;br /&gt;
&lt;br /&gt;
'''4.''' Add this code in the '''Luup code''' box:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
local SENSOR = 17    -- The door/window sensor device number&lt;br /&gt;
local THERMOSTAT = 3 -- The thermostat device number&lt;br /&gt;
local DELAY = 600    -- Seconds&lt;br /&gt;
&lt;br /&gt;
local SES_SID = &amp;quot;urn:micasaverde-com:serviceId:SecuritySensor1&amp;quot;&lt;br /&gt;
local HVACO_SID = &amp;quot;urn:upnp-org:serviceId:HVAC_UserOperatingMode1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
luup.call_delay( &amp;quot;turnOnAc&amp;quot;, DELAY)&lt;br /&gt;
&lt;br /&gt;
-- Turn on the thermostat if the sensor hasn't been tripped in the past 10 minutes.&lt;br /&gt;
function turnOnAc()&lt;br /&gt;
    local tripped = luup.variable_get( SES_SID, &amp;quot;Tripped&amp;quot;, DOOR_SENSOR) or &amp;quot;0&amp;quot;&lt;br /&gt;
    local lastTrip = luup.variable_get( SES_SID, &amp;quot;LastTrip&amp;quot;, DOOR_SENSOR) or os.time()&lt;br /&gt;
    if (tripped == &amp;quot;0&amp;quot; and (os.time() - lastTrip &amp;gt;= DELAY)) then&lt;br /&gt;
        local lastModeStatus = luup.variable_get( HVACO_SID, &amp;quot;LastModeStatus&amp;quot;, THERMOSTAT) or &amp;quot;Off&amp;quot;&lt;br /&gt;
        luup.call_action( HVACO_SID, &amp;quot;SetModeTarget&amp;quot;, {NewModeTarget = lastModeStatus}, THERMOSTAT)&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''5.''' Save.&lt;br /&gt;
&lt;br /&gt;
[[Category:Development]]&lt;/div&gt;</summary>
		<author><name>Solipsia</name></author>	</entry>

	<entry>
		<id>http://wiki.mios.com/index.php/Luup_Scenes_Events</id>
		<title>Luup Scenes Events</title>
		<link rel="alternate" type="text/html" href="http://wiki.mios.com/index.php/Luup_Scenes_Events"/>
				<updated>2012-09-09T12:22:49Z</updated>
		
		<summary type="html">&lt;p&gt;Solipsia: /* Switch on, and switch off 2 seconds later */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Adding Lua code to scenes and events  ==&lt;br /&gt;
&lt;br /&gt;
[[Image:SceneFlowchart.png]] &lt;br /&gt;
&lt;br /&gt;
You can add Lua script to scenes and events for simple tasks, like making a scene or event conditional. Conditional meaning &amp;quot;do something only '''if''' some condition is met&amp;quot;, such as attaching a condition to your &amp;quot;Come Home&amp;quot; scene so it is only run '''if''' the temperature is over 70 degrees. Basic conditional expressions are easy, and, if that's all you're looking to do, skip to the walk-through below. &lt;br /&gt;
&lt;br /&gt;
If you're more technically inclined you can also do very advanced things too. For an overview of all the advanced things you can do with Vera's Luup engine, and how scenes and events fit in, see the [[Luup Intro]] page. &lt;br /&gt;
&lt;br /&gt;
To add Lua code to a scene, create the [[Scenes]] and click 'Luup scene'. Fill in your Lua code in the input box. To do a simple condition, see the sample below. Or if you want to do advanced scripting you can use any [[http://lua.org Lua]] commands as described in the [[http://www.lua.org/manual/5.1/ Lua reference manual]] as well as the variables and functions that the Luup engine adds to Lua documented here: [[Luup Lua extensions]]. The Lua code will be run every time the scene is activated either by the user or a scene or a timer. The Lua code is run before the commands that you included in the scene. If your Lua code ends with this: &amp;quot;return false&amp;quot; then the commands in the scene will not be run. &lt;br /&gt;
&lt;br /&gt;
You can also add Lua code to an event by clicking 'Luup event'. Since events are attached to scenes anyway, there is usually little difference between adding the code to an event, or to the scene the event is part of. If the Lua code in an event returns false, then the event is aborted, meaning the scene that the event is attached to will not be triggered by the event. The main reason for attaching Lua code to an event is if you have multiple events to a scene. For example, you may have a scene called &amp;quot;Turn lights on in hallway&amp;quot; which is triggered by 2 events: 1) The front door opens, and 2) the motion sensor in the hallway is tripped. Perhaps whenever the front door opens you always want the scene to be activated, but you only want the motion sensor to activate the scene before 10:00. In this case, you would add Lua code to the motion sensor's event which does something like (pseudo-code): &amp;quot;if time&amp;amp;gt;10:00 return false&amp;quot;. That way the event from the motion sensor will be aborted if it's after 10:00, but the event from the front door will always activate the scene regardless. &lt;br /&gt;
&lt;br /&gt;
When you edit the Lua code in a scene or event you must click 'Save' before the code is saved. Then you can activate the scene or trigger the event to see what happens when your code is run. If you're doing some advanced scripting that you'll need to debug this can be tedious, but there are easy ways to test your Lua script immediately without saving first as explained in [[Lua Debugging]]. &lt;br /&gt;
&lt;br /&gt;
If you're doing advanced Lua scripting, you should note that all the Lua code in your scenes and events run in a single Lua instance, which is separate from any Lua plugins. This means if you set a global variable in one scene, or create a function inside the Lua code in a scene, then in another scene's Lua code you can use that global variable or call that function. You do not need to worry about conflicting with a Luup plugin, though, since they have their own Lua instance, meaning they have their own global variables and functions. &lt;br /&gt;
&lt;br /&gt;
== Walk-through #1 -- At 12 noon, turn off the interior lights if the temperature is over 80 degrees  ==&lt;br /&gt;
&lt;br /&gt;
Before you start, in Vera's setup interface go to 'Devices' and click the '+' button next to the thermostat. Make note of the Device #. &lt;br /&gt;
&lt;br /&gt;
In this walkthrough we'll assume it's Device #3, but use the actual device number of''your'' thermostat. Next, visit [[Luup Variables]] to get a list of all the variables for devices. A variable is a piece of information about the current state of a device, such as whether it's on or off, it's current temperature, etc. &lt;br /&gt;
&lt;br /&gt;
Look down at ''Thermostat'', and copy the name of the service/variable which corresponds to the current temperature, namely. In this case, it's &lt;br /&gt;
&lt;br /&gt;
  urn:upnp-org:serviceId:TemperatureSensor1 CurrentTemperature&lt;br /&gt;
&lt;br /&gt;
Notice that it states the &amp;lt;tt&amp;gt;CurrentTemperature&amp;lt;/tt&amp;gt; is in Celsius. So type in &amp;quot;80 degrees Fahrenheit to Celsius&amp;quot; in Google and you'll see that it's 26.6 degrees Celsius. &lt;br /&gt;
&lt;br /&gt;
Now, the first step is to create the scene that turns off the lights. In Vera's setup interface, click 'Scenes', and click 'Add Scene' to add a new scene to one of the rooms. It's not important which room you choose. Scenes are categorized in rooms just to help you keep track of them if you have a lot of scenes. You can also put the scene in 'Global Scenes', or, you can create dummy rooms on the 'Rooms' tab if you want to have more &amp;quot;rooms&amp;quot; to organize your scenes with. After you click 'Add Scene', type in a description to remember your scene by, such as &amp;quot;Lights off 12:00 if 80&amp;quot;. Under the 'Commands' area you'll see all the rooms. Click '+' next to the rooms that have lights you want to control, and choose &amp;quot;Off&amp;quot; in the pull-down. At this point, you have a normal scene, and, if you were to save your changes now, whenever you click the scene on the dashboard or on a remote control, the lights should turn off. &lt;br /&gt;
&lt;br /&gt;
Second, next to the scene's description click 'add timer'. You can give the timer a description too so that if you have multiple timers you can see in the logs which one is activating the scene. Choose &amp;quot;Day of week based&amp;quot;. If you want this scene to only run on certain days of the week, just check off which days you want this scene to run on. Otherwise, you can leave them all unchecked (or check them all) to do it every day. Leave the pull-down at &amp;quot;a certain time of day&amp;quot;, and choose 12&amp;amp;nbsp;: 00&amp;amp;nbsp;: 00 from the pull-downs. At this point, if you were to save your changes, the lights would turn off automatically at 12 noon. &lt;br /&gt;
&lt;br /&gt;
Third, the last step is to add the condition. To the right of the scene's description you'll see the button &amp;quot;Luup Scene&amp;quot;. Click it and in the code box, copy and paste the following: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
  local lul_temp = luup.variable_get(&amp;quot;urn:upnp-org:serviceId:TemperatureSensor1&amp;quot;,&amp;quot;CurrentTemperature&amp;quot;, 3)&lt;br /&gt;
  if (tonumber(lul_temp) &amp;lt; 26.6) then&lt;br /&gt;
    return false&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/source&amp;gt; &lt;br /&gt;
&lt;br /&gt;
Don't forget to change the &amp;quot;3&amp;quot; to whatever is the actual device number of your thermostat. Assign the result of &amp;lt;tt&amp;gt;luup.variable_get&amp;lt;/tt&amp;gt; to a variable first, rather than putting it directly in the &amp;lt;tt&amp;gt;tonumber()&amp;lt;/tt&amp;gt;, because &amp;lt;tt&amp;gt;luup.variable_get&amp;lt;/tt&amp;gt; actually returns 2 values: the value of the variable, and the time when the variable was modified. The '&amp;lt;tt&amp;gt;tonumber&amp;lt;/tt&amp;gt;' is needed because all of a device's variables are stored as plain text--not numbers--so if you want to do arithmetic or numeric comparison of a variable, you need to put &amp;lt;tt&amp;gt;tonumber()&amp;lt;/tt&amp;gt; around &amp;lt;tt&amp;gt;luup.variable_get&amp;lt;/tt&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;luup.variable_get&amp;lt;/tt&amp;gt; is documented in [[Luup Lua extensions]]. &lt;br /&gt;
&lt;br /&gt;
Now click 'Update', and then click 'Save' to save everything. The &amp;quot;return false&amp;quot; means &amp;quot;don't run this scene&amp;quot;. So if the current temperature is &amp;amp;lt;26.6, the scene will be aborted and won't run. The timer will make it trigger every day at 12 noon. &lt;br /&gt;
&lt;br /&gt;
To test it, you can click the scene button on the dashboard. The lights will turn off only if the temperature is over 80 degrees. If it's less than 80 degrees, the scene won't do anything. Since this scene is something that happens automatically and you probably won't execute manually, you can go to the scene again and check the &amp;quot;Hidden&amp;quot; box so the scene doesn't show up on&amp;amp;nbsp;Vera's 'Dashboard' and on your remote controls, like the iPhone. If you want to have a scene that turns off the lights which you can run whenever you want from 'Dashboard''or your remote control, you should create another scene that has the same commands and simply don't add the timers and Luup conditions, and don't check the &amp;quot;Hidden&amp;quot; box. '' &lt;br /&gt;
&lt;br /&gt;
You can substitute other service/variables and device ID's to make other types of conditions. The &amp;quot;if&amp;quot; statement above also supports nesting with ( and ), as well as the keywords 'and' and 'or'. So the following means the scene would abort if the temperature is &amp;amp;lt;26.6 and &amp;amp;gt;25, unless it's &amp;amp;lt;23: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
  local lul_temp = luup.variable_get(&amp;quot;urn:upnp-org:serviceId:TemperatureSensor1&amp;quot;,&amp;quot;CurrentTemperature&amp;quot;, 3)&lt;br /&gt;
  if ((tonumber(lul_temp) &amp;lt; 26.6&lt;br /&gt;
    and tonumber(lul_temp) &amp;gt; 25)&lt;br /&gt;
    or tonumber(lul_temp) &amp;lt; 23) then&lt;br /&gt;
      return false&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/source&amp;gt; &lt;br /&gt;
&lt;br /&gt;
If the scene doesn't run, it's possible&amp;amp;nbsp;there is&amp;amp;nbsp;a syntax error. The easiest way to test this is to copy the Lua code from the scene, then go to Devices, Luup Plugins, and &amp;quot;Test Luup code&amp;quot;. Paste the code in the box and click 'go'. If the info box above the 'go' button has a check and says &amp;quot;Message sent successful&amp;quot;, your code is okay. If there's an error, it says: &amp;quot;Code failed&amp;quot;. &lt;br /&gt;
&lt;br /&gt;
To see if that's true, use putty, or telnet or ssh to log-in to Vera, as explained in detail in [[Logon_Vera_SSH]] and [[Lua Debugging]], and type: &lt;br /&gt;
&lt;br /&gt;
   cd /var/log/cmh&lt;br /&gt;
 tail -f LuaUPnP.log | grep '^01'&lt;br /&gt;
&lt;br /&gt;
Now click 'Save' in Vera's setup page, even if it's gray, as that will cause Vera to restart the Luup engine and log any syntax errors. See: [[Lua Debugging]] for in-depth details on how to debug.&lt;br /&gt;
&lt;br /&gt;
== Walk-through #2 -- Only run the scene during the daytime  ==&lt;br /&gt;
&lt;br /&gt;
In the Luup tab for the scene paste this: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
  return luup.is_night() == false&lt;br /&gt;
&amp;lt;/source&amp;gt; &lt;br /&gt;
&lt;br /&gt;
That works because if the return is 'true' the scene runs, and if it's 'false' it doesn't. So during the daytime the expression is true. Or, an alternative long form: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
  if (luup.is_night()) then&lt;br /&gt;
     return false&lt;br /&gt;
  else&lt;br /&gt;
     return true&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/source&amp;gt; &lt;br /&gt;
&lt;br /&gt;
== Samples  ==&lt;br /&gt;
&lt;br /&gt;
This page is a wiki which anyone can edit. If you have some Lua code you think other users might find useful, feel free to add it here. &lt;br /&gt;
&lt;br /&gt;
=== Lighting and Switch Actions  ===&lt;br /&gt;
&lt;br /&gt;
Did you see the sample here already: http://wiki.micasaverde.com/index.php/Luup_Scenes_Events &lt;br /&gt;
&lt;br /&gt;
==== Turn an appliance switch or a Danfoss thermostat on for device #5  ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
  luup.call_action(&amp;quot;urn:upnp-org:serviceId:SwitchPower1&amp;quot;, &amp;quot;SetTarget&amp;quot;, {newTargetValue = &amp;quot;1&amp;quot;}, 5)&lt;br /&gt;
&amp;lt;/source&amp;gt; &lt;br /&gt;
&lt;br /&gt;
==== Turn an appliance switch or a Danfoss thermostat off  ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
  luup.call_action(&amp;quot;urn:upnp-org:serviceId:SwitchPower1&amp;quot;, &amp;quot;SetTarget&amp;quot;, {newTargetValue = &amp;quot;0&amp;quot;}, 5)&lt;br /&gt;
&amp;lt;/source&amp;gt; &lt;br /&gt;
&lt;br /&gt;
==== Do something if switch device #5 is on  ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
  local lul_tmp = luup.variable_get(&amp;quot;urn:upnp-org:serviceId:SwitchPower1&amp;quot;, &amp;quot;Status&amp;quot;, 5)&lt;br /&gt;
  if (lul_tmp == &amp;quot;1&amp;quot;) then&lt;br /&gt;
     --something to do goes here&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/source&amp;gt; &lt;br /&gt;
&lt;br /&gt;
==== Dim switch #6 to 30%  ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
  luup.call_action(&amp;quot;urn:upnp-org:serviceId:Dimming1&amp;quot;, &amp;quot;SetLoadLevelTarget&amp;quot;, {newLoadlevelTarget = &amp;quot;30&amp;quot;}, 6)&lt;br /&gt;
&amp;lt;/source&amp;gt; &lt;br /&gt;
&lt;br /&gt;
== ==Switch on, and switch off 2 seconds later ====&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
local device  = 29&lt;br /&gt;
luup.call_action(&amp;quot;urn:upnp-org:serviceId:SwitchPower1&amp;quot;,&amp;quot;SetTarget&amp;quot;,{ newTargetValue=&amp;quot;1&amp;quot; },device)&lt;br /&gt;
luup.call_delay( 'switch_off', 2) -- Call this function after a delay of 2 seconds&lt;br /&gt;
function switch_off()&lt;br /&gt;
   luup.call_action(&amp;quot;urn:upnp-org:serviceId:SwitchPower1&amp;quot;,&amp;quot;SetTarget&amp;quot;,{ newTargetValue=&amp;quot;0&amp;quot; },device)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/source&amp;gt; &lt;br /&gt;
&lt;br /&gt;
==== Blinking lights (and how to delay for a number of seconds)  ====&lt;br /&gt;
&lt;br /&gt;
http://forum.micasaverde.com/index.php?topic=5127.0&lt;br /&gt;
&lt;br /&gt;
=== Motion Sensor Actions  ===&lt;br /&gt;
&lt;br /&gt;
==== Arm motion sensor #7  ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
  luup.variable_set(&amp;quot;urn:micasaverde-com:serviceId:SecuritySensor1&amp;quot;, &amp;quot;Armed&amp;quot;, &amp;quot;1&amp;quot;, 7)&lt;br /&gt;
&amp;lt;/source&amp;gt; &lt;br /&gt;
&lt;br /&gt;
==== Disarm motion sensor #7  ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
  luup.variable_set(&amp;quot;urn:micasaverde-com:serviceId:SecuritySensor1&amp;quot;, &amp;quot;Armed&amp;quot;, &amp;quot;0&amp;quot;, 7)&lt;br /&gt;
&amp;lt;/source&amp;gt; &lt;br /&gt;
&lt;br /&gt;
Note, arming and disarming isn't a concept within UPnP or Z-Wave. It's just a flag that the Luup engine uses, and is stored in a variable we created called &amp;quot;Armed&amp;quot;. &lt;br /&gt;
&lt;br /&gt;
=== Scene Actions  ===&lt;br /&gt;
&lt;br /&gt;
==== Run Scene #5  ====&lt;br /&gt;
&lt;br /&gt;
Thanks &amp;quot;denix&amp;quot; on the forum for the correct syntax. &amp;quot;Actually, the 4th parameter IS required, but it's not used. Otherwise the command fails with an error message&amp;quot; &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
  luup.call_action(&amp;quot;urn:micasaverde-com:serviceId:HomeAutomationGateway1&amp;quot;, &amp;quot;RunScene&amp;quot;, {SceneNum = &amp;quot;5&amp;quot;}, 0)&lt;br /&gt;
&amp;lt;/source&amp;gt; &lt;br /&gt;
&lt;br /&gt;
In this case we left the device number off (the 4th parameter to &amp;lt;tt&amp;gt;luup.call_action&amp;lt;/tt&amp;gt;), because the &amp;quot;&amp;lt;tt&amp;gt;RunScene&amp;lt;/tt&amp;gt;&amp;quot; action is handled by the Luup engine itself--not by some device within Z-Wave, etc. &lt;br /&gt;
&lt;br /&gt;
However, normally you don't need to &amp;lt;tt&amp;gt;luup.call_action&amp;lt;/tt&amp;gt; in Lua code. Rather, whatever actions, or commands, you want to run, you put into the scene itself, and the only Lua code is to simply check if some condition is true and abort the scene if the condition isn't met. &lt;br /&gt;
&lt;br /&gt;
=== Thermostat Actions  ===&lt;br /&gt;
&lt;br /&gt;
==== Change the Temperature on Thermostat (Cool) device #19  ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
  luup.call_action(&amp;quot;urn:upnp-org:serviceId:TemperatureSetpoint1_Cool&amp;quot;,&lt;br /&gt;
                   &amp;quot;SetCurrentSetpoint&amp;quot;, {NewCurrentSetpoint = &amp;quot;68&amp;quot;},&lt;br /&gt;
                   19)&lt;br /&gt;
&amp;lt;/source&amp;gt; &lt;br /&gt;
&lt;br /&gt;
==== Change the Temperature on a Thermostat (Heat) device #19  ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
  luup.call_action(&amp;quot;urn:upnp-org:serviceId:TemperatureSetpoint1_Heat&amp;quot;,&lt;br /&gt;
                   &amp;quot;SetCurrentSetpoint&amp;quot;, {NewCurrentSetpoint = &amp;quot;68&amp;quot;},&lt;br /&gt;
                   19)&lt;br /&gt;
&amp;lt;/source&amp;gt; &lt;br /&gt;
&lt;br /&gt;
==== Change the Thermostat Operating mode device #19  ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
luup.call_action(&amp;quot;urn:upnp-org:serviceId:HVAC_UserOperatingMode1&amp;quot;,&lt;br /&gt;
                 &amp;quot;SetModeTarget&amp;quot;, {NewModeTarget = &amp;quot;Off&amp;quot;},&lt;br /&gt;
                 19)&lt;br /&gt;
&amp;lt;/source&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt; &lt;br /&gt;
&lt;br /&gt;
=== Camera Actions  ===&lt;br /&gt;
&lt;br /&gt;
==== 'Privacy' mode for Foscam FI8908[w]  ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
  local IP_address = '&amp;lt;IP address of camera&amp;gt;'&lt;br /&gt;
  local username = '&amp;lt;username&amp;gt;'&lt;br /&gt;
  local password = '&amp;lt;password&amp;gt;'&lt;br /&gt;
  local timeout  = 5&lt;br /&gt;
 &lt;br /&gt;
  function move_up()&lt;br /&gt;
    luup.inet.wget('http://' .. IP_address .. '/decoder_control.cgi?command=0', timeout, username, password)&lt;br /&gt;
  end&lt;br /&gt;
 &lt;br /&gt;
  -- center the camera; takes some time, so we have to wait 2 minutes for the command to complete&lt;br /&gt;
 &lt;br /&gt;
  luup.inet.wget('http://' .. IP_address .. '/decoder_control.cgi?command=25', timeout, username, password)&lt;br /&gt;
 &lt;br /&gt;
  luup.call_delay('move_up', 120)&lt;br /&gt;
&amp;lt;/source&amp;gt; &lt;br /&gt;
&lt;br /&gt;
=== Misc Actions  ===&lt;br /&gt;
&lt;br /&gt;
==== Playing an announcement  ====&lt;br /&gt;
&lt;br /&gt;
http://forum.micasaverde.com/index.php?topic=5466.msg36405#msg36405 &lt;br /&gt;
&lt;br /&gt;
=== Calculate sunrise and sunset  ===&lt;br /&gt;
&lt;br /&gt;
See http://forum.micasaverde.com/index.php?topic=2073.msg8132#msg8132 &lt;br /&gt;
&lt;br /&gt;
... or use DAD: http://forum.micasaverde.com/index.php?topic=5466.0 &lt;br /&gt;
&lt;br /&gt;
=== Access the web  ===&lt;br /&gt;
&lt;br /&gt;
==== Invoke HTTP URL with &amp;lt;tt&amp;gt;GET&amp;lt;/tt&amp;gt; request (Method 1)  ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
  -- 5 Second timeout&lt;br /&gt;
  local status, result = luup.inet.wget(&amp;quot;http://www.yahoo.com&amp;quot;, 5)&lt;br /&gt;
&amp;lt;/source&amp;gt; &lt;br /&gt;
&lt;br /&gt;
==== Invoke HTTP URL with &amp;lt;tt&amp;gt;GET&amp;lt;/tt&amp;gt; request (Method 2)  ====&lt;br /&gt;
&lt;br /&gt;
Based on code by Jim/jgc94131 &amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
  require('ltn12')&lt;br /&gt;
  local http = require('socket.http')&lt;br /&gt;
&lt;br /&gt;
  -- 5 Second timeout&lt;br /&gt;
  socket.http.TIMEOUT = 5&lt;br /&gt;
&lt;br /&gt;
  local response_body = {}&lt;br /&gt;
  local request_body = ''&lt;br /&gt;
&lt;br /&gt;
  local r, c, h = socket.http.request{&lt;br /&gt;
    url = 'http://website/page?parameter1=value&amp;amp;parameter2=value',&lt;br /&gt;
    method = &amp;quot;GET&amp;quot;,&lt;br /&gt;
    port = 80,&lt;br /&gt;
    headers = {&lt;br /&gt;
      [&amp;quot;Content-Length&amp;quot;] = string.len(request_body),&lt;br /&gt;
      [&amp;quot;Content-Type&amp;quot;] = &amp;quot;application/x-www-form-urlencoded&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    source = ltn12.source.string(request_body),&lt;br /&gt;
    sink = ltn12.sink.table(response_body)&lt;br /&gt;
  }&lt;br /&gt;
&amp;lt;/source&amp;gt; &lt;br /&gt;
&lt;br /&gt;
==== Invoke HTTP URL with &amp;lt;tt&amp;gt;POST&amp;lt;/tt&amp;gt; request (Method 3)  ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
  local http = require(&amp;quot;socket.http&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
  -- 5 Second timeout&lt;br /&gt;
  http.TIMEOUT = 5&lt;br /&gt;
&lt;br /&gt;
  -- The return parameters are in a different order from luup.inet.wget(...)&lt;br /&gt;
  result, status = http.request(&amp;quot;http://192.168.0.113/runprocess.htm&amp;quot;, &amp;quot;run=run&amp;quot;)    &lt;br /&gt;
&amp;lt;/source&amp;gt; &lt;br /&gt;
&lt;br /&gt;
=== Access the current time  ===&lt;br /&gt;
&lt;br /&gt;
The Lua function &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
  os.date (format, time)&lt;br /&gt;
&amp;lt;/source&amp;gt; &lt;br /&gt;
&lt;br /&gt;
converts a time value `time` into a human readable date/time string, according to `format`. If you leave out the optional `time` parameter, it defaults to current time. The `format` parameter defaults to a fairly complete format. If you specify '*t' as the format, it will return a table instead of a formatted string. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
  t = os.date('*t')&lt;br /&gt;
  t = {year=2010, month=2, day=19, yday=50, wday=6, hour=22, min=45, sec=45, isdst=false}&lt;br /&gt;
&amp;lt;/source&amp;gt; &lt;br /&gt;
&lt;br /&gt;
The fields are year, month, day of month, day of year, day of week, hour in 24 hour clock, minutes, seconds and if it's Daylight Savings Time. &lt;br /&gt;
&lt;br /&gt;
Current hour: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
  os.date('*t').hour&lt;br /&gt;
&amp;lt;/source&amp;gt; &lt;br /&gt;
&lt;br /&gt;
Current minute: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
  os.date('*t').min&lt;br /&gt;
&amp;lt;/source&amp;gt; &lt;br /&gt;
&lt;br /&gt;
Current second: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
  os.date('*t').sec&lt;br /&gt;
&amp;lt;/source&amp;gt; &lt;br /&gt;
&lt;br /&gt;
Do something between 16:00 and 21:15: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
  local t = os.date('*t')&lt;br /&gt;
  local current_second = t.hour * 3600 + t.min * 60 + t.sec   -- number of seconds since midnight&lt;br /&gt;
  local min_time_in_seconds = 16 * 3600 +  0 * 60             -- 16:00&lt;br /&gt;
  local max_time_in_seconds = 21 * 3600 + 15 * 60             -- 21:15&lt;br /&gt;
 &lt;br /&gt;
  if (current_second &amp;gt; min_time_in_seconds) and (current_second &amp;lt; max_time_in_seconds) then&lt;br /&gt;
    -- do something&lt;br /&gt;
  else&lt;br /&gt;
    return false&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/source&amp;gt; &lt;br /&gt;
&lt;br /&gt;
See http://forum.micasaverde.com/index.php?topic=2015.0 and http://www.lua.org/manual/5.1/manual.html#5.8.&lt;br /&gt;
&lt;br /&gt;
=== Set Z-Wave parameters  ===&lt;br /&gt;
&lt;br /&gt;
See http://forum.micasaverde.com/index.php?topic=1937.msg7803#msg7803 &lt;br /&gt;
&lt;br /&gt;
=== a scene if the temperature is outside of a range  ===&lt;br /&gt;
&lt;br /&gt;
add snippets here... &lt;br /&gt;
&lt;br /&gt;
=== Reload Luup at 3 AM every day  ===&lt;br /&gt;
&lt;br /&gt;
1. Create a scene and set it to run daily at 3 AM. &lt;br /&gt;
&lt;br /&gt;
2. Add this code in the '''Luup code''' box: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;luup.call_action(&amp;quot;urn:micasaverde-com:serviceId:HomeAutomationGateway1&amp;quot;, &amp;quot;Reload&amp;quot;, {}, 0)&amp;lt;/source&amp;gt; &lt;br /&gt;
&lt;br /&gt;
3. Save.&lt;br /&gt;
&lt;br /&gt;
=== Thermostat conditioned by door/window ===&lt;br /&gt;
Turn off the thermostat if the door/window is left open for 5 minutes or more and back on if the door/window is closed for 10 minutes or more.&lt;br /&gt;
&lt;br /&gt;
'''1.''' Create a scene and set it to run when the door is opened.&lt;br /&gt;
&lt;br /&gt;
'''2.''' Add this code in the '''Luup code''' box:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
local SENSOR = 17    -- The door/window sensor device number&lt;br /&gt;
local THERMOSTAT = 3 -- The thermostat device number&lt;br /&gt;
local DELAY = 300    -- Seconds&lt;br /&gt;
&lt;br /&gt;
local SES_SID = &amp;quot;urn:micasaverde-com:serviceId:SecuritySensor1&amp;quot;&lt;br /&gt;
local HVACO_SID = &amp;quot;urn:upnp-org:serviceId:HVAC_UserOperatingMode1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
luup.call_delay( &amp;quot;turnOffAc&amp;quot;, DELAY)&lt;br /&gt;
&lt;br /&gt;
-- Turn off the thermostat if the sensor has been tripped for at least 5 minutes.&lt;br /&gt;
function turnOffAc()&lt;br /&gt;
    local tripped = luup.variable_get( SES_SID, &amp;quot;Tripped&amp;quot;, SENSOR) or &amp;quot;0&amp;quot;&lt;br /&gt;
    local lastTrip = luup.variable_get( SES_SID, &amp;quot;LastTrip&amp;quot;, SENSOR) or os.time()&lt;br /&gt;
    if (tripped == &amp;quot;1&amp;quot; and (os.time() - lastTrip &amp;gt;= DELAY)) then&lt;br /&gt;
        local modeStatus = luup.variable_get( HVACO_SID, &amp;quot;ModeStatus&amp;quot;, THERMOSTAT) or &amp;quot;Off&amp;quot;&lt;br /&gt;
        luup.variable_set( HVACO_SID, &amp;quot;LastModeStatus&amp;quot;, modeStatus, THERMOSTAT)&lt;br /&gt;
        luup.call_action( HVACO_SID, &amp;quot;SetModeTarget&amp;quot;, {NewModeTarget = &amp;quot;Off&amp;quot;}, THERMOSTAT)&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''3.''' Create another scene and set it to run when the door is closed.&lt;br /&gt;
&lt;br /&gt;
'''4.''' Add this code in the '''Luup code''' box:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
local SENSOR = 17    -- The door/window sensor device number&lt;br /&gt;
local THERMOSTAT = 3 -- The thermostat device number&lt;br /&gt;
local DELAY = 600    -- Seconds&lt;br /&gt;
&lt;br /&gt;
local SES_SID = &amp;quot;urn:micasaverde-com:serviceId:SecuritySensor1&amp;quot;&lt;br /&gt;
local HVACO_SID = &amp;quot;urn:upnp-org:serviceId:HVAC_UserOperatingMode1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
luup.call_delay( &amp;quot;turnOnAc&amp;quot;, DELAY)&lt;br /&gt;
&lt;br /&gt;
-- Turn on the thermostat if the sensor hasn't been tripped in the past 10 minutes.&lt;br /&gt;
function turnOnAc()&lt;br /&gt;
    local tripped = luup.variable_get( SES_SID, &amp;quot;Tripped&amp;quot;, DOOR_SENSOR) or &amp;quot;0&amp;quot;&lt;br /&gt;
    local lastTrip = luup.variable_get( SES_SID, &amp;quot;LastTrip&amp;quot;, DOOR_SENSOR) or os.time()&lt;br /&gt;
    if (tripped == &amp;quot;0&amp;quot; and (os.time() - lastTrip &amp;gt;= DELAY)) then&lt;br /&gt;
        local lastModeStatus = luup.variable_get( HVACO_SID, &amp;quot;LastModeStatus&amp;quot;, THERMOSTAT) or &amp;quot;Off&amp;quot;&lt;br /&gt;
        luup.call_action( HVACO_SID, &amp;quot;SetModeTarget&amp;quot;, {NewModeTarget = lastModeStatus}, THERMOSTAT)&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''5.''' Save.&lt;br /&gt;
&lt;br /&gt;
[[Category:Development]]&lt;/div&gt;</summary>
		<author><name>Solipsia</name></author>	</entry>

	<entry>
		<id>http://wiki.mios.com/index.php/Luup_Scenes_Events</id>
		<title>Luup Scenes Events</title>
		<link rel="alternate" type="text/html" href="http://wiki.mios.com/index.php/Luup_Scenes_Events"/>
				<updated>2012-09-09T12:22:11Z</updated>
		
		<summary type="html">&lt;p&gt;Solipsia: /* Samples */ Added delay code&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Adding Lua code to scenes and events  ==&lt;br /&gt;
&lt;br /&gt;
[[Image:SceneFlowchart.png]] &lt;br /&gt;
&lt;br /&gt;
You can add Lua script to scenes and events for simple tasks, like making a scene or event conditional. Conditional meaning &amp;quot;do something only '''if''' some condition is met&amp;quot;, such as attaching a condition to your &amp;quot;Come Home&amp;quot; scene so it is only run '''if''' the temperature is over 70 degrees. Basic conditional expressions are easy, and, if that's all you're looking to do, skip to the walk-through below. &lt;br /&gt;
&lt;br /&gt;
If you're more technically inclined you can also do very advanced things too. For an overview of all the advanced things you can do with Vera's Luup engine, and how scenes and events fit in, see the [[Luup Intro]] page. &lt;br /&gt;
&lt;br /&gt;
To add Lua code to a scene, create the [[Scenes]] and click 'Luup scene'. Fill in your Lua code in the input box. To do a simple condition, see the sample below. Or if you want to do advanced scripting you can use any [[http://lua.org Lua]] commands as described in the [[http://www.lua.org/manual/5.1/ Lua reference manual]] as well as the variables and functions that the Luup engine adds to Lua documented here: [[Luup Lua extensions]]. The Lua code will be run every time the scene is activated either by the user or a scene or a timer. The Lua code is run before the commands that you included in the scene. If your Lua code ends with this: &amp;quot;return false&amp;quot; then the commands in the scene will not be run. &lt;br /&gt;
&lt;br /&gt;
You can also add Lua code to an event by clicking 'Luup event'. Since events are attached to scenes anyway, there is usually little difference between adding the code to an event, or to the scene the event is part of. If the Lua code in an event returns false, then the event is aborted, meaning the scene that the event is attached to will not be triggered by the event. The main reason for attaching Lua code to an event is if you have multiple events to a scene. For example, you may have a scene called &amp;quot;Turn lights on in hallway&amp;quot; which is triggered by 2 events: 1) The front door opens, and 2) the motion sensor in the hallway is tripped. Perhaps whenever the front door opens you always want the scene to be activated, but you only want the motion sensor to activate the scene before 10:00. In this case, you would add Lua code to the motion sensor's event which does something like (pseudo-code): &amp;quot;if time&amp;amp;gt;10:00 return false&amp;quot;. That way the event from the motion sensor will be aborted if it's after 10:00, but the event from the front door will always activate the scene regardless. &lt;br /&gt;
&lt;br /&gt;
When you edit the Lua code in a scene or event you must click 'Save' before the code is saved. Then you can activate the scene or trigger the event to see what happens when your code is run. If you're doing some advanced scripting that you'll need to debug this can be tedious, but there are easy ways to test your Lua script immediately without saving first as explained in [[Lua Debugging]]. &lt;br /&gt;
&lt;br /&gt;
If you're doing advanced Lua scripting, you should note that all the Lua code in your scenes and events run in a single Lua instance, which is separate from any Lua plugins. This means if you set a global variable in one scene, or create a function inside the Lua code in a scene, then in another scene's Lua code you can use that global variable or call that function. You do not need to worry about conflicting with a Luup plugin, though, since they have their own Lua instance, meaning they have their own global variables and functions. &lt;br /&gt;
&lt;br /&gt;
== Walk-through #1 -- At 12 noon, turn off the interior lights if the temperature is over 80 degrees  ==&lt;br /&gt;
&lt;br /&gt;
Before you start, in Vera's setup interface go to 'Devices' and click the '+' button next to the thermostat. Make note of the Device #. &lt;br /&gt;
&lt;br /&gt;
In this walkthrough we'll assume it's Device #3, but use the actual device number of''your'' thermostat. Next, visit [[Luup Variables]] to get a list of all the variables for devices. A variable is a piece of information about the current state of a device, such as whether it's on or off, it's current temperature, etc. &lt;br /&gt;
&lt;br /&gt;
Look down at ''Thermostat'', and copy the name of the service/variable which corresponds to the current temperature, namely. In this case, it's &lt;br /&gt;
&lt;br /&gt;
  urn:upnp-org:serviceId:TemperatureSensor1 CurrentTemperature&lt;br /&gt;
&lt;br /&gt;
Notice that it states the &amp;lt;tt&amp;gt;CurrentTemperature&amp;lt;/tt&amp;gt; is in Celsius. So type in &amp;quot;80 degrees Fahrenheit to Celsius&amp;quot; in Google and you'll see that it's 26.6 degrees Celsius. &lt;br /&gt;
&lt;br /&gt;
Now, the first step is to create the scene that turns off the lights. In Vera's setup interface, click 'Scenes', and click 'Add Scene' to add a new scene to one of the rooms. It's not important which room you choose. Scenes are categorized in rooms just to help you keep track of them if you have a lot of scenes. You can also put the scene in 'Global Scenes', or, you can create dummy rooms on the 'Rooms' tab if you want to have more &amp;quot;rooms&amp;quot; to organize your scenes with. After you click 'Add Scene', type in a description to remember your scene by, such as &amp;quot;Lights off 12:00 if 80&amp;quot;. Under the 'Commands' area you'll see all the rooms. Click '+' next to the rooms that have lights you want to control, and choose &amp;quot;Off&amp;quot; in the pull-down. At this point, you have a normal scene, and, if you were to save your changes now, whenever you click the scene on the dashboard or on a remote control, the lights should turn off. &lt;br /&gt;
&lt;br /&gt;
Second, next to the scene's description click 'add timer'. You can give the timer a description too so that if you have multiple timers you can see in the logs which one is activating the scene. Choose &amp;quot;Day of week based&amp;quot;. If you want this scene to only run on certain days of the week, just check off which days you want this scene to run on. Otherwise, you can leave them all unchecked (or check them all) to do it every day. Leave the pull-down at &amp;quot;a certain time of day&amp;quot;, and choose 12&amp;amp;nbsp;: 00&amp;amp;nbsp;: 00 from the pull-downs. At this point, if you were to save your changes, the lights would turn off automatically at 12 noon. &lt;br /&gt;
&lt;br /&gt;
Third, the last step is to add the condition. To the right of the scene's description you'll see the button &amp;quot;Luup Scene&amp;quot;. Click it and in the code box, copy and paste the following: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
  local lul_temp = luup.variable_get(&amp;quot;urn:upnp-org:serviceId:TemperatureSensor1&amp;quot;,&amp;quot;CurrentTemperature&amp;quot;, 3)&lt;br /&gt;
  if (tonumber(lul_temp) &amp;lt; 26.6) then&lt;br /&gt;
    return false&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/source&amp;gt; &lt;br /&gt;
&lt;br /&gt;
Don't forget to change the &amp;quot;3&amp;quot; to whatever is the actual device number of your thermostat. Assign the result of &amp;lt;tt&amp;gt;luup.variable_get&amp;lt;/tt&amp;gt; to a variable first, rather than putting it directly in the &amp;lt;tt&amp;gt;tonumber()&amp;lt;/tt&amp;gt;, because &amp;lt;tt&amp;gt;luup.variable_get&amp;lt;/tt&amp;gt; actually returns 2 values: the value of the variable, and the time when the variable was modified. The '&amp;lt;tt&amp;gt;tonumber&amp;lt;/tt&amp;gt;' is needed because all of a device's variables are stored as plain text--not numbers--so if you want to do arithmetic or numeric comparison of a variable, you need to put &amp;lt;tt&amp;gt;tonumber()&amp;lt;/tt&amp;gt; around &amp;lt;tt&amp;gt;luup.variable_get&amp;lt;/tt&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;luup.variable_get&amp;lt;/tt&amp;gt; is documented in [[Luup Lua extensions]]. &lt;br /&gt;
&lt;br /&gt;
Now click 'Update', and then click 'Save' to save everything. The &amp;quot;return false&amp;quot; means &amp;quot;don't run this scene&amp;quot;. So if the current temperature is &amp;amp;lt;26.6, the scene will be aborted and won't run. The timer will make it trigger every day at 12 noon. &lt;br /&gt;
&lt;br /&gt;
To test it, you can click the scene button on the dashboard. The lights will turn off only if the temperature is over 80 degrees. If it's less than 80 degrees, the scene won't do anything. Since this scene is something that happens automatically and you probably won't execute manually, you can go to the scene again and check the &amp;quot;Hidden&amp;quot; box so the scene doesn't show up on&amp;amp;nbsp;Vera's 'Dashboard' and on your remote controls, like the iPhone. If you want to have a scene that turns off the lights which you can run whenever you want from 'Dashboard''or your remote control, you should create another scene that has the same commands and simply don't add the timers and Luup conditions, and don't check the &amp;quot;Hidden&amp;quot; box. '' &lt;br /&gt;
&lt;br /&gt;
You can substitute other service/variables and device ID's to make other types of conditions. The &amp;quot;if&amp;quot; statement above also supports nesting with ( and ), as well as the keywords 'and' and 'or'. So the following means the scene would abort if the temperature is &amp;amp;lt;26.6 and &amp;amp;gt;25, unless it's &amp;amp;lt;23: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
  local lul_temp = luup.variable_get(&amp;quot;urn:upnp-org:serviceId:TemperatureSensor1&amp;quot;,&amp;quot;CurrentTemperature&amp;quot;, 3)&lt;br /&gt;
  if ((tonumber(lul_temp) &amp;lt; 26.6&lt;br /&gt;
    and tonumber(lul_temp) &amp;gt; 25)&lt;br /&gt;
    or tonumber(lul_temp) &amp;lt; 23) then&lt;br /&gt;
      return false&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/source&amp;gt; &lt;br /&gt;
&lt;br /&gt;
If the scene doesn't run, it's possible&amp;amp;nbsp;there is&amp;amp;nbsp;a syntax error. The easiest way to test this is to copy the Lua code from the scene, then go to Devices, Luup Plugins, and &amp;quot;Test Luup code&amp;quot;. Paste the code in the box and click 'go'. If the info box above the 'go' button has a check and says &amp;quot;Message sent successful&amp;quot;, your code is okay. If there's an error, it says: &amp;quot;Code failed&amp;quot;. &lt;br /&gt;
&lt;br /&gt;
To see if that's true, use putty, or telnet or ssh to log-in to Vera, as explained in detail in [[Logon_Vera_SSH]] and [[Lua Debugging]], and type: &lt;br /&gt;
&lt;br /&gt;
   cd /var/log/cmh&lt;br /&gt;
 tail -f LuaUPnP.log | grep '^01'&lt;br /&gt;
&lt;br /&gt;
Now click 'Save' in Vera's setup page, even if it's gray, as that will cause Vera to restart the Luup engine and log any syntax errors. See: [[Lua Debugging]] for in-depth details on how to debug.&lt;br /&gt;
&lt;br /&gt;
== Walk-through #2 -- Only run the scene during the daytime  ==&lt;br /&gt;
&lt;br /&gt;
In the Luup tab for the scene paste this: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
  return luup.is_night() == false&lt;br /&gt;
&amp;lt;/source&amp;gt; &lt;br /&gt;
&lt;br /&gt;
That works because if the return is 'true' the scene runs, and if it's 'false' it doesn't. So during the daytime the expression is true. Or, an alternative long form: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
  if (luup.is_night()) then&lt;br /&gt;
     return false&lt;br /&gt;
  else&lt;br /&gt;
     return true&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/source&amp;gt; &lt;br /&gt;
&lt;br /&gt;
== Samples  ==&lt;br /&gt;
&lt;br /&gt;
This page is a wiki which anyone can edit. If you have some Lua code you think other users might find useful, feel free to add it here. &lt;br /&gt;
&lt;br /&gt;
=== Lighting and Switch Actions  ===&lt;br /&gt;
&lt;br /&gt;
Did you see the sample here already: http://wiki.micasaverde.com/index.php/Luup_Scenes_Events &lt;br /&gt;
&lt;br /&gt;
==== Turn an appliance switch or a Danfoss thermostat on for device #5  ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
  luup.call_action(&amp;quot;urn:upnp-org:serviceId:SwitchPower1&amp;quot;, &amp;quot;SetTarget&amp;quot;, {newTargetValue = &amp;quot;1&amp;quot;}, 5)&lt;br /&gt;
&amp;lt;/source&amp;gt; &lt;br /&gt;
&lt;br /&gt;
==== Turn an appliance switch or a Danfoss thermostat off  ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
  luup.call_action(&amp;quot;urn:upnp-org:serviceId:SwitchPower1&amp;quot;, &amp;quot;SetTarget&amp;quot;, {newTargetValue = &amp;quot;0&amp;quot;}, 5)&lt;br /&gt;
&amp;lt;/source&amp;gt; &lt;br /&gt;
&lt;br /&gt;
==== Do something if switch device #5 is on  ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
  local lul_tmp = luup.variable_get(&amp;quot;urn:upnp-org:serviceId:SwitchPower1&amp;quot;, &amp;quot;Status&amp;quot;, 5)&lt;br /&gt;
  if (lul_tmp == &amp;quot;1&amp;quot;) then&lt;br /&gt;
     --something to do goes here&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/source&amp;gt; &lt;br /&gt;
&lt;br /&gt;
==== Dim switch #6 to 30%  ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
  luup.call_action(&amp;quot;urn:upnp-org:serviceId:Dimming1&amp;quot;, &amp;quot;SetLoadLevelTarget&amp;quot;, {newLoadlevelTarget = &amp;quot;30&amp;quot;}, 6)&lt;br /&gt;
&amp;lt;/source&amp;gt; &lt;br /&gt;
&lt;br /&gt;
== Switch on, and switch off 2 seconds later ==&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
local device  = 29&lt;br /&gt;
luup.call_action(&amp;quot;urn:upnp-org:serviceId:SwitchPower1&amp;quot;,&amp;quot;SetTarget&amp;quot;,{ newTargetValue=&amp;quot;1&amp;quot; },device)&lt;br /&gt;
luup.call_delay( 'switch_off', 2) -- Call this function after a delay of 2 seconds&lt;br /&gt;
function switch_off()&lt;br /&gt;
   luup.call_action(&amp;quot;urn:upnp-org:serviceId:SwitchPower1&amp;quot;,&amp;quot;SetTarget&amp;quot;,{ newTargetValue=&amp;quot;0&amp;quot; },device)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/source&amp;gt; &lt;br /&gt;
&lt;br /&gt;
==== Blinking lights (and how to delay for a number of seconds)  ====&lt;br /&gt;
&lt;br /&gt;
http://forum.micasaverde.com/index.php?topic=5127.0&lt;br /&gt;
&lt;br /&gt;
=== Motion Sensor Actions  ===&lt;br /&gt;
&lt;br /&gt;
==== Arm motion sensor #7  ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
  luup.variable_set(&amp;quot;urn:micasaverde-com:serviceId:SecuritySensor1&amp;quot;, &amp;quot;Armed&amp;quot;, &amp;quot;1&amp;quot;, 7)&lt;br /&gt;
&amp;lt;/source&amp;gt; &lt;br /&gt;
&lt;br /&gt;
==== Disarm motion sensor #7  ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
  luup.variable_set(&amp;quot;urn:micasaverde-com:serviceId:SecuritySensor1&amp;quot;, &amp;quot;Armed&amp;quot;, &amp;quot;0&amp;quot;, 7)&lt;br /&gt;
&amp;lt;/source&amp;gt; &lt;br /&gt;
&lt;br /&gt;
Note, arming and disarming isn't a concept within UPnP or Z-Wave. It's just a flag that the Luup engine uses, and is stored in a variable we created called &amp;quot;Armed&amp;quot;. &lt;br /&gt;
&lt;br /&gt;
=== Scene Actions  ===&lt;br /&gt;
&lt;br /&gt;
==== Run Scene #5  ====&lt;br /&gt;
&lt;br /&gt;
Thanks &amp;quot;denix&amp;quot; on the forum for the correct syntax. &amp;quot;Actually, the 4th parameter IS required, but it's not used. Otherwise the command fails with an error message&amp;quot; &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
  luup.call_action(&amp;quot;urn:micasaverde-com:serviceId:HomeAutomationGateway1&amp;quot;, &amp;quot;RunScene&amp;quot;, {SceneNum = &amp;quot;5&amp;quot;}, 0)&lt;br /&gt;
&amp;lt;/source&amp;gt; &lt;br /&gt;
&lt;br /&gt;
In this case we left the device number off (the 4th parameter to &amp;lt;tt&amp;gt;luup.call_action&amp;lt;/tt&amp;gt;), because the &amp;quot;&amp;lt;tt&amp;gt;RunScene&amp;lt;/tt&amp;gt;&amp;quot; action is handled by the Luup engine itself--not by some device within Z-Wave, etc. &lt;br /&gt;
&lt;br /&gt;
However, normally you don't need to &amp;lt;tt&amp;gt;luup.call_action&amp;lt;/tt&amp;gt; in Lua code. Rather, whatever actions, or commands, you want to run, you put into the scene itself, and the only Lua code is to simply check if some condition is true and abort the scene if the condition isn't met. &lt;br /&gt;
&lt;br /&gt;
=== Thermostat Actions  ===&lt;br /&gt;
&lt;br /&gt;
==== Change the Temperature on Thermostat (Cool) device #19  ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
  luup.call_action(&amp;quot;urn:upnp-org:serviceId:TemperatureSetpoint1_Cool&amp;quot;,&lt;br /&gt;
                   &amp;quot;SetCurrentSetpoint&amp;quot;, {NewCurrentSetpoint = &amp;quot;68&amp;quot;},&lt;br /&gt;
                   19)&lt;br /&gt;
&amp;lt;/source&amp;gt; &lt;br /&gt;
&lt;br /&gt;
==== Change the Temperature on a Thermostat (Heat) device #19  ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
  luup.call_action(&amp;quot;urn:upnp-org:serviceId:TemperatureSetpoint1_Heat&amp;quot;,&lt;br /&gt;
                   &amp;quot;SetCurrentSetpoint&amp;quot;, {NewCurrentSetpoint = &amp;quot;68&amp;quot;},&lt;br /&gt;
                   19)&lt;br /&gt;
&amp;lt;/source&amp;gt; &lt;br /&gt;
&lt;br /&gt;
==== Change the Thermostat Operating mode device #19  ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
luup.call_action(&amp;quot;urn:upnp-org:serviceId:HVAC_UserOperatingMode1&amp;quot;,&lt;br /&gt;
                 &amp;quot;SetModeTarget&amp;quot;, {NewModeTarget = &amp;quot;Off&amp;quot;},&lt;br /&gt;
                 19)&lt;br /&gt;
&amp;lt;/source&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt; &lt;br /&gt;
&lt;br /&gt;
=== Camera Actions  ===&lt;br /&gt;
&lt;br /&gt;
==== 'Privacy' mode for Foscam FI8908[w]  ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
  local IP_address = '&amp;lt;IP address of camera&amp;gt;'&lt;br /&gt;
  local username = '&amp;lt;username&amp;gt;'&lt;br /&gt;
  local password = '&amp;lt;password&amp;gt;'&lt;br /&gt;
  local timeout  = 5&lt;br /&gt;
 &lt;br /&gt;
  function move_up()&lt;br /&gt;
    luup.inet.wget('http://' .. IP_address .. '/decoder_control.cgi?command=0', timeout, username, password)&lt;br /&gt;
  end&lt;br /&gt;
 &lt;br /&gt;
  -- center the camera; takes some time, so we have to wait 2 minutes for the command to complete&lt;br /&gt;
 &lt;br /&gt;
  luup.inet.wget('http://' .. IP_address .. '/decoder_control.cgi?command=25', timeout, username, password)&lt;br /&gt;
 &lt;br /&gt;
  luup.call_delay('move_up', 120)&lt;br /&gt;
&amp;lt;/source&amp;gt; &lt;br /&gt;
&lt;br /&gt;
=== Misc Actions  ===&lt;br /&gt;
&lt;br /&gt;
==== Playing an announcement  ====&lt;br /&gt;
&lt;br /&gt;
http://forum.micasaverde.com/index.php?topic=5466.msg36405#msg36405 &lt;br /&gt;
&lt;br /&gt;
=== Calculate sunrise and sunset  ===&lt;br /&gt;
&lt;br /&gt;
See http://forum.micasaverde.com/index.php?topic=2073.msg8132#msg8132 &lt;br /&gt;
&lt;br /&gt;
... or use DAD: http://forum.micasaverde.com/index.php?topic=5466.0 &lt;br /&gt;
&lt;br /&gt;
=== Access the web  ===&lt;br /&gt;
&lt;br /&gt;
==== Invoke HTTP URL with &amp;lt;tt&amp;gt;GET&amp;lt;/tt&amp;gt; request (Method 1)  ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
  -- 5 Second timeout&lt;br /&gt;
  local status, result = luup.inet.wget(&amp;quot;http://www.yahoo.com&amp;quot;, 5)&lt;br /&gt;
&amp;lt;/source&amp;gt; &lt;br /&gt;
&lt;br /&gt;
==== Invoke HTTP URL with &amp;lt;tt&amp;gt;GET&amp;lt;/tt&amp;gt; request (Method 2)  ====&lt;br /&gt;
&lt;br /&gt;
Based on code by Jim/jgc94131 &amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
  require('ltn12')&lt;br /&gt;
  local http = require('socket.http')&lt;br /&gt;
&lt;br /&gt;
  -- 5 Second timeout&lt;br /&gt;
  socket.http.TIMEOUT = 5&lt;br /&gt;
&lt;br /&gt;
  local response_body = {}&lt;br /&gt;
  local request_body = ''&lt;br /&gt;
&lt;br /&gt;
  local r, c, h = socket.http.request{&lt;br /&gt;
    url = 'http://website/page?parameter1=value&amp;amp;parameter2=value',&lt;br /&gt;
    method = &amp;quot;GET&amp;quot;,&lt;br /&gt;
    port = 80,&lt;br /&gt;
    headers = {&lt;br /&gt;
      [&amp;quot;Content-Length&amp;quot;] = string.len(request_body),&lt;br /&gt;
      [&amp;quot;Content-Type&amp;quot;] = &amp;quot;application/x-www-form-urlencoded&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    source = ltn12.source.string(request_body),&lt;br /&gt;
    sink = ltn12.sink.table(response_body)&lt;br /&gt;
  }&lt;br /&gt;
&amp;lt;/source&amp;gt; &lt;br /&gt;
&lt;br /&gt;
==== Invoke HTTP URL with &amp;lt;tt&amp;gt;POST&amp;lt;/tt&amp;gt; request (Method 3)  ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
  local http = require(&amp;quot;socket.http&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
  -- 5 Second timeout&lt;br /&gt;
  http.TIMEOUT = 5&lt;br /&gt;
&lt;br /&gt;
  -- The return parameters are in a different order from luup.inet.wget(...)&lt;br /&gt;
  result, status = http.request(&amp;quot;http://192.168.0.113/runprocess.htm&amp;quot;, &amp;quot;run=run&amp;quot;)    &lt;br /&gt;
&amp;lt;/source&amp;gt; &lt;br /&gt;
&lt;br /&gt;
=== Access the current time  ===&lt;br /&gt;
&lt;br /&gt;
The Lua function &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
  os.date (format, time)&lt;br /&gt;
&amp;lt;/source&amp;gt; &lt;br /&gt;
&lt;br /&gt;
converts a time value `time` into a human readable date/time string, according to `format`. If you leave out the optional `time` parameter, it defaults to current time. The `format` parameter defaults to a fairly complete format. If you specify '*t' as the format, it will return a table instead of a formatted string. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
  t = os.date('*t')&lt;br /&gt;
  t = {year=2010, month=2, day=19, yday=50, wday=6, hour=22, min=45, sec=45, isdst=false}&lt;br /&gt;
&amp;lt;/source&amp;gt; &lt;br /&gt;
&lt;br /&gt;
The fields are year, month, day of month, day of year, day of week, hour in 24 hour clock, minutes, seconds and if it's Daylight Savings Time. &lt;br /&gt;
&lt;br /&gt;
Current hour: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
  os.date('*t').hour&lt;br /&gt;
&amp;lt;/source&amp;gt; &lt;br /&gt;
&lt;br /&gt;
Current minute: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
  os.date('*t').min&lt;br /&gt;
&amp;lt;/source&amp;gt; &lt;br /&gt;
&lt;br /&gt;
Current second: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
  os.date('*t').sec&lt;br /&gt;
&amp;lt;/source&amp;gt; &lt;br /&gt;
&lt;br /&gt;
Do something between 16:00 and 21:15: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
  local t = os.date('*t')&lt;br /&gt;
  local current_second = t.hour * 3600 + t.min * 60 + t.sec   -- number of seconds since midnight&lt;br /&gt;
  local min_time_in_seconds = 16 * 3600 +  0 * 60             -- 16:00&lt;br /&gt;
  local max_time_in_seconds = 21 * 3600 + 15 * 60             -- 21:15&lt;br /&gt;
 &lt;br /&gt;
  if (current_second &amp;gt; min_time_in_seconds) and (current_second &amp;lt; max_time_in_seconds) then&lt;br /&gt;
    -- do something&lt;br /&gt;
  else&lt;br /&gt;
    return false&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/source&amp;gt; &lt;br /&gt;
&lt;br /&gt;
See http://forum.micasaverde.com/index.php?topic=2015.0 and http://www.lua.org/manual/5.1/manual.html#5.8.&lt;br /&gt;
&lt;br /&gt;
=== Set Z-Wave parameters  ===&lt;br /&gt;
&lt;br /&gt;
See http://forum.micasaverde.com/index.php?topic=1937.msg7803#msg7803 &lt;br /&gt;
&lt;br /&gt;
=== a scene if the temperature is outside of a range  ===&lt;br /&gt;
&lt;br /&gt;
add snippets here... &lt;br /&gt;
&lt;br /&gt;
=== Reload Luup at 3 AM every day  ===&lt;br /&gt;
&lt;br /&gt;
1. Create a scene and set it to run daily at 3 AM. &lt;br /&gt;
&lt;br /&gt;
2. Add this code in the '''Luup code''' box: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;luup.call_action(&amp;quot;urn:micasaverde-com:serviceId:HomeAutomationGateway1&amp;quot;, &amp;quot;Reload&amp;quot;, {}, 0)&amp;lt;/source&amp;gt; &lt;br /&gt;
&lt;br /&gt;
3. Save.&lt;br /&gt;
&lt;br /&gt;
=== Thermostat conditioned by door/window ===&lt;br /&gt;
Turn off the thermostat if the door/window is left open for 5 minutes or more and back on if the door/window is closed for 10 minutes or more.&lt;br /&gt;
&lt;br /&gt;
'''1.''' Create a scene and set it to run when the door is opened.&lt;br /&gt;
&lt;br /&gt;
'''2.''' Add this code in the '''Luup code''' box:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
local SENSOR = 17    -- The door/window sensor device number&lt;br /&gt;
local THERMOSTAT = 3 -- The thermostat device number&lt;br /&gt;
local DELAY = 300    -- Seconds&lt;br /&gt;
&lt;br /&gt;
local SES_SID = &amp;quot;urn:micasaverde-com:serviceId:SecuritySensor1&amp;quot;&lt;br /&gt;
local HVACO_SID = &amp;quot;urn:upnp-org:serviceId:HVAC_UserOperatingMode1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
luup.call_delay( &amp;quot;turnOffAc&amp;quot;, DELAY)&lt;br /&gt;
&lt;br /&gt;
-- Turn off the thermostat if the sensor has been tripped for at least 5 minutes.&lt;br /&gt;
function turnOffAc()&lt;br /&gt;
    local tripped = luup.variable_get( SES_SID, &amp;quot;Tripped&amp;quot;, SENSOR) or &amp;quot;0&amp;quot;&lt;br /&gt;
    local lastTrip = luup.variable_get( SES_SID, &amp;quot;LastTrip&amp;quot;, SENSOR) or os.time()&lt;br /&gt;
    if (tripped == &amp;quot;1&amp;quot; and (os.time() - lastTrip &amp;gt;= DELAY)) then&lt;br /&gt;
        local modeStatus = luup.variable_get( HVACO_SID, &amp;quot;ModeStatus&amp;quot;, THERMOSTAT) or &amp;quot;Off&amp;quot;&lt;br /&gt;
        luup.variable_set( HVACO_SID, &amp;quot;LastModeStatus&amp;quot;, modeStatus, THERMOSTAT)&lt;br /&gt;
        luup.call_action( HVACO_SID, &amp;quot;SetModeTarget&amp;quot;, {NewModeTarget = &amp;quot;Off&amp;quot;}, THERMOSTAT)&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''3.''' Create another scene and set it to run when the door is closed.&lt;br /&gt;
&lt;br /&gt;
'''4.''' Add this code in the '''Luup code''' box:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
local SENSOR = 17    -- The door/window sensor device number&lt;br /&gt;
local THERMOSTAT = 3 -- The thermostat device number&lt;br /&gt;
local DELAY = 600    -- Seconds&lt;br /&gt;
&lt;br /&gt;
local SES_SID = &amp;quot;urn:micasaverde-com:serviceId:SecuritySensor1&amp;quot;&lt;br /&gt;
local HVACO_SID = &amp;quot;urn:upnp-org:serviceId:HVAC_UserOperatingMode1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
luup.call_delay( &amp;quot;turnOnAc&amp;quot;, DELAY)&lt;br /&gt;
&lt;br /&gt;
-- Turn on the thermostat if the sensor hasn't been tripped in the past 10 minutes.&lt;br /&gt;
function turnOnAc()&lt;br /&gt;
    local tripped = luup.variable_get( SES_SID, &amp;quot;Tripped&amp;quot;, DOOR_SENSOR) or &amp;quot;0&amp;quot;&lt;br /&gt;
    local lastTrip = luup.variable_get( SES_SID, &amp;quot;LastTrip&amp;quot;, DOOR_SENSOR) or os.time()&lt;br /&gt;
    if (tripped == &amp;quot;0&amp;quot; and (os.time() - lastTrip &amp;gt;= DELAY)) then&lt;br /&gt;
        local lastModeStatus = luup.variable_get( HVACO_SID, &amp;quot;LastModeStatus&amp;quot;, THERMOSTAT) or &amp;quot;Off&amp;quot;&lt;br /&gt;
        luup.call_action( HVACO_SID, &amp;quot;SetModeTarget&amp;quot;, {NewModeTarget = lastModeStatus}, THERMOSTAT)&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''5.''' Save.&lt;br /&gt;
&lt;br /&gt;
[[Category:Development]]&lt;/div&gt;</summary>
		<author><name>Solipsia</name></author>	</entry>

	<entry>
		<id>http://wiki.mios.com/index.php/Luup_Scenes_Events</id>
		<title>Luup Scenes Events</title>
		<link rel="alternate" type="text/html" href="http://wiki.mios.com/index.php/Luup_Scenes_Events"/>
				<updated>2012-09-09T12:17:07Z</updated>
		
		<summary type="html">&lt;p&gt;Solipsia: /* Blinking lights */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Adding Lua code to scenes and events  ==&lt;br /&gt;
&lt;br /&gt;
[[Image:SceneFlowchart.png]] &lt;br /&gt;
&lt;br /&gt;
You can add Lua script to scenes and events for simple tasks, like making a scene or event conditional. Conditional meaning &amp;quot;do something only '''if''' some condition is met&amp;quot;, such as attaching a condition to your &amp;quot;Come Home&amp;quot; scene so it is only run '''if''' the temperature is over 70 degrees. Basic conditional expressions are easy, and, if that's all you're looking to do, skip to the walk-through below. &lt;br /&gt;
&lt;br /&gt;
If you're more technically inclined you can also do very advanced things too. For an overview of all the advanced things you can do with Vera's Luup engine, and how scenes and events fit in, see the [[Luup Intro]] page. &lt;br /&gt;
&lt;br /&gt;
To add Lua code to a scene, create the [[Scenes]] and click 'Luup scene'. Fill in your Lua code in the input box. To do a simple condition, see the sample below. Or if you want to do advanced scripting you can use any [[http://lua.org Lua]] commands as described in the [[http://www.lua.org/manual/5.1/ Lua reference manual]] as well as the variables and functions that the Luup engine adds to Lua documented here: [[Luup Lua extensions]]. The Lua code will be run every time the scene is activated either by the user or a scene or a timer. The Lua code is run before the commands that you included in the scene. If your Lua code ends with this: &amp;quot;return false&amp;quot; then the commands in the scene will not be run. &lt;br /&gt;
&lt;br /&gt;
You can also add Lua code to an event by clicking 'Luup event'. Since events are attached to scenes anyway, there is usually little difference between adding the code to an event, or to the scene the event is part of. If the Lua code in an event returns false, then the event is aborted, meaning the scene that the event is attached to will not be triggered by the event. The main reason for attaching Lua code to an event is if you have multiple events to a scene. For example, you may have a scene called &amp;quot;Turn lights on in hallway&amp;quot; which is triggered by 2 events: 1) The front door opens, and 2) the motion sensor in the hallway is tripped. Perhaps whenever the front door opens you always want the scene to be activated, but you only want the motion sensor to activate the scene before 10:00. In this case, you would add Lua code to the motion sensor's event which does something like (pseudo-code): &amp;quot;if time&amp;amp;gt;10:00 return false&amp;quot;. That way the event from the motion sensor will be aborted if it's after 10:00, but the event from the front door will always activate the scene regardless. &lt;br /&gt;
&lt;br /&gt;
When you edit the Lua code in a scene or event you must click 'Save' before the code is saved. Then you can activate the scene or trigger the event to see what happens when your code is run. If you're doing some advanced scripting that you'll need to debug this can be tedious, but there are easy ways to test your Lua script immediately without saving first as explained in [[Lua Debugging]]. &lt;br /&gt;
&lt;br /&gt;
If you're doing advanced Lua scripting, you should note that all the Lua code in your scenes and events run in a single Lua instance, which is separate from any Lua plugins. This means if you set a global variable in one scene, or create a function inside the Lua code in a scene, then in another scene's Lua code you can use that global variable or call that function. You do not need to worry about conflicting with a Luup plugin, though, since they have their own Lua instance, meaning they have their own global variables and functions. &lt;br /&gt;
&lt;br /&gt;
== Walk-through #1 -- At 12 noon, turn off the interior lights if the temperature is over 80 degrees  ==&lt;br /&gt;
&lt;br /&gt;
Before you start, in Vera's setup interface go to 'Devices' and click the '+' button next to the thermostat. Make note of the Device #. &lt;br /&gt;
&lt;br /&gt;
In this walkthrough we'll assume it's Device #3, but use the actual device number of''your'' thermostat. Next, visit [[Luup Variables]] to get a list of all the variables for devices. A variable is a piece of information about the current state of a device, such as whether it's on or off, it's current temperature, etc. &lt;br /&gt;
&lt;br /&gt;
Look down at ''Thermostat'', and copy the name of the service/variable which corresponds to the current temperature, namely. In this case, it's &lt;br /&gt;
&lt;br /&gt;
  urn:upnp-org:serviceId:TemperatureSensor1 CurrentTemperature&lt;br /&gt;
&lt;br /&gt;
Notice that it states the &amp;lt;tt&amp;gt;CurrentTemperature&amp;lt;/tt&amp;gt; is in Celsius. So type in &amp;quot;80 degrees Fahrenheit to Celsius&amp;quot; in Google and you'll see that it's 26.6 degrees Celsius. &lt;br /&gt;
&lt;br /&gt;
Now, the first step is to create the scene that turns off the lights. In Vera's setup interface, click 'Scenes', and click 'Add Scene' to add a new scene to one of the rooms. It's not important which room you choose. Scenes are categorized in rooms just to help you keep track of them if you have a lot of scenes. You can also put the scene in 'Global Scenes', or, you can create dummy rooms on the 'Rooms' tab if you want to have more &amp;quot;rooms&amp;quot; to organize your scenes with. After you click 'Add Scene', type in a description to remember your scene by, such as &amp;quot;Lights off 12:00 if 80&amp;quot;. Under the 'Commands' area you'll see all the rooms. Click '+' next to the rooms that have lights you want to control, and choose &amp;quot;Off&amp;quot; in the pull-down. At this point, you have a normal scene, and, if you were to save your changes now, whenever you click the scene on the dashboard or on a remote control, the lights should turn off. &lt;br /&gt;
&lt;br /&gt;
Second, next to the scene's description click 'add timer'. You can give the timer a description too so that if you have multiple timers you can see in the logs which one is activating the scene. Choose &amp;quot;Day of week based&amp;quot;. If you want this scene to only run on certain days of the week, just check off which days you want this scene to run on. Otherwise, you can leave them all unchecked (or check them all) to do it every day. Leave the pull-down at &amp;quot;a certain time of day&amp;quot;, and choose 12&amp;amp;nbsp;: 00&amp;amp;nbsp;: 00 from the pull-downs. At this point, if you were to save your changes, the lights would turn off automatically at 12 noon. &lt;br /&gt;
&lt;br /&gt;
Third, the last step is to add the condition. To the right of the scene's description you'll see the button &amp;quot;Luup Scene&amp;quot;. Click it and in the code box, copy and paste the following: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
  local lul_temp = luup.variable_get(&amp;quot;urn:upnp-org:serviceId:TemperatureSensor1&amp;quot;,&amp;quot;CurrentTemperature&amp;quot;, 3)&lt;br /&gt;
  if (tonumber(lul_temp) &amp;lt; 26.6) then&lt;br /&gt;
    return false&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/source&amp;gt; &lt;br /&gt;
&lt;br /&gt;
Don't forget to change the &amp;quot;3&amp;quot; to whatever is the actual device number of your thermostat. Assign the result of &amp;lt;tt&amp;gt;luup.variable_get&amp;lt;/tt&amp;gt; to a variable first, rather than putting it directly in the &amp;lt;tt&amp;gt;tonumber()&amp;lt;/tt&amp;gt;, because &amp;lt;tt&amp;gt;luup.variable_get&amp;lt;/tt&amp;gt; actually returns 2 values: the value of the variable, and the time when the variable was modified. The '&amp;lt;tt&amp;gt;tonumber&amp;lt;/tt&amp;gt;' is needed because all of a device's variables are stored as plain text--not numbers--so if you want to do arithmetic or numeric comparison of a variable, you need to put &amp;lt;tt&amp;gt;tonumber()&amp;lt;/tt&amp;gt; around &amp;lt;tt&amp;gt;luup.variable_get&amp;lt;/tt&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;luup.variable_get&amp;lt;/tt&amp;gt; is documented in [[Luup Lua extensions]]. &lt;br /&gt;
&lt;br /&gt;
Now click 'Update', and then click 'Save' to save everything. The &amp;quot;return false&amp;quot; means &amp;quot;don't run this scene&amp;quot;. So if the current temperature is &amp;amp;lt;26.6, the scene will be aborted and won't run. The timer will make it trigger every day at 12 noon. &lt;br /&gt;
&lt;br /&gt;
To test it, you can click the scene button on the dashboard. The lights will turn off only if the temperature is over 80 degrees. If it's less than 80 degrees, the scene won't do anything. Since this scene is something that happens automatically and you probably won't execute manually, you can go to the scene again and check the &amp;quot;Hidden&amp;quot; box so the scene doesn't show up on&amp;amp;nbsp;Vera's 'Dashboard' and on your remote controls, like the iPhone. If you want to have a scene that turns off the lights which you can run whenever you want from 'Dashboard''or your remote control, you should create another scene that has the same commands and simply don't add the timers and Luup conditions, and don't check the &amp;quot;Hidden&amp;quot; box. '' &lt;br /&gt;
&lt;br /&gt;
You can substitute other service/variables and device ID's to make other types of conditions. The &amp;quot;if&amp;quot; statement above also supports nesting with ( and ), as well as the keywords 'and' and 'or'. So the following means the scene would abort if the temperature is &amp;amp;lt;26.6 and &amp;amp;gt;25, unless it's &amp;amp;lt;23: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
  local lul_temp = luup.variable_get(&amp;quot;urn:upnp-org:serviceId:TemperatureSensor1&amp;quot;,&amp;quot;CurrentTemperature&amp;quot;, 3)&lt;br /&gt;
  if ((tonumber(lul_temp) &amp;lt; 26.6&lt;br /&gt;
    and tonumber(lul_temp) &amp;gt; 25)&lt;br /&gt;
    or tonumber(lul_temp) &amp;lt; 23) then&lt;br /&gt;
      return false&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/source&amp;gt; &lt;br /&gt;
&lt;br /&gt;
If the scene doesn't run, it's possible&amp;amp;nbsp;there is&amp;amp;nbsp;a syntax error. The easiest way to test this is to copy the Lua code from the scene, then go to Devices, Luup Plugins, and &amp;quot;Test Luup code&amp;quot;. Paste the code in the box and click 'go'. If the info box above the 'go' button has a check and says &amp;quot;Message sent successful&amp;quot;, your code is okay. If there's an error, it says: &amp;quot;Code failed&amp;quot;. &lt;br /&gt;
&lt;br /&gt;
To see if that's true, use putty, or telnet or ssh to log-in to Vera, as explained in detail in [[Logon_Vera_SSH]] and [[Lua Debugging]], and type: &lt;br /&gt;
&lt;br /&gt;
   cd /var/log/cmh&lt;br /&gt;
 tail -f LuaUPnP.log | grep '^01'&lt;br /&gt;
&lt;br /&gt;
Now click 'Save' in Vera's setup page, even if it's gray, as that will cause Vera to restart the Luup engine and log any syntax errors. See: [[Lua Debugging]] for in-depth details on how to debug.&lt;br /&gt;
&lt;br /&gt;
== Walk-through #2 -- Only run the scene during the daytime  ==&lt;br /&gt;
&lt;br /&gt;
In the Luup tab for the scene paste this: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
  return luup.is_night() == false&lt;br /&gt;
&amp;lt;/source&amp;gt; &lt;br /&gt;
&lt;br /&gt;
That works because if the return is 'true' the scene runs, and if it's 'false' it doesn't. So during the daytime the expression is true. Or, an alternative long form: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
  if (luup.is_night()) then&lt;br /&gt;
     return false&lt;br /&gt;
  else&lt;br /&gt;
     return true&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/source&amp;gt; &lt;br /&gt;
&lt;br /&gt;
== Samples  ==&lt;br /&gt;
&lt;br /&gt;
This page is a wiki which anyone can edit. If you have some Lua code you think other users might find useful, feel free to add it here. &lt;br /&gt;
&lt;br /&gt;
=== Lighting and Switch Actions  ===&lt;br /&gt;
&lt;br /&gt;
Did you see the sample here already: http://wiki.micasaverde.com/index.php/Luup_Scenes_Events &lt;br /&gt;
&lt;br /&gt;
==== Turn an appliance switch or a Danfoss thermostat on for device #5  ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
  luup.call_action(&amp;quot;urn:upnp-org:serviceId:SwitchPower1&amp;quot;, &amp;quot;SetTarget&amp;quot;, {newTargetValue = &amp;quot;1&amp;quot;}, 5)&lt;br /&gt;
&amp;lt;/source&amp;gt; &lt;br /&gt;
&lt;br /&gt;
==== Turn an appliance switch or a Danfoss thermostat off  ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
  luup.call_action(&amp;quot;urn:upnp-org:serviceId:SwitchPower1&amp;quot;, &amp;quot;SetTarget&amp;quot;, {newTargetValue = &amp;quot;0&amp;quot;}, 5)&lt;br /&gt;
&amp;lt;/source&amp;gt; &lt;br /&gt;
&lt;br /&gt;
==== Do something if switch device #5 is on  ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
  local lul_tmp = luup.variable_get(&amp;quot;urn:upnp-org:serviceId:SwitchPower1&amp;quot;, &amp;quot;Status&amp;quot;, 5)&lt;br /&gt;
  if (lul_tmp == &amp;quot;1&amp;quot;) then&lt;br /&gt;
     --something to do goes here&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/source&amp;gt; &lt;br /&gt;
&lt;br /&gt;
==== Dim switch #6 to 30%  ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
  luup.call_action(&amp;quot;urn:upnp-org:serviceId:Dimming1&amp;quot;, &amp;quot;SetLoadLevelTarget&amp;quot;, {newLoadlevelTarget = &amp;quot;30&amp;quot;}, 6)&lt;br /&gt;
&amp;lt;/source&amp;gt; &lt;br /&gt;
&lt;br /&gt;
==== Blinking lights (and how to delay for a number of seconds)  ====&lt;br /&gt;
&lt;br /&gt;
http://forum.micasaverde.com/index.php?topic=5127.0&lt;br /&gt;
&lt;br /&gt;
=== Motion Sensor Actions  ===&lt;br /&gt;
&lt;br /&gt;
==== Arm motion sensor #7  ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
  luup.variable_set(&amp;quot;urn:micasaverde-com:serviceId:SecuritySensor1&amp;quot;, &amp;quot;Armed&amp;quot;, &amp;quot;1&amp;quot;, 7)&lt;br /&gt;
&amp;lt;/source&amp;gt; &lt;br /&gt;
&lt;br /&gt;
==== Disarm motion sensor #7  ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
  luup.variable_set(&amp;quot;urn:micasaverde-com:serviceId:SecuritySensor1&amp;quot;, &amp;quot;Armed&amp;quot;, &amp;quot;0&amp;quot;, 7)&lt;br /&gt;
&amp;lt;/source&amp;gt; &lt;br /&gt;
&lt;br /&gt;
Note, arming and disarming isn't a concept within UPnP or Z-Wave. It's just a flag that the Luup engine uses, and is stored in a variable we created called &amp;quot;Armed&amp;quot;. &lt;br /&gt;
&lt;br /&gt;
=== Scene Actions  ===&lt;br /&gt;
&lt;br /&gt;
==== Run Scene #5  ====&lt;br /&gt;
&lt;br /&gt;
Thanks &amp;quot;denix&amp;quot; on the forum for the correct syntax. &amp;quot;Actually, the 4th parameter IS required, but it's not used. Otherwise the command fails with an error message&amp;quot; &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
  luup.call_action(&amp;quot;urn:micasaverde-com:serviceId:HomeAutomationGateway1&amp;quot;, &amp;quot;RunScene&amp;quot;, {SceneNum = &amp;quot;5&amp;quot;}, 0)&lt;br /&gt;
&amp;lt;/source&amp;gt; &lt;br /&gt;
&lt;br /&gt;
In this case we left the device number off (the 4th parameter to &amp;lt;tt&amp;gt;luup.call_action&amp;lt;/tt&amp;gt;), because the &amp;quot;&amp;lt;tt&amp;gt;RunScene&amp;lt;/tt&amp;gt;&amp;quot; action is handled by the Luup engine itself--not by some device within Z-Wave, etc. &lt;br /&gt;
&lt;br /&gt;
However, normally you don't need to &amp;lt;tt&amp;gt;luup.call_action&amp;lt;/tt&amp;gt; in Lua code. Rather, whatever actions, or commands, you want to run, you put into the scene itself, and the only Lua code is to simply check if some condition is true and abort the scene if the condition isn't met. &lt;br /&gt;
&lt;br /&gt;
=== Thermostat Actions  ===&lt;br /&gt;
&lt;br /&gt;
==== Change the Temperature on Thermostat (Cool) device #19  ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
  luup.call_action(&amp;quot;urn:upnp-org:serviceId:TemperatureSetpoint1_Cool&amp;quot;,&lt;br /&gt;
                   &amp;quot;SetCurrentSetpoint&amp;quot;, {NewCurrentSetpoint = &amp;quot;68&amp;quot;},&lt;br /&gt;
                   19)&lt;br /&gt;
&amp;lt;/source&amp;gt; &lt;br /&gt;
&lt;br /&gt;
==== Change the Temperature on a Thermostat (Heat) device #19  ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
  luup.call_action(&amp;quot;urn:upnp-org:serviceId:TemperatureSetpoint1_Heat&amp;quot;,&lt;br /&gt;
                   &amp;quot;SetCurrentSetpoint&amp;quot;, {NewCurrentSetpoint = &amp;quot;68&amp;quot;},&lt;br /&gt;
                   19)&lt;br /&gt;
&amp;lt;/source&amp;gt; &lt;br /&gt;
&lt;br /&gt;
==== Change the Thermostat Operating mode device #19  ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
luup.call_action(&amp;quot;urn:upnp-org:serviceId:HVAC_UserOperatingMode1&amp;quot;,&lt;br /&gt;
                 &amp;quot;SetModeTarget&amp;quot;, {NewModeTarget = &amp;quot;Off&amp;quot;},&lt;br /&gt;
                 19)&lt;br /&gt;
&amp;lt;/source&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt; &lt;br /&gt;
&lt;br /&gt;
=== Camera Actions  ===&lt;br /&gt;
&lt;br /&gt;
==== 'Privacy' mode for Foscam FI8908[w]  ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
  local IP_address = '&amp;lt;IP address of camera&amp;gt;'&lt;br /&gt;
  local username = '&amp;lt;username&amp;gt;'&lt;br /&gt;
  local password = '&amp;lt;password&amp;gt;'&lt;br /&gt;
  local timeout  = 5&lt;br /&gt;
 &lt;br /&gt;
  function move_up()&lt;br /&gt;
    luup.inet.wget('http://' .. IP_address .. '/decoder_control.cgi?command=0', timeout, username, password)&lt;br /&gt;
  end&lt;br /&gt;
 &lt;br /&gt;
  -- center the camera; takes some time, so we have to wait 2 minutes for the command to complete&lt;br /&gt;
 &lt;br /&gt;
  luup.inet.wget('http://' .. IP_address .. '/decoder_control.cgi?command=25', timeout, username, password)&lt;br /&gt;
 &lt;br /&gt;
  luup.call_delay('move_up', 120)&lt;br /&gt;
&amp;lt;/source&amp;gt; &lt;br /&gt;
&lt;br /&gt;
=== Misc Actions  ===&lt;br /&gt;
&lt;br /&gt;
==== Playing an announcement  ====&lt;br /&gt;
&lt;br /&gt;
http://forum.micasaverde.com/index.php?topic=5466.msg36405#msg36405 &lt;br /&gt;
&lt;br /&gt;
=== Calculate sunrise and sunset  ===&lt;br /&gt;
&lt;br /&gt;
See http://forum.micasaverde.com/index.php?topic=2073.msg8132#msg8132 &lt;br /&gt;
&lt;br /&gt;
... or use DAD: http://forum.micasaverde.com/index.php?topic=5466.0 &lt;br /&gt;
&lt;br /&gt;
=== Access the web  ===&lt;br /&gt;
&lt;br /&gt;
==== Invoke HTTP URL with &amp;lt;tt&amp;gt;GET&amp;lt;/tt&amp;gt; request (Method 1)  ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
  -- 5 Second timeout&lt;br /&gt;
  local status, result = luup.inet.wget(&amp;quot;http://www.yahoo.com&amp;quot;, 5)&lt;br /&gt;
&amp;lt;/source&amp;gt; &lt;br /&gt;
&lt;br /&gt;
==== Invoke HTTP URL with &amp;lt;tt&amp;gt;GET&amp;lt;/tt&amp;gt; request (Method 2)  ====&lt;br /&gt;
&lt;br /&gt;
Based on code by Jim/jgc94131 &amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
  require('ltn12')&lt;br /&gt;
  local http = require('socket.http')&lt;br /&gt;
&lt;br /&gt;
  -- 5 Second timeout&lt;br /&gt;
  socket.http.TIMEOUT = 5&lt;br /&gt;
&lt;br /&gt;
  local response_body = {}&lt;br /&gt;
  local request_body = ''&lt;br /&gt;
&lt;br /&gt;
  local r, c, h = socket.http.request{&lt;br /&gt;
    url = 'http://website/page?parameter1=value&amp;amp;parameter2=value',&lt;br /&gt;
    method = &amp;quot;GET&amp;quot;,&lt;br /&gt;
    port = 80,&lt;br /&gt;
    headers = {&lt;br /&gt;
      [&amp;quot;Content-Length&amp;quot;] = string.len(request_body),&lt;br /&gt;
      [&amp;quot;Content-Type&amp;quot;] = &amp;quot;application/x-www-form-urlencoded&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    source = ltn12.source.string(request_body),&lt;br /&gt;
    sink = ltn12.sink.table(response_body)&lt;br /&gt;
  }&lt;br /&gt;
&amp;lt;/source&amp;gt; &lt;br /&gt;
&lt;br /&gt;
==== Invoke HTTP URL with &amp;lt;tt&amp;gt;POST&amp;lt;/tt&amp;gt; request (Method 3)  ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
  local http = require(&amp;quot;socket.http&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
  -- 5 Second timeout&lt;br /&gt;
  http.TIMEOUT = 5&lt;br /&gt;
&lt;br /&gt;
  -- The return parameters are in a different order from luup.inet.wget(...)&lt;br /&gt;
  result, status = http.request(&amp;quot;http://192.168.0.113/runprocess.htm&amp;quot;, &amp;quot;run=run&amp;quot;)    &lt;br /&gt;
&amp;lt;/source&amp;gt; &lt;br /&gt;
&lt;br /&gt;
=== Access the current time  ===&lt;br /&gt;
&lt;br /&gt;
The Lua function &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
  os.date (format, time)&lt;br /&gt;
&amp;lt;/source&amp;gt; &lt;br /&gt;
&lt;br /&gt;
converts a time value `time` into a human readable date/time string, according to `format`. If you leave out the optional `time` parameter, it defaults to current time. The `format` parameter defaults to a fairly complete format. If you specify '*t' as the format, it will return a table instead of a formatted string. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
  t = os.date('*t')&lt;br /&gt;
  t = {year=2010, month=2, day=19, yday=50, wday=6, hour=22, min=45, sec=45, isdst=false}&lt;br /&gt;
&amp;lt;/source&amp;gt; &lt;br /&gt;
&lt;br /&gt;
The fields are year, month, day of month, day of year, day of week, hour in 24 hour clock, minutes, seconds and if it's Daylight Savings Time. &lt;br /&gt;
&lt;br /&gt;
Current hour: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
  os.date('*t').hour&lt;br /&gt;
&amp;lt;/source&amp;gt; &lt;br /&gt;
&lt;br /&gt;
Current minute: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
  os.date('*t').min&lt;br /&gt;
&amp;lt;/source&amp;gt; &lt;br /&gt;
&lt;br /&gt;
Current second: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
  os.date('*t').sec&lt;br /&gt;
&amp;lt;/source&amp;gt; &lt;br /&gt;
&lt;br /&gt;
Do something between 16:00 and 21:15: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
  local t = os.date('*t')&lt;br /&gt;
  local current_second = t.hour * 3600 + t.min * 60 + t.sec   -- number of seconds since midnight&lt;br /&gt;
  local min_time_in_seconds = 16 * 3600 +  0 * 60             -- 16:00&lt;br /&gt;
  local max_time_in_seconds = 21 * 3600 + 15 * 60             -- 21:15&lt;br /&gt;
 &lt;br /&gt;
  if (current_second &amp;gt; min_time_in_seconds) and (current_second &amp;lt; max_time_in_seconds) then&lt;br /&gt;
    -- do something&lt;br /&gt;
  else&lt;br /&gt;
    return false&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/source&amp;gt; &lt;br /&gt;
&lt;br /&gt;
See http://forum.micasaverde.com/index.php?topic=2015.0 and http://www.lua.org/manual/5.1/manual.html#5.8.&lt;br /&gt;
&lt;br /&gt;
=== Set Z-Wave parameters  ===&lt;br /&gt;
&lt;br /&gt;
See http://forum.micasaverde.com/index.php?topic=1937.msg7803#msg7803 &lt;br /&gt;
&lt;br /&gt;
=== a scene if the temperature is outside of a range  ===&lt;br /&gt;
&lt;br /&gt;
add snippets here... &lt;br /&gt;
&lt;br /&gt;
=== Reload Luup at 3 AM every day  ===&lt;br /&gt;
&lt;br /&gt;
1. Create a scene and set it to run daily at 3 AM. &lt;br /&gt;
&lt;br /&gt;
2. Add this code in the '''Luup code''' box: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;luup.call_action(&amp;quot;urn:micasaverde-com:serviceId:HomeAutomationGateway1&amp;quot;, &amp;quot;Reload&amp;quot;, {}, 0)&amp;lt;/source&amp;gt; &lt;br /&gt;
&lt;br /&gt;
3. Save.&lt;br /&gt;
&lt;br /&gt;
=== Thermostat conditioned by door/window ===&lt;br /&gt;
Turn off the thermostat if the door/window is left open for 5 minutes or more and back on if the door/window is closed for 10 minutes or more.&lt;br /&gt;
&lt;br /&gt;
'''1.''' Create a scene and set it to run when the door is opened.&lt;br /&gt;
&lt;br /&gt;
'''2.''' Add this code in the '''Luup code''' box:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
local SENSOR = 17    -- The door/window sensor device number&lt;br /&gt;
local THERMOSTAT = 3 -- The thermostat device number&lt;br /&gt;
local DELAY = 300    -- Seconds&lt;br /&gt;
&lt;br /&gt;
local SES_SID = &amp;quot;urn:micasaverde-com:serviceId:SecuritySensor1&amp;quot;&lt;br /&gt;
local HVACO_SID = &amp;quot;urn:upnp-org:serviceId:HVAC_UserOperatingMode1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
luup.call_delay( &amp;quot;turnOffAc&amp;quot;, DELAY)&lt;br /&gt;
&lt;br /&gt;
-- Turn off the thermostat if the sensor has been tripped for at least 5 minutes.&lt;br /&gt;
function turnOffAc()&lt;br /&gt;
    local tripped = luup.variable_get( SES_SID, &amp;quot;Tripped&amp;quot;, SENSOR) or &amp;quot;0&amp;quot;&lt;br /&gt;
    local lastTrip = luup.variable_get( SES_SID, &amp;quot;LastTrip&amp;quot;, SENSOR) or os.time()&lt;br /&gt;
    if (tripped == &amp;quot;1&amp;quot; and (os.time() - lastTrip &amp;gt;= DELAY)) then&lt;br /&gt;
        local modeStatus = luup.variable_get( HVACO_SID, &amp;quot;ModeStatus&amp;quot;, THERMOSTAT) or &amp;quot;Off&amp;quot;&lt;br /&gt;
        luup.variable_set( HVACO_SID, &amp;quot;LastModeStatus&amp;quot;, modeStatus, THERMOSTAT)&lt;br /&gt;
        luup.call_action( HVACO_SID, &amp;quot;SetModeTarget&amp;quot;, {NewModeTarget = &amp;quot;Off&amp;quot;}, THERMOSTAT)&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''3.''' Create another scene and set it to run when the door is closed.&lt;br /&gt;
&lt;br /&gt;
'''4.''' Add this code in the '''Luup code''' box:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
local SENSOR = 17    -- The door/window sensor device number&lt;br /&gt;
local THERMOSTAT = 3 -- The thermostat device number&lt;br /&gt;
local DELAY = 600    -- Seconds&lt;br /&gt;
&lt;br /&gt;
local SES_SID = &amp;quot;urn:micasaverde-com:serviceId:SecuritySensor1&amp;quot;&lt;br /&gt;
local HVACO_SID = &amp;quot;urn:upnp-org:serviceId:HVAC_UserOperatingMode1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
luup.call_delay( &amp;quot;turnOnAc&amp;quot;, DELAY)&lt;br /&gt;
&lt;br /&gt;
-- Turn on the thermostat if the sensor hasn't been tripped in the past 10 minutes.&lt;br /&gt;
function turnOnAc()&lt;br /&gt;
    local tripped = luup.variable_get( SES_SID, &amp;quot;Tripped&amp;quot;, DOOR_SENSOR) or &amp;quot;0&amp;quot;&lt;br /&gt;
    local lastTrip = luup.variable_get( SES_SID, &amp;quot;LastTrip&amp;quot;, DOOR_SENSOR) or os.time()&lt;br /&gt;
    if (tripped == &amp;quot;0&amp;quot; and (os.time() - lastTrip &amp;gt;= DELAY)) then&lt;br /&gt;
        local lastModeStatus = luup.variable_get( HVACO_SID, &amp;quot;LastModeStatus&amp;quot;, THERMOSTAT) or &amp;quot;Off&amp;quot;&lt;br /&gt;
        luup.call_action( HVACO_SID, &amp;quot;SetModeTarget&amp;quot;, {NewModeTarget = lastModeStatus}, THERMOSTAT)&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''5.''' Save.&lt;br /&gt;
&lt;br /&gt;
[[Category:Development]]&lt;/div&gt;</summary>
		<author><name>Solipsia</name></author>	</entry>

	<entry>
		<id>http://wiki.mios.com/index.php/ExpressControls3in1</id>
		<title>ExpressControls3in1</title>
		<link rel="alternate" type="text/html" href="http://wiki.mios.com/index.php/ExpressControls3in1"/>
				<updated>2012-09-08T13:28:53Z</updated>
		
		<summary type="html">&lt;p&gt;Solipsia: /* Configure */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;br&amp;gt; &lt;br /&gt;
&lt;br /&gt;
== Overview  ==&lt;br /&gt;
&lt;br /&gt;
The EZMotion Wireless 3-in-1 sensor is functionally identical to the HomeSeer HSM100 device. The user's manual is here: http://www.expresscontrols.com/pdf/EZMotionOwnerManual.pdf &lt;br /&gt;
&lt;br /&gt;
=== Features  ===&lt;br /&gt;
&lt;br /&gt;
This unit is a contains three sensors that report values to the Vera: &lt;br /&gt;
&lt;br /&gt;
*'''Motion Sensor''' with adjustable sensitivity and timeout &lt;br /&gt;
*'''Temperature Sensor''' &lt;br /&gt;
*'''Luminosity (Light Level) Sensor''' reporting level of light as a percentage between the brightest and darkest levels it has encountered since being switched on for the first time&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt; The temperature and light levels are reported when the device wakes up and reports back to Vera, but the motion sensor will report automatically whenever it has been tripped, wether the device is sleeping or not.&amp;lt;br&amp;gt; The unit has a red LED which indicates when motion is detected and it can be disabled. It can also report its battery level as a percentage to the Vera.&amp;lt;br&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt; &lt;br /&gt;
&lt;br /&gt;
== Basic Configuration  ==&lt;br /&gt;
&lt;br /&gt;
For more information about Device Options, please visit:&amp;lt;br&amp;gt; &lt;br /&gt;
&lt;br /&gt;
[http://docs5.mios.com/doc.php?language=1&amp;amp;manual=1&amp;amp;platform=3Pro&amp;amp;page=add_device_zwave_properties_dev_option http://docs5.mios.com/doc.php?language=1&amp;amp;amp;manual=1&amp;amp;amp;platform=3Pro&amp;amp;amp;page=add_device_zwave_properties_dev_option]&amp;lt;br&amp;gt; &lt;br /&gt;
&lt;br /&gt;
=== Wake Up interval  ===&lt;br /&gt;
&lt;br /&gt;
The unit sleeps for the duration of the Wake Up interval, which defaults to 1800 seconds or 30 minutes. When the interval expires, it wakes up and reports Temperature and Luminosity to the Vera. Note that while all 4 devices in the Vera MIOS screen can be configured for Wake Up intervals, only the setting for the '3-in-1 Sensor' has any effect and controls both Temperature and Luminosity intervals. The Motion Sensor is unaffected by the Wakeup Interval (see On Time below) &lt;br /&gt;
&lt;br /&gt;
To set the Wake Up Interval, click on the spanner (wrench) icon for the &amp;quot;3-in-1 sensor&amp;quot; device, click on Setting and set Wakeup Interval to the desired interval (in seconds, e.g. 1800(seconds) = 30 min before the sensor wakes up again). Reducing the wake up interval (causing the sensor to transmit radio signals more often) reduces battery life. &lt;br /&gt;
&lt;br /&gt;
=== On Time  ===&lt;br /&gt;
&lt;br /&gt;
When the Motion Sensor is tripped, it transmits a tripped command and changes its state to Tripped=1 for the duration of the ON TIME variable. After this time has expired, it sends an Untripped command to the Vera and resets it state to Tripped=0. While the device is in a tripped state, any motion detected resets the interval timer but doesn't report a new trip event to the Vera. During the wait time the Motion Sensor device in the Vera will show Tripped=1 in the Advanced tab. &lt;br /&gt;
&lt;br /&gt;
To set the ON TIME, click on the spanner (wrench) icon for the &amp;quot;3-in-1 sensor&amp;quot; device, click on Device Options and set variable 2 (On Time) to 5 (or the desired interval in minutes) &lt;br /&gt;
&lt;br /&gt;
'''Direct Association:''' The unit can be associated directly with another device such as a light. If you've done this, the unit will turn the light on when motion is sensed, then turn it off after the ON TIME. According to the sensor's manual up to four associated devices are supported, but associating more than one device does not work (as of Vera's firmware 1.0.900, see http://bugs.micasaverde.com/view.php?id=705). &lt;br /&gt;
&lt;br /&gt;
Leave Parameter #6, &amp;quot;OnValue&amp;quot;, at the default if you want the sensor tripped events in Vera. &lt;br /&gt;
&lt;br /&gt;
=== Polling Frequency  ===&lt;br /&gt;
&lt;br /&gt;
The unit can only be polled when it is either in Test mode or within 3 seconds after waking up (see Wake Up Interval above). Polling at any other time will fail since the unit will not respond. Also, every time the unit wakes up, it updates Vera with the temperature and luminosity. This means that polling is unnecessary and the polling frequency should be set to 0 (disabled) or a long interval to avoid unnecessary traffic on Vera, which could cause updates to be missed. &lt;br /&gt;
&lt;br /&gt;
An exception to this rule is when Vera is set to Always Awake (see AC Power below). In that case, the unit is always awake, so never reports its values (which happens at wake-up) and must be polled at regular intervals. &lt;br /&gt;
&lt;br /&gt;
=== Example  ===&lt;br /&gt;
&lt;br /&gt;
Consider the following example of how to configure the sensor and the Vera for a common application. Suppose you want to install a motion sensor in your garage to turn the lights on when you enter, keep them on for as long as you move around in the garage, then turn them off 5 minutes after you've left. &lt;br /&gt;
&lt;br /&gt;
'''&amp;lt;u&amp;gt;UI4&amp;lt;/u&amp;gt;'''&amp;lt;br&amp;gt; &lt;br /&gt;
&lt;br /&gt;
#Put the unit in Test mode by pressing the button on the side &lt;br /&gt;
#Configure the On Time to 5 minutes &lt;br /&gt;
#Create two scenes in Vera: &lt;br /&gt;
##Turn on the light when the unit has tripped (New Scene, Events tab, Add Event, Device=Motion sensor, Type of Event=Armed sensor has tripped, Name=whatever, Tripped=Yes) &lt;br /&gt;
##Turn off the light when the unit sends an untrip command which happens after the On Time interval. (New Scene, Events tab, Add Event, Device=Motion sensor, Type of Event=Armed sensor has tripped, Name=whatever, Tripped=No)&lt;br /&gt;
&lt;br /&gt;
'''&amp;lt;u&amp;gt;UI5&amp;lt;/u&amp;gt;'''&amp;lt;br&amp;gt; &lt;br /&gt;
&lt;br /&gt;
#Put the unit in Test mode by pressing the button on the side &lt;br /&gt;
#Configure the On Time to 5 minutes &lt;br /&gt;
#Create two scenes in Vera: &lt;br /&gt;
##Turn on the light when the unit has tripped (Automation -&amp;amp;gt; Create Scene, Triggers tab, Add trigger, Device=Motion sensor, What type of event is the trigger?=An armed sensor is tripped, Name for this trigger=whatever, Device armed is tripped) &lt;br /&gt;
##Turn off the light when the unit sends an untrip command which happens after the On Time interval. (Automation -&amp;amp;gt; Create Scene, Triggers tab, Add trigger, Device=Motion sensor, What type of event is the trigger?=An armed sensor is tripped, Name for this trigger=whatever, Device armed is not tripped)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt; &lt;br /&gt;
&lt;br /&gt;
== Advanced Configuration  ==&lt;br /&gt;
&lt;br /&gt;
=== Running from AC Power  ===&lt;br /&gt;
&lt;br /&gt;
==== Overview  ====&lt;br /&gt;
&lt;br /&gt;
It is possible to run the unit from AC power instead of batteries, which will have the following benefits: &lt;br /&gt;
&lt;br /&gt;
*Allow you to keep the unit awake permanently, allowing you to poll it and customise it without being in Test mode &lt;br /&gt;
*Report continuously every time motion is sensed, as opposed to waiting for the ON TIME duration in between trips &lt;br /&gt;
*Set the unit to report temperature and light levels at higher frequencies up to 1 minute &lt;br /&gt;
*Let the unit act as a Z-Wave repeater, increasing the span of your network &lt;br /&gt;
*Never worry about running down batteries. All of the above options are possible on battery power, but will run your batteries down within a few days&lt;br /&gt;
&lt;br /&gt;
==== Configure  ====&lt;br /&gt;
&lt;br /&gt;
To do this, you will need to connect a AC to DC transformer that supplies 4.5v to 5.5v at up to 1amp to the battery terminals directly. Ensure that you measure that actual output voltage of the transformer using a multi/voltage meter (don't rely on its advertised rating). Any over-voltage may fry the unit. Also make sure that the polarity is correct. It may be helpful to add a diode in series with the positive terminal to prevent accidentally frying the unit if the polarity is incorrect. It will drop the voltage by 0.6v though. &lt;br /&gt;
&lt;br /&gt;
'''Setting ''Stay Awake'' to On''' By default, the unit is constantly asleep and only wakes up at regular intervals to report the luminosity and temperature, before sleeping again. This is to save batteries. While asleep, the unit cannot be programmed from the Vera and cannot be polled for information. To get around this, one normally activates the Test mode by pressing the button on the side of the unit, which keeps it awake for 10 minutes so that it can be programmed. By setting the unit to stay awake constantly, you can program, poll or configure it at any time. It also has the side effect of enabling the unit to become a repeater of Z Wave signals throughout the network. &lt;br /&gt;
&lt;br /&gt;
To set it, click on the spanner (wrench) icon for the &amp;quot;3-in-1 sensor&amp;quot; device, click on Device Options and set variable 5 (Stay Awake) to 1 or any number greater than 0. &lt;br /&gt;
&lt;br /&gt;
To activate this setting, you will need to power off and power back on the device. Remember to save your settings first. &lt;br /&gt;
&lt;br /&gt;
'''Setting ''On Time'' to ''Always Fire''''' When the unit detects motion, it reports it by sending a Tripped command to the Vera. It then waits for the duration of the On Time and then sends un Untripped command to the Vera and waits for the next motion. Since battery life is not a consideration while on AC power, you can set it to 'Always Fire', which sends a Tripped command whenever motion is detected with no waiting period. Note, this will also prevent an Untripped command from being sent. &lt;br /&gt;
&lt;br /&gt;
To set it, click on the spanner (wrench) icon for the &amp;quot;3-in-1 sensor&amp;quot; device, click on Device Options and set variable 2 (On Time) to 0. &lt;br /&gt;
&lt;br /&gt;
'''Setting Poll frequency''' The unit usually only reports temperate and luminosity every time it wakes up, but since the unit is now constantly awake, you will have to configure a poll frequency to gather that information. &lt;br /&gt;
&lt;br /&gt;
To set it, click on the spanner (wrench) icon for the &amp;quot;Motion Sensor&amp;quot; device, click on Settings and set &amp;quot;Poll this node at most every&amp;quot; to the required update frequency. The Wakeup interval setting on this same screen has no effect since it's been overridden by Always Awake setting.&lt;br /&gt;
&lt;br /&gt;
== Known issues  ==&lt;br /&gt;
&lt;br /&gt;
[[Category:Hardware]] [[Category:Plugins]] [[Category:3rd_Party]]&lt;/div&gt;</summary>
		<author><name>Solipsia</name></author>	</entry>

	<entry>
		<id>http://wiki.mios.com/index.php/ExpressControls3in1</id>
		<title>ExpressControls3in1</title>
		<link rel="alternate" type="text/html" href="http://wiki.mios.com/index.php/ExpressControls3in1"/>
				<updated>2011-02-21T14:14:09Z</updated>
		
		<summary type="html">&lt;p&gt;Solipsia: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Hardware]]&lt;br /&gt;
[[Category:Plugins]]&lt;br /&gt;
[[Category:3rd Party]]&lt;br /&gt;
&lt;br /&gt;
== Overview ==&lt;br /&gt;
The EZMotion Wireless 3-in-1 sensor is functionally identical to the HomeSeer HSM100 device. The user's manual is here: http://www.expresscontrols.com/pdf/EZMotionOwnerManual.pdf &lt;br /&gt;
&lt;br /&gt;
=== Features ===&lt;br /&gt;
&lt;br /&gt;
This unit is a contains three sensors that report values to the Vera:&lt;br /&gt;
* '''Motion Sensor''' with adjustable sensitivity and timeout&lt;br /&gt;
* '''Temperature Sensor'''&lt;br /&gt;
* '''Luminosity (Light Level) Sensor''' reporting level of light as a percentage between the brightest and darkest levels it has encountered since being switched on for the first time&lt;br /&gt;
&lt;br /&gt;
The unit has a red LED which indicates when motion is detected and it can be disabled. It can also report its battery level as a percentage to the Vera.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Basic Configuration ==&lt;br /&gt;
=== Wake Up interval ===&lt;br /&gt;
The unit sleeps for the duration of the Wake Up interval, which defaults to 1800 seconds or 30 minutes. When the interval expires, it wakes up and reports Temperature and Luminosity to the Vera. Note that while all 4 devices in the Vera MIOS screen can be configured for Wake Up intervals, only the setting for the '3-in-1 Sensor' has any effect and controls both Temperature and Luminosity intervals. The Motion Sensor is unaffected by the Wakeup Interval (see On Time below)&lt;br /&gt;
&lt;br /&gt;
To set the Wake Up Interval, click on the spanner (wrench) icon for the &amp;quot;3-in-1 sensor&amp;quot; device, click on Setting and set Wakeup Interval to the desired interval.&lt;br /&gt;
&lt;br /&gt;
=== On Time ===&lt;br /&gt;
When the Motion Sensor is tripped, it transmits a tripped command and changes its state to Tripped=1 for the duration of the ON TIME variable. After this time has expired, it sends an Untripped command to the Vera and resets it state to Tripped=0. While the device is in a tripped state, any motion detected resets the interval timer but doesn't report a new trip event to the Vera. During the wait time the Motion Sensor device in the Vera will show Tripped=1 in the Advanced tab.&lt;br /&gt;
&lt;br /&gt;
To set the ON TIME, click on the spanner (wrench) icon for the &amp;quot;3-in-1 sensor&amp;quot; device, click on Device Options and set variable 2 (On Time) to 5 (or the desired interval in minutes)&lt;br /&gt;
&lt;br /&gt;
'''Direct Association:''' The unit can be associated directly with another device such as a light. If you've done this, the unit will turn the light on when motion is sensed, then turn it off after the ON TIME. According to the sensor's manual up to four associated devices are supported, but associating more than one device does not work (as of Vera's firmware 1.0.900, see http://bugs.micasaverde.com/view.php?id=705).&lt;br /&gt;
&lt;br /&gt;
Leave Parameter #6, &amp;quot;OnValue&amp;quot;, at the default if you want the sensor tripped events in Vera.&lt;br /&gt;
&lt;br /&gt;
=== Polling Frequency ===&lt;br /&gt;
The unit can only be polled when it is either in Test mode or within 3 seconds after waking up (see Wake Up Interval above). Polling at any other time will fail since the unit will not respond. Also, every time the unit wakes up, it updates Vera with the temperature and luminosity. This means that polling is unnecessary and the polling frequency should be set to 0 (disabled) or a long interval to avoid unnecessary traffic on Vera, which could cause updates to be missed.&lt;br /&gt;
&lt;br /&gt;
An exception to this rule is when Vera is set to Always Awake (see AC Power below). In that case, the unit is always awake, so never reports its values (which happens at wake-up) and must be polled at regular intervals.&lt;br /&gt;
&lt;br /&gt;
=== Example ===&lt;br /&gt;
Consider the following example of how to configure the sensor and the Vera for a common application. Suppose you want to install a motion sensor in your garage to turn the lights on when you enter, keep them on for as long as you move around in the garage, then turn them off 5 minutes after you've left. &lt;br /&gt;
# Put the unit in Test mode by pressing the button on the side&lt;br /&gt;
# Configure the On Time to 5 minutes&lt;br /&gt;
# Create two scenes in Vera:&lt;br /&gt;
## Turn on the light when the unit has tripped (New Scene, Events tab, Add Event, Device=Motion sensor, Type of Event=Armed sensor has tripped, Name=whatever, Tripped=Yes)&lt;br /&gt;
## Turn off the light when the unit sends an untrip command which happens after the On Time interval. (New Scene, Events tab, Add Event, Device=Motion sensor, Type of Event=Armed sensor has tripped, Name=whatever, Tripped=No)&lt;br /&gt;
&lt;br /&gt;
== Advanced Configuration ==&lt;br /&gt;
=== Running from AC Power ===&lt;br /&gt;
==== Overview ====&lt;br /&gt;
It is possible to run the unit from AC power instead of batteries, which will have the following benefits:&lt;br /&gt;
* Allow you to keep the unit awake permanently, allowing you to poll it and customise it without being in Test mode&lt;br /&gt;
* Report continuously every time motion is sensed, as opposed to waiting for the ON TIME duration in between trips&lt;br /&gt;
* Set the unit to report temperature and light levels at higher frequencies up to 1 minute&lt;br /&gt;
* Let the unit act as a Z-Wave repeater, increasing the span of your network&lt;br /&gt;
* Never worry about running down batteries. All of the above options are possible on battery power, but will run your batteries down within a few days&lt;br /&gt;
==== Configure ====&lt;br /&gt;
To do this, you will need to connect a AC to DC transformer that supplies 4.5v to 5.5v at up to 1amp to the battery terminals directly. Ensure that you measure that actual output voltage of the transformer using a multi/voltage meter (don't rely on its advertised rating). Any over-voltage may fry the unit. Also make sure that the polarity is correct. It may be helpful to add a diode in series with the positive terminal to prevent accidentally frying the unit if the polarity is incorrect. It will drop the voltage by 0.6v though. &lt;br /&gt;
&lt;br /&gt;
'''Setting ''Stay Awake'' to On'''&lt;br /&gt;
By default, the unit is constantly asleep and only wakes up at regular intervals to report the luminosity and temperature, before sleeping again. This is to save batteries. While asleep, the unit cannot be programmed from the Vera and cannot be polled for information. To get around this, one normally activates the Test mode by pressing the button on the side of the unit, which keeps it awake for 10 minutes so that it can be programmed. By setting the unit to stay awake constantly, you can program, poll or configure it at any time. It also has the side effect of enabling the unit to become a repeater of Z Wave signals throughout the network.&lt;br /&gt;
&lt;br /&gt;
To set it, click on the spanner (wrench) icon for the &amp;quot;3-in-1 sensor&amp;quot; device, click on Device Options and set variable 5 (Stay Awake) to 1 or any number greater than 0.&lt;br /&gt;
&lt;br /&gt;
To activate this setting, you will need to exclude and reinclude the unit using the standard Vera process. Remember to save your settings first.  &lt;br /&gt;
&lt;br /&gt;
'''Setting ''On Time'' to ''Always Fire'''''&lt;br /&gt;
When the unit detects motion, it reports it by sending a Tripped command to the Vera. It then waits for the duration of the On Time and then sends un Untripped command to the Vera and waits for the next motion. Since battery life is not a consideration while on AC power, you can set it to 'Always Fire', which sends a Tripped command whenever motion is detected with no waiting period. Note, this will also prevent an Untripped command from being sent.&lt;br /&gt;
&lt;br /&gt;
To set it, click on the spanner (wrench) icon for the &amp;quot;3-in-1 sensor&amp;quot; device, click on Device Options and set variable 2 (On Time) to 0.&lt;br /&gt;
&lt;br /&gt;
''' Setting Poll frequency'''&lt;br /&gt;
The unit usually only reports temperate and luminosity every time it wakes up, but since the unit is now constantly awake, you will have to configure a poll frequency to gather that information.&lt;br /&gt;
&lt;br /&gt;
To set it, click on the spanner (wrench) icon for the &amp;quot;Motion Sensor&amp;quot; device, click on Settings and set &amp;quot;Poll this node at most every&amp;quot; to the required update frequency. The Wakeup interval setting on this same screen has no effect since it's been overridden by Always Awake setting.&lt;br /&gt;
&lt;br /&gt;
== Known issues ==&lt;/div&gt;</summary>
		<author><name>Solipsia</name></author>	</entry>

	<entry>
		<id>http://wiki.mios.com/index.php/Luup_Scenes_Events</id>
		<title>Luup Scenes Events</title>
		<link rel="alternate" type="text/html" href="http://wiki.mios.com/index.php/Luup_Scenes_Events"/>
				<updated>2011-02-20T18:03:33Z</updated>
		
		<summary type="html">&lt;p&gt;Solipsia: Added flowchart&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Development]]&lt;br /&gt;
== Adding Lua code to scenes and events ==&lt;br /&gt;
[[Image:SceneFlowchart.png]]&lt;br /&gt;
&lt;br /&gt;
You can add Lua script to scenes and events for simple tasks, like making a scene or event conditional.  Conditional meaning &amp;quot;do something only '''if''' some condition is met&amp;quot;, such as attaching a condition to your &amp;quot;Come Home&amp;quot; scene so it is only run '''if''' the temperature is over 70 degrees.  Basic conditional expressions are easy, and, if that's all you're looking to do, skip to the walk-through below.&lt;br /&gt;
&lt;br /&gt;
If you're more technically inclined you can also do very advanced things too.  For an overview of all the advanced things you can do with Vera's Luup engine, and how scenes and events fit in, see the [[Luup_Intro]] page.&lt;br /&gt;
&lt;br /&gt;
To add Lua code to a scene, create the [[Scenes]] and click 'Luup scene'.  Fill in your Lua code in the input box.  To do a simple condition, see the sample below.  Or if you want to do advanced scripting you can use any [[http://lua.org Lua]] commands as described in the [[http://www.lua.org/manual/5.1/ Lua reference manual]] as well as the variables and functions that the Luup engine adds to Lua documented here: [[Luup_Lua_extensions]].  The Lua code will be run every time the scene is activated either by the user or a scene or a timer.  The Lua code is run before the commands that you included in the scene.  If your Lua code ends with this: &amp;quot;return false&amp;quot; then the commands in the scene will not be run.&lt;br /&gt;
&lt;br /&gt;
You can also add Lua code to an event by clicking 'Luup event'.  Since events are attached to scenes anyway, there is usually little difference between adding the code to an event, or to the scene the event is part of.  If the Lua code in an event returns false, then the event is aborted, meaning the scene that the event is attached to will not be triggered by the event.  The main reason for attaching Lua code to an event is if you have multiple events to a scene.  For example, you may have a scene called &amp;quot;Turn lights on in hallway&amp;quot; which is triggered by 2 events: 1) The front door opens, and 2) the motion sensor in the hallway is tripped.  Perhaps whenever the front door opens you always want the scene to be activated, but you only want the motion sensor to activate the scene before 10:00.  In this case, you would add Lua code to the motion sensor's event which does something like (pseudo-code): &amp;quot;if time&amp;gt;10:00 return false&amp;quot;.  That way the event from the motion sensor will be aborted if it's after 10:00, but the event from the front door will always activate the scene regardless.&lt;br /&gt;
&lt;br /&gt;
When you edit the Lua code in a scene or event you must click 'Save' before the code is saved.  Then you can activate the scene or trigger the event to see what happens when your code is run.  If you're doing some advanced scripting that you'll need to debug this can be tedious, but there are easy ways to test your Lua script immediately without saving first as explained in [[Lua_Debugging]].&lt;br /&gt;
&lt;br /&gt;
If you're doing advanced Lua scripting, you should note that all the Lua code in your scenes and events run in a single Lua instance, which is separate from any Lua plugins.  This means if you set a global variable in one scene, or create a function inside the Lua code in a scene, then in another scene's Lua code you can use that global variable or call that function.  You do not need to worry about conflicting with a Luup plugin, though, since they have their own Lua instance, meaning they have their own global variables and functions.&lt;br /&gt;
&lt;br /&gt;
== Walk-through #1 -- At 12 noon, turn off the interior lights if the temperature is over 80 degrees  ==&lt;br /&gt;
&lt;br /&gt;
Before you start, in Vera's setup interface go to 'Devices' and click the '+' button next to the thermostat. Make note of the Device #. &lt;br /&gt;
&lt;br /&gt;
In this walkthrough we'll assume it's Device #3, but use the actual device number of''your'' thermostat. Next, visit [[Luup Variables]] to get a list of all the variables for devices. A variable is a piece of information about the current state of a device, such as whether it's on or off, it's current temperature, etc. &lt;br /&gt;
&lt;br /&gt;
Look down at ''Thermostat'', and copy the name of the service/variable which corresponds to the current temperature, namely.  In this case, it's&lt;br /&gt;
&lt;br /&gt;
  urn:upnp-org:serviceId:TemperatureSensor1 CurrentTemperature&lt;br /&gt;
&lt;br /&gt;
Notice that it states the &amp;lt;tt&amp;gt;CurrentTemperature&amp;lt;/tt&amp;gt; is in Celsius. So type in &amp;quot;80 degrees Fahrenheit to Celsius&amp;quot; in Google and you'll see that it's 26.6 degrees Celsius. &lt;br /&gt;
&lt;br /&gt;
Now, the first step is to create the scene that turns off the lights. In Vera's setup interface, click 'Scenes', and click 'Add Scene' to add a new scene to one of the rooms. It's not important which room you choose. Scenes are categorized in rooms just to help you keep track of them if you have a lot of scenes. You can also put the scene in 'Global Scenes', or, you can create dummy rooms on the 'Rooms' tab if you want to have more &amp;quot;rooms&amp;quot; to organize your scenes with. After you click 'Add Scene', type in a description to remember your scene by, such as &amp;quot;Lights off 12:00 if 80&amp;quot;. Under the 'Commands' area you'll see all the rooms. Click '+' next to the rooms that have lights you want to control, and choose &amp;quot;Off&amp;quot; in the pull-down. At this point, you have a normal scene, and, if you were to save your changes now, whenever you click the scene on the dashboard or on a remote control, the lights should turn off. &lt;br /&gt;
&lt;br /&gt;
Second, next to the scene's description click 'add timer'. You can give the timer a description too so that if you have multiple timers you can see in the logs which one is activating the scene. Choose &amp;quot;Day of week based&amp;quot;. If you want this scene to only run on certain days of the week, just check off which days you want this scene to run on. Otherwise, you can leave them all unchecked (or check them all) to do it every day. Leave the pull-down at &amp;quot;a certain time of day&amp;quot;, and choose 12&amp;amp;nbsp;: 00&amp;amp;nbsp;: 00 from the pull-downs. At this point, if you were to save your changes, the lights would turn off automatically at 12 noon. &lt;br /&gt;
&lt;br /&gt;
Third, the last step is to add the condition. To the right of the scene's description you'll see the button &amp;quot;Luup Scene&amp;quot;. Click it and in the code box, copy and paste the following: &lt;br /&gt;
&lt;br /&gt;
  local lul_temp=luup.variable_get(&amp;quot;urn:upnp-org:serviceId:TemperatureSensor1&amp;quot;,&amp;quot;CurrentTemperature&amp;quot;,3)&lt;br /&gt;
  if( tonumber(lul_temp)&amp;amp;lt;26.6 ) then&lt;br /&gt;
    return false&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
Don't forget to change the &amp;quot;3&amp;quot; to whatever is the actual device number of your thermostat. Assign the result of &amp;lt;tt&amp;gt;luup.variable_get&amp;lt;/tt&amp;gt; to a variable first, rather than putting it directly in the &amp;lt;tt&amp;gt;tonumber()&amp;lt;/tt&amp;gt;, because &amp;lt;tt&amp;gt;luup.variable_get&amp;lt;/tt&amp;gt; actually returns 2 values: the value of the variable, and the time when the variable was modified. The '&amp;lt;tt&amp;gt;tonumber&amp;lt;/tt&amp;gt;' is needed because all of a device's variables are stored as plain text--not numbers--so if you want to do arithmetic or numeric comparison of a variable, you need to put &amp;lt;tt&amp;gt;tonumber()&amp;lt;/tt&amp;gt; around &amp;lt;tt&amp;gt;luup.variable_get&amp;lt;/tt&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;luup.variable_get&amp;lt;/tt&amp;gt; is documented in [[Luup Lua extensions]]. &lt;br /&gt;
&lt;br /&gt;
Now click 'Update', and then click 'Save' to save everything. The &amp;quot;return false&amp;quot; means &amp;quot;don't run this scene&amp;quot;. So if the current temperature is &amp;amp;lt;26.6, the scene will be aborted and won't run. The timer will make it trigger every day at 12 noon. &lt;br /&gt;
&lt;br /&gt;
To test it, you can click the scene button on the dashboard. The lights will turn off only if the temperature is over 80 degrees. If it's less than 80 degrees, the scene won't do anything. Since this scene is something that happens automatically and you probably won't execute manually, you can go to the scene again and check the &amp;quot;Hidden&amp;quot; box so the scene doesn't show up on&amp;amp;nbsp;Vera's 'Dashboard' and on your remote controls, like the iPhone. If you want to have a scene that turns off the lights which you can run whenever you want from 'Dashboard'' or your remote control, you should create another scene that has the same commands and simply don't add the timers and Luup conditions, and don't check the &amp;quot;Hidden&amp;quot; box. &lt;br /&gt;
&lt;br /&gt;
You can substitute other service/variables and device ID's to make other types of conditions. The &amp;quot;if&amp;quot; statement above also supports nesting with ( and ), as well as the keywords 'and' and 'or'. So the following means the scene would abort if the temperature is &amp;amp;lt;26.6 and &amp;amp;gt;25, unless it's &amp;amp;lt;23: &lt;br /&gt;
&lt;br /&gt;
  local lul_temp=luup.variable_get(&amp;quot;urn:upnp-org:serviceId:TemperatureSensor1&amp;quot;,&amp;quot;CurrentTemperature&amp;quot;,3)&lt;br /&gt;
  if( (tonumber(lul_temp)&amp;amp;lt;26.6&lt;br /&gt;
    and tonumber(lul_temp)&amp;amp;gt;25)&lt;br /&gt;
    or tonumber(lul_temp)&amp;amp;lt;23 ) then&lt;br /&gt;
      return false&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
If the scene doesn't run, it's possible&amp;amp;nbsp;there is&amp;amp;nbsp;a syntax error. The easiest way to test this is to copy the Lua code from the scene, then go to Devices, Luup Plugins, and &amp;quot;Test Luup code&amp;quot;. Paste the code in the box and click 'go'. If the info box above the 'go' button has a check and says &amp;quot;Message sent successful&amp;quot;, your code is okay. If there's an error, it says: &amp;quot;Code failed&amp;quot;. &lt;br /&gt;
&lt;br /&gt;
To see if that's true, use putty, or telnet or ssh to log-in to Vera, as explained in detail in [[Lua Debugging]], and type: &lt;br /&gt;
&lt;br /&gt;
   cd /var/log/cmh&lt;br /&gt;
   tail -f LuaUPnP.log | grep '^01'&lt;br /&gt;
&lt;br /&gt;
Now click 'Save' in Vera's setup page, even if it's gray, as that will cause Vera to restart the Luup engine and log any syntax errors. See: [[Lua Debugging]] for in-depth details on how to debug.&lt;br /&gt;
&lt;br /&gt;
== Samples ==&lt;br /&gt;
&lt;br /&gt;
This page is a wiki which anyone can edit.  If you have some Lua code you think other users might find useful, feel free to add it here.&lt;br /&gt;
&lt;br /&gt;
=== Misc actions ===&lt;br /&gt;
&lt;br /&gt;
Did you see the sample here already: http://wiki.micasaverde.com/index.php/Luup_Scenes_Events&lt;br /&gt;
&lt;br /&gt;
====Turn an appliance switch or a Danfoss thermostat on for device #5====&lt;br /&gt;
&lt;br /&gt;
  luup.call_action(&amp;quot;urn:upnp-org:serviceId:SwitchPower1&amp;quot;,&amp;quot;SetTarget&amp;quot;,{ newTargetValue=&amp;quot;1&amp;quot; },5)&lt;br /&gt;
&lt;br /&gt;
====Turn an appliance switch or a Danfoss thermostat off====&lt;br /&gt;
&lt;br /&gt;
  luup.call_action(&amp;quot;urn:upnp-org:serviceId:SwitchPower1&amp;quot;,&amp;quot;SetTarget&amp;quot;,{ newTargetValue=&amp;quot;0&amp;quot; },5)&lt;br /&gt;
&lt;br /&gt;
====Do something if switch device #5 is on====&lt;br /&gt;
&lt;br /&gt;
  local lul_tmp = luup.variable_get(&amp;quot;urn:upnp-org:serviceId:SwitchPower1&amp;quot;,&amp;quot;Status&amp;quot;,5)&lt;br /&gt;
  if( lul_tmp==&amp;quot;1&amp;quot; ) then&lt;br /&gt;
     --something to do goes here&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
====Dim switch #6 to 30%====&lt;br /&gt;
&lt;br /&gt;
  luup.call_action(&amp;quot;urn:upnp-org:serviceId:Dimming1&amp;quot;,&amp;quot;SetLoadLevelTarget&amp;quot;,{ newLoadlevelTarget=&amp;quot;30&amp;quot; },6)&lt;br /&gt;
&lt;br /&gt;
====Arm motion sensor #7====&lt;br /&gt;
&lt;br /&gt;
  luup.variable_set(&amp;quot;urn:micasaverde-com:serviceId:SecuritySensor1&amp;quot;,&amp;quot;Armed&amp;quot;,&amp;quot;1&amp;quot;,7)&lt;br /&gt;
&lt;br /&gt;
====Disarm motion sensor #7====&lt;br /&gt;
&lt;br /&gt;
  luup.variable_set(&amp;quot;urn:micasaverde-com:serviceId:SecuritySensor1&amp;quot;,&amp;quot;Armed&amp;quot;,&amp;quot;0&amp;quot;,7)&lt;br /&gt;
&lt;br /&gt;
Note, arming and disarming isn't a concept within UPnP or Z-Wave.  It's just a flag that the Luup engine uses, and is stored in a variable we created called &amp;quot;Armed&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
====Run Scene #5====&lt;br /&gt;
&lt;br /&gt;
Thanks &amp;quot;denix&amp;quot; on the forum for the correct syntax.&lt;br /&gt;
&amp;quot;Actually, the 4th parameter IS required, but it's not used. Otherwise the command fails with an error message&amp;quot;&lt;br /&gt;
&lt;br /&gt;
  luup.call_action(&amp;quot;urn:micasaverde-com:serviceId:HomeAutomationGateway1&amp;quot;,&amp;quot;RunScene&amp;quot;,{ SceneNum=&amp;quot;5&amp;quot; }, 0)&lt;br /&gt;
&lt;br /&gt;
In this case we left the device number off (the 4th parameter to &amp;lt;tt&amp;gt;luup.call_action&amp;lt;/tt&amp;gt;), because the &amp;quot;&amp;lt;tt&amp;gt;RunScene&amp;lt;/tt&amp;gt;&amp;quot; action is handled by the Luup engine itself--not by some device within Z-Wave, etc.&lt;br /&gt;
&lt;br /&gt;
However, normally you don't need to &amp;lt;tt&amp;gt;luup.call_action&amp;lt;/tt&amp;gt; in Lua code.  Rather, whatever actions, or commands, you want to run, you put into the scene itself, and the only Lua code is to simply check if some condition is true and abort the scene if the condition isn't met.&lt;br /&gt;
&lt;br /&gt;
====Change the Temperature on Thermostat (Cool) device #19====&lt;br /&gt;
  luup.call_action(&amp;quot;urn:upnp-org:serviceId:TemperatureSetpoint1_Cool&amp;quot;,&lt;br /&gt;
                   &amp;quot;SetCurrentSetpoint&amp;quot;, { NewCurrentSetpoint=&amp;quot;68&amp;quot; },&lt;br /&gt;
                   19)&lt;br /&gt;
&lt;br /&gt;
====Change the Temperature on a Thermostat (Heat) device #19====&lt;br /&gt;
  luup.call_action(&amp;quot;urn:upnp-org:serviceId:TemperatureSetpoint1_Heat&amp;quot;,&lt;br /&gt;
                   &amp;quot;SetCurrentSetpoint&amp;quot;,{ NewCurrentSetpoint=&amp;quot;68&amp;quot; },&lt;br /&gt;
                   19)&lt;br /&gt;
&lt;br /&gt;
===='Privacy' mode for Foscam FI8908[w]====&lt;br /&gt;
&lt;br /&gt;
 local IP_address      = '&amp;lt;IP address of camera&amp;gt;'&lt;br /&gt;
 local username        = '&amp;lt;username&amp;gt;'&lt;br /&gt;
 local password        = '&amp;lt;password&amp;gt;'&lt;br /&gt;
 local timeout         = 5&lt;br /&gt;
 &lt;br /&gt;
 function move_up()&lt;br /&gt;
 &lt;br /&gt;
  luup.inet.wget( 'http://'..IP_address..'/decoder_control.cgi?command=0' , timeout, username, password )&lt;br /&gt;
 &lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 -- center the camera; takes some time, so we have to wait 2 minutes for the command to complete&lt;br /&gt;
 &lt;br /&gt;
 luup.inet.wget( 'http://'..IP_address..'/decoder_control.cgi?command=25', timeout, username, password )&lt;br /&gt;
 &lt;br /&gt;
 luup.call_delay( 'move_up', 120 )&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Blinking lights====&lt;br /&gt;
&lt;br /&gt;
http://forum.micasaverde.com/index.php?topic=5127.0&lt;br /&gt;
&lt;br /&gt;
=== Calculate sunrise and sunset ===&lt;br /&gt;
&lt;br /&gt;
See http://forum.micasaverde.com/index.php?topic=2073.msg8132#msg8132&lt;br /&gt;
&lt;br /&gt;
=== Access the web ===&lt;br /&gt;
==== Invoke URL by GET request ====&lt;br /&gt;
Based on code by Jim/jgc94131&lt;br /&gt;
  require('ltn12')&lt;br /&gt;
  local http=require('socket.http')&lt;br /&gt;
  local response_body = {}&lt;br /&gt;
  local request_body = ''&lt;br /&gt;
  socket.http.TIMEOUT = 4&lt;br /&gt;
  local r, c, h = socket.http.request{&lt;br /&gt;
    url = 'http://website/page?parameter1=value&amp;amp;parameter2=value',&lt;br /&gt;
    method = &amp;quot;GET&amp;quot;,&lt;br /&gt;
    port = 80,&lt;br /&gt;
    headers = {&lt;br /&gt;
      [&amp;quot;Content-Length&amp;quot;] = string.len(request_body),&lt;br /&gt;
      [&amp;quot;Content-Type&amp;quot;] =  &amp;quot;application/x-www-form-urlencoded&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    source = ltn12.source.string(request_body),&lt;br /&gt;
    sink = ltn12.sink.table(response_body)&lt;br /&gt;
  } &lt;br /&gt;
&lt;br /&gt;
=== Access the current time  ===&lt;br /&gt;
&lt;br /&gt;
The Lua function &lt;br /&gt;
&lt;br /&gt;
  os.date (format, time)&lt;br /&gt;
&lt;br /&gt;
converts a time value `time` into a human readable date/time string, according to `format`. If you leave out the optional `time` parameter, it defaults to current time. The `format` parameter defaults to a fairly complete format. If you specify '*t' as the format, it will return a table instead of a formatted string. &lt;br /&gt;
&lt;br /&gt;
  t = os.date('*t')&lt;br /&gt;
 t =&amp;amp;gt; {year=2010, month=2, day=19, yday=50, wday=6, hour=22, min=45, sec=45, isdst=false}&lt;br /&gt;
&lt;br /&gt;
The fields are year, month, day of month, day of year, day of week, hour in 24 hour clock, minutes, seconds and if it's Daylight Savings Time.&lt;br /&gt;
&lt;br /&gt;
Current hour: &lt;br /&gt;
&lt;br /&gt;
  os.date('*t').hour&lt;br /&gt;
&lt;br /&gt;
Current minute: &lt;br /&gt;
&lt;br /&gt;
  os.date('*t').min&lt;br /&gt;
&lt;br /&gt;
Current second: &lt;br /&gt;
&lt;br /&gt;
  os.date('*t').sec&lt;br /&gt;
&lt;br /&gt;
Do something between 16:00 and 21:15: &lt;br /&gt;
&lt;br /&gt;
 local t = os.date('*t')&lt;br /&gt;
 local current_second = t.hour * 3600 + t.min * 60 + t.sec     -- number of seconds since midnight&lt;br /&gt;
 local min_time_in_seconds = 16 * 3600 +  0 * 60             -- 16:00&lt;br /&gt;
 local max_time_in_seconds = 21 * 3600 + 15 * 60             -- 21:15&lt;br /&gt;
 &lt;br /&gt;
 if (current_second &amp;amp;gt; min_time_in_seconds) and (current_second &amp;amp;lt; max_time_in_seconds)&lt;br /&gt;
 then&lt;br /&gt;
 -- do something&lt;br /&gt;
 else&lt;br /&gt;
 return false&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
See http://forum.micasaverde.com/index.php?topic=2015.0 and http://www.lua.org/manual/5.1/manual.html#5.8.&lt;br /&gt;
&lt;br /&gt;
=== Set Z-Wave parameters ===&lt;br /&gt;
&lt;br /&gt;
See http://forum.micasaverde.com/index.php?topic=1937.msg7803#msg7803&lt;br /&gt;
&lt;br /&gt;
===  a scene if the temperature is outside of a range ===&lt;br /&gt;
&lt;br /&gt;
add snippets here...&lt;/div&gt;</summary>
		<author><name>Solipsia</name></author>	</entry>

	<entry>
		<id>http://wiki.mios.com/index.php/File:SceneFlowchart.png</id>
		<title>File:SceneFlowchart.png</title>
		<link rel="alternate" type="text/html" href="http://wiki.mios.com/index.php/File:SceneFlowchart.png"/>
				<updated>2011-02-20T18:02:24Z</updated>
		
		<summary type="html">&lt;p&gt;Solipsia: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Solipsia</name></author>	</entry>

	<entry>
		<id>http://wiki.mios.com/index.php/ExpressControls3in1</id>
		<title>ExpressControls3in1</title>
		<link rel="alternate" type="text/html" href="http://wiki.mios.com/index.php/ExpressControls3in1"/>
				<updated>2011-02-20T15:10:26Z</updated>
		
		<summary type="html">&lt;p&gt;Solipsia: /* Usage */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Hardware]]&lt;br /&gt;
[[Category:Plugins]]&lt;br /&gt;
[[Category:3rd Party]]&lt;br /&gt;
&lt;br /&gt;
== Overview ==&lt;br /&gt;
The EZMotion Wireless 3-in-1 sensor is functionally identical to the HomeSeer HSM100 device. The user's manual is here: http://www.expresscontrols.com/pdf/EZMotionOwnerManual.pdf &lt;br /&gt;
&lt;br /&gt;
=== Features ===&lt;br /&gt;
&lt;br /&gt;
This unit is a contains three sensors that report values to the Vera:&lt;br /&gt;
* '''Motion Sensor''' with adjustable sensitivity and timeout&lt;br /&gt;
* '''Temperature Sensor'''&lt;br /&gt;
* '''Luminosity (Light Level) Sensor''' reporting level of light as a percentage between the brightest and darkest levels it has encountered since being switched on for the first time&lt;br /&gt;
&lt;br /&gt;
The unit has a red LED which indicates when motion is detected and it can be disabled. It can also report its battery level as a percentage to the Vera.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Basic Configuration ==&lt;br /&gt;
=== Wake Up interval ===&lt;br /&gt;
The unit sleeps for the duration of the Wake Up interval, which defaults to 1800 seconds or 30 minutes. When the interval expires, it wakes up and reports Temperature and Luminosity to the Vera. Note that while all 4 devices in the Vera MIOS screen can be configured for Wake Up intervals, only the setting for the '3-in-1 Sensor' has any effect and controls both Temperature and Luminosity intervals. The Motion Sensor is unaffected by the Wakeup Interval (see On Time below)&lt;br /&gt;
&lt;br /&gt;
To set the Wake Up Interval, click on the spanner for the &amp;quot;3-in-1 sensor&amp;quot; device, click on Setting and set Wakeup Interval to the desired interval. &lt;br /&gt;
&lt;br /&gt;
=== On Time ===&lt;br /&gt;
When the Motion Sensor is tripped, it transmits a tripped command and changes its state to Tripped=1 for the duration of the ON TIME variable. After this time has expired, it sends an Untripped command to the Vera and resets it state to Tripped=0. While the device is in a tripped state, any motion detected resets the interval timer but doesn't report a new trip event to the Vera. During the wait time the Motion Sensor device in the Vera will show Tripped=1 in the Advanced tab.&lt;br /&gt;
&lt;br /&gt;
To set the ON TIME, click on the spanner for the &amp;quot;3-in-1 sensor&amp;quot; device, click on Device Options and set variable 2 (On Time) to 5 (or the desired interval in minutes)&lt;br /&gt;
&lt;br /&gt;
'''Direct Association:''' The unit can be associated directly with another device such as a light. If you've done this, the unit will turn the light on when motion is sensed, then turn it off after the ON TIME. According to the sensor's manual up to four associated devices are supported, but associating more than one device does not work (as of Vera's firmware 1.0.900, see http://bugs.micasaverde.com/view.php?id=705).&lt;br /&gt;
&lt;br /&gt;
Leave Parameter #6, &amp;quot;OnValue&amp;quot;, at the default if you want the sensor tripped events in Vera.&lt;br /&gt;
&lt;br /&gt;
=== Polling Frequency ===&lt;br /&gt;
The unit can only be polled when it is either in Test mode or within 3 seconds after waking up (see Wake Up Interval above). Polling at any other time will fail since the unit will not respond. Also, every time the unit wakes up, it updates Vera with the temperature and luminosity. This means that polling is unnecessary and the polling frequency should be set to 0 (disabled) or a long interval to avoid unnecessary traffic on Vera, which could cause updates to be missed.&lt;br /&gt;
&lt;br /&gt;
An exception to this rule is when Vera is set to Always Awake (see AC Power below). In that case, the unit never wakes up, so never reports its values and must be polled at regular intervals.&lt;br /&gt;
&lt;br /&gt;
=== Example ===&lt;br /&gt;
Consider the following example of how to configure the sensor and the Vera for a common application. Suppose you want to install a motion sensor in your garage to turn the lights on when you enter, keep them on for as long as you move around in the garage, then turn them off 5 minutes after you've left. &lt;br /&gt;
# Put the unit in Test mode by pressing the button on the side&lt;br /&gt;
# Configure the On Time to 5 minutes&lt;br /&gt;
# Create two scenes in Vera:&lt;br /&gt;
## Turn on the light when the unit has tripped (New Scene, Events tab, Add Event, Device=Motion sensor, Type of Event=Armed sensor has tripped, Name=whatever, Tripped=Yes)&lt;br /&gt;
## Turn off the light when the unit sends an untrip command which happens after the On Time interval. (New Scene, Events tab, Add Event, Device=Motion sensor, Type of Event=Armed sensor has tripped, Name=whatever, Tripped=No)&lt;br /&gt;
&lt;br /&gt;
== Advanced Configuration ==&lt;br /&gt;
=== Running from AC Power ===&lt;br /&gt;
==== Overview ====&lt;br /&gt;
It is possible to run the unit from AC power instead of batteries, which will have the following benefits:&lt;br /&gt;
* Allow you to keep the unit awake permanently, allowing you to poll it and customise it without being in Test mode&lt;br /&gt;
* Report continuously every time motion is sensed, as opposed to waiting for the ON TIME duration in between trips&lt;br /&gt;
* Set the unit to report temperature and light levels at higher frequencies up to 1 minute&lt;br /&gt;
* Let the unit act as a Z-Wave repeater, increasing the span of your network&lt;br /&gt;
* Never worry about running down batteries. All of the above options are possible on battery power, but will run your batteries down within a few days&lt;br /&gt;
==== Configure ====&lt;br /&gt;
To do this, you will need to connect a AC to DC transformer that supplies 4.5v to 5.5v at up to 1amp to the battery terminals directly. Ensure that you measure that actual output voltage of the transformer using a multi/voltage meter (don't rely on its advertised rating). Any over-voltage may fry the unit. Also make sure that the polarity is correct. It may be helpful to add a diode in series with the positive terminal to prevent accidentally frying the unit if the polarity is incorrect. It will drop the voltage by 0.6v though. &lt;br /&gt;
&lt;br /&gt;
'''Setting ''Stay Awake'' to On'''&lt;br /&gt;
By default, the unit is constantly asleep and only wakes up at regular intervals to report the luminosity and temperature, before sleeping again. This is to save batteries. While asleep, the unit cannot be programmed from the Vera and cannot be polled for information. To get around this, one normally activates the Test mode by pressing the button on the side of the unit, which keeps it awake for 10 minutes so that it can be programmed. By setting the unit to stay awake constantly, you can program, poll or configure it at any time. It also has the side effect of enabling the unit to become a repeater of Z Wave signals throughout the network.&lt;br /&gt;
&lt;br /&gt;
To set it, click on the spanner for the &amp;quot;3-in-1 sensor&amp;quot; device, click on Device Options and set variable 5 (Stay Awake) to 1 or any number greater than 0.&lt;br /&gt;
&lt;br /&gt;
'''Setting ''On Time'' to ''Always Fire'''''&lt;br /&gt;
When the unit detects motion, it reports it by sending a Tripped command to the Vera. It then waits for the duration of the On Time and then sends un Untripped command to the Vera and waits for the next motion. Since battery life is not a consideration while on AC power, you can set it to 'Always Fire', which sends a Tripped command whenever motion is detected with no waiting period. Note, this will also prevent an Untripped command from being sent.&lt;br /&gt;
&lt;br /&gt;
To set it, click on the spanner for the &amp;quot;3-in-1 sensor&amp;quot; device, click on Device Options and set variable 2 (On Time) to 0.&lt;br /&gt;
&lt;br /&gt;
'''Excluding and Reincluding the unit'''&lt;br /&gt;
To activate these new settings, you will need to exclude and reinclude the unit using the standard Vera process. Remember to save your settings first.  &lt;br /&gt;
&lt;br /&gt;
''' Setting Poll frequency'''&lt;br /&gt;
The unit usually only reports temperate and luminosity every time it wakes up, but since the unit is now constantly awake, you will have to configure a poll frequency to gather that information.&lt;br /&gt;
&lt;br /&gt;
To set it, click on the spanner for the &amp;quot;Motion Sensor&amp;quot; device, click on Settings and set &amp;quot;Poll this node at most every&amp;quot; to the required update frequency. The Wakeup interval setting on this same screen has no effect since it's been overridden by Always Awake setting.&lt;br /&gt;
&lt;br /&gt;
== Known issues ==&lt;/div&gt;</summary>
		<author><name>Solipsia</name></author>	</entry>

	<entry>
		<id>http://wiki.mios.com/index.php/ExpressControls3in1</id>
		<title>ExpressControls3in1</title>
		<link rel="alternate" type="text/html" href="http://wiki.mios.com/index.php/ExpressControls3in1"/>
				<updated>2011-02-20T15:08:20Z</updated>
		
		<summary type="html">&lt;p&gt;Solipsia: /* Overview */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Hardware]]&lt;br /&gt;
[[Category:Plugins]]&lt;br /&gt;
[[Category:3rd Party]]&lt;br /&gt;
&lt;br /&gt;
== Overview ==&lt;br /&gt;
The EZMotion Wireless 3-in-1 sensor is functionally identical to the HomeSeer HSM100 device. The user's manual is here: http://www.expresscontrols.com/pdf/EZMotionOwnerManual.pdf &lt;br /&gt;
&lt;br /&gt;
=== Features ===&lt;br /&gt;
&lt;br /&gt;
This unit is a contains three sensors that report values to the Vera:&lt;br /&gt;
* '''Motion Sensor''' with adjustable sensitivity and timeout&lt;br /&gt;
* '''Temperature Sensor'''&lt;br /&gt;
* '''Luminosity (Light Level) Sensor''' reporting level of light as a percentage between the brightest and darkest levels it has encountered since being switched on for the first time&lt;br /&gt;
&lt;br /&gt;
The unit has a red LED which indicates when motion is detected and it can be disabled. It can also report its battery level as a percentage to the Vera.&lt;br /&gt;
&lt;br /&gt;
=== Usage ===&lt;br /&gt;
&lt;br /&gt;
You can add an [[Event]] to your [[Scenes]] 'sensor tripped' or 'armed sensor is tripped' so the scene is executed when the motion sensor is tripped. (See also [[Intro Security]].) You can see the current temperature and light level on Vera's dashboard or on the mobile phone interface. &lt;br /&gt;
&lt;br /&gt;
To pair the sensor with Vera (i.e. add it to Vera's Z-Wave network), bring Vera's dongle near the sensor as you would pair any device, and press the blue button on the 3-in-1 sensor. Reconnect Vera's Z-Wave dongle. &lt;br /&gt;
&lt;br /&gt;
Vera needs to communicate with the sensor to identify what type of device it is and configure it. But the sensor will only talk to Vera within a minute of pressing the blue button. After re-connecting Vera's Z-Wave dongle, wait 60 seconds, and if the sensor shows up as 'Generic IO', go press the blue button again, and again wait 60 seconds. Vera should show it as an 'Express Controls' with 3 embedded devices. Assign it to a room like any other device. &lt;br /&gt;
&lt;br /&gt;
If you want Vera to be able to use the sensor, click the '+' button next to the device. Check the box &amp;quot;Let Vera manage the associations&amp;quot;. Fill in the 'wakeup interval' box. The sensor is normally asleep to conserve the batteries and will only report the temperature and light reading when it periodically wakes up. This is the frequency of the wakeup. The minimum number you can put in is 360, which means 6 minutes (i.e. 6 minutes * 60 seconds/minute = 360 seconds). At 360, you will get a new light/temperature reading every 6 minutes. However, at this rate, the batteries may only last a couple months. You can instead put in a wakeup interval of, for example, 3600 (i.e. 1 hour) and the batteries will last a lot longer, but the reading Vera has for the current temperature and light may be up to 1 hour old. &lt;br /&gt;
&lt;br /&gt;
When you have specified those settings, save your changes. Wait a minute for Vera to configure the Z-Wave devices and check the color of the cog wheel next to the sensor as explained [[Device Control Status|here]]. If it's green, everything is okay and the sensor will work. If it's red, Vera was not able to configure the sensor because it probably went to sleep already by the time you saved your changes. Go to the sensor and press the blue button. Within a minute or so it should turn green. &lt;br /&gt;
&lt;br /&gt;
If you have difficulty getting the green cog icon, try pressing the blue button on the sensor, then in Vera's device page, click the '+' button for the device and click 'configure right now'. &lt;br /&gt;
&lt;br /&gt;
There are also a few custom configuration settings for the sensor for things like Sensitivity, Timeout Delay, LED Enabled, Light Threshold, and so on. To set them, click the + button next to the device, choose 'Custom Z-Wave Settings', then 'Add configuration setting', put in the variable number that corresponds to the setting you want to change, choose a data size of '1 byte dec' and enter the desired value, as shown below. Then click 'Save'. Vera will attempt to re-configure the sensor. If it fails, probably because the sensor is asleep, you will see the red cog. Press the blue button on the sensor and you should get a green cog meaning the sensor has been configured with your new settings. (See also: [[ZWave Options]])&lt;br /&gt;
&lt;br /&gt;
== Basic Configuration ==&lt;br /&gt;
=== Wake Up interval ===&lt;br /&gt;
The unit sleeps for the duration of the Wake Up interval, which defaults to 1800 seconds or 30 minutes. When the interval expires, it wakes up and reports Temperature and Luminosity to the Vera. Note that while all 4 devices in the Vera MIOS screen can be configured for Wake Up intervals, only the setting for the '3-in-1 Sensor' has any effect and controls both Temperature and Luminosity intervals. The Motion Sensor is unaffected by the Wakeup Interval (see On Time below)&lt;br /&gt;
&lt;br /&gt;
To set the Wake Up Interval, click on the spanner for the &amp;quot;3-in-1 sensor&amp;quot; device, click on Setting and set Wakeup Interval to the desired interval. &lt;br /&gt;
&lt;br /&gt;
=== On Time ===&lt;br /&gt;
When the Motion Sensor is tripped, it transmits a tripped command and changes its state to Tripped=1 for the duration of the ON TIME variable. After this time has expired, it sends an Untripped command to the Vera and resets it state to Tripped=0. While the device is in a tripped state, any motion detected resets the interval timer but doesn't report a new trip event to the Vera. During the wait time the Motion Sensor device in the Vera will show Tripped=1 in the Advanced tab.&lt;br /&gt;
&lt;br /&gt;
To set the ON TIME, click on the spanner for the &amp;quot;3-in-1 sensor&amp;quot; device, click on Device Options and set variable 2 (On Time) to 5 (or the desired interval in minutes)&lt;br /&gt;
&lt;br /&gt;
'''Direct Association:''' The unit can be associated directly with another device such as a light. If you've done this, the unit will turn the light on when motion is sensed, then turn it off after the ON TIME. According to the sensor's manual up to four associated devices are supported, but associating more than one device does not work (as of Vera's firmware 1.0.900, see http://bugs.micasaverde.com/view.php?id=705).&lt;br /&gt;
&lt;br /&gt;
Leave Parameter #6, &amp;quot;OnValue&amp;quot;, at the default if you want the sensor tripped events in Vera.&lt;br /&gt;
&lt;br /&gt;
=== Polling Frequency ===&lt;br /&gt;
The unit can only be polled when it is either in Test mode or within 3 seconds after waking up (see Wake Up Interval above). Polling at any other time will fail since the unit will not respond. Also, every time the unit wakes up, it updates Vera with the temperature and luminosity. This means that polling is unnecessary and the polling frequency should be set to 0 (disabled) or a long interval to avoid unnecessary traffic on Vera, which could cause updates to be missed.&lt;br /&gt;
&lt;br /&gt;
An exception to this rule is when Vera is set to Always Awake (see AC Power below). In that case, the unit never wakes up, so never reports its values and must be polled at regular intervals.&lt;br /&gt;
&lt;br /&gt;
=== Example ===&lt;br /&gt;
Consider the following example of how to configure the sensor and the Vera for a common application. Suppose you want to install a motion sensor in your garage to turn the lights on when you enter, keep them on for as long as you move around in the garage, then turn them off 5 minutes after you've left. &lt;br /&gt;
# Put the unit in Test mode by pressing the button on the side&lt;br /&gt;
# Configure the On Time to 5 minutes&lt;br /&gt;
# Create two scenes in Vera:&lt;br /&gt;
## Turn on the light when the unit has tripped (New Scene, Events tab, Add Event, Device=Motion sensor, Type of Event=Armed sensor has tripped, Name=whatever, Tripped=Yes)&lt;br /&gt;
## Turn off the light when the unit sends an untrip command which happens after the On Time interval. (New Scene, Events tab, Add Event, Device=Motion sensor, Type of Event=Armed sensor has tripped, Name=whatever, Tripped=No)&lt;br /&gt;
&lt;br /&gt;
== Advanced Configuration ==&lt;br /&gt;
=== Running from AC Power ===&lt;br /&gt;
==== Overview ====&lt;br /&gt;
It is possible to run the unit from AC power instead of batteries, which will have the following benefits:&lt;br /&gt;
* Allow you to keep the unit awake permanently, allowing you to poll it and customise it without being in Test mode&lt;br /&gt;
* Report continuously every time motion is sensed, as opposed to waiting for the ON TIME duration in between trips&lt;br /&gt;
* Set the unit to report temperature and light levels at higher frequencies up to 1 minute&lt;br /&gt;
* Let the unit act as a Z-Wave repeater, increasing the span of your network&lt;br /&gt;
* Never worry about running down batteries. All of the above options are possible on battery power, but will run your batteries down within a few days&lt;br /&gt;
==== Configure ====&lt;br /&gt;
To do this, you will need to connect a AC to DC transformer that supplies 4.5v to 5.5v at up to 1amp to the battery terminals directly. Ensure that you measure that actual output voltage of the transformer using a multi/voltage meter (don't rely on its advertised rating). Any over-voltage may fry the unit. Also make sure that the polarity is correct. It may be helpful to add a diode in series with the positive terminal to prevent accidentally frying the unit if the polarity is incorrect. It will drop the voltage by 0.6v though. &lt;br /&gt;
&lt;br /&gt;
'''Setting ''Stay Awake'' to On'''&lt;br /&gt;
By default, the unit is constantly asleep and only wakes up at regular intervals to report the luminosity and temperature, before sleeping again. This is to save batteries. While asleep, the unit cannot be programmed from the Vera and cannot be polled for information. To get around this, one normally activates the Test mode by pressing the button on the side of the unit, which keeps it awake for 10 minutes so that it can be programmed. By setting the unit to stay awake constantly, you can program, poll or configure it at any time. It also has the side effect of enabling the unit to become a repeater of Z Wave signals throughout the network.&lt;br /&gt;
&lt;br /&gt;
To set it, click on the spanner for the &amp;quot;3-in-1 sensor&amp;quot; device, click on Device Options and set variable 5 (Stay Awake) to 1 or any number greater than 0.&lt;br /&gt;
&lt;br /&gt;
'''Setting ''On Time'' to ''Always Fire'''''&lt;br /&gt;
When the unit detects motion, it reports it by sending a Tripped command to the Vera. It then waits for the duration of the On Time and then sends un Untripped command to the Vera and waits for the next motion. Since battery life is not a consideration while on AC power, you can set it to 'Always Fire', which sends a Tripped command whenever motion is detected with no waiting period. Note, this will also prevent an Untripped command from being sent.&lt;br /&gt;
&lt;br /&gt;
To set it, click on the spanner for the &amp;quot;3-in-1 sensor&amp;quot; device, click on Device Options and set variable 2 (On Time) to 0.&lt;br /&gt;
&lt;br /&gt;
'''Excluding and Reincluding the unit'''&lt;br /&gt;
To activate these new settings, you will need to exclude and reinclude the unit using the standard Vera process. Remember to save your settings first.  &lt;br /&gt;
&lt;br /&gt;
''' Setting Poll frequency'''&lt;br /&gt;
The unit usually only reports temperate and luminosity every time it wakes up, but since the unit is now constantly awake, you will have to configure a poll frequency to gather that information.&lt;br /&gt;
&lt;br /&gt;
To set it, click on the spanner for the &amp;quot;Motion Sensor&amp;quot; device, click on Settings and set &amp;quot;Poll this node at most every&amp;quot; to the required update frequency. The Wakeup interval setting on this same screen has no effect since it's been overridden by Always Awake setting.&lt;br /&gt;
&lt;br /&gt;
== Known issues ==&lt;/div&gt;</summary>
		<author><name>Solipsia</name></author>	</entry>

	<entry>
		<id>http://wiki.mios.com/index.php/ExpressControls3in1</id>
		<title>ExpressControls3in1</title>
		<link rel="alternate" type="text/html" href="http://wiki.mios.com/index.php/ExpressControls3in1"/>
				<updated>2011-02-20T14:58:32Z</updated>
		
		<summary type="html">&lt;p&gt;Solipsia: /* Configure */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Hardware]]&lt;br /&gt;
[[Category:Plugins]]&lt;br /&gt;
[[Category:3rd Party]]&lt;br /&gt;
&lt;br /&gt;
== Overview ==&lt;br /&gt;
This unit is functionally identical to the HomeSeer HSM100 device. The user's manual is here: http://www.expresscontrols.com/pdf/EZMotionOwnerManual.pdf &lt;br /&gt;
&lt;br /&gt;
You can add an [[Event]] to your [[Scenes]] 'sensor tripped' or 'armed sensor is tripped' so the scene is executed when the motion sensor is tripped. (See also [[Intro Security]].) You can see the current temperature and light level on Vera's dashboard or on the mobile phone interface. &lt;br /&gt;
&lt;br /&gt;
To pair the sensor with Vera (i.e. add it to Vera's Z-Wave network), bring Vera's dongle near the sensor as you would pair any device, and press the blue button on the 3-in-1 sensor. Reconnect Vera's Z-Wave dongle. &lt;br /&gt;
&lt;br /&gt;
Vera needs to communicate with the sensor to identify what type of device it is and configure it. But the sensor will only talk to Vera within a minute of pressing the blue button. After re-connecting Vera's Z-Wave dongle, wait 60 seconds, and if the sensor shows up as 'Generic IO', go press the blue button again, and again wait 60 seconds. Vera should show it as an 'Express Controls' with 3 embedded devices. Assign it to a room like any other device. &lt;br /&gt;
&lt;br /&gt;
If you want Vera to be able to use the sensor, click the '+' button next to the device. Check the box &amp;quot;Let Vera manage the associations&amp;quot;. Fill in the 'wakeup interval' box. The sensor is normally asleep to conserve the batteries and will only report the temperature and light reading when it periodically wakes up. This is the frequency of the wakeup. The minimum number you can put in is 360, which means 6 minutes (i.e. 6 minutes * 60 seconds/minute = 360 seconds). At 360, you will get a new light/temperature reading every 6 minutes. However, at this rate, the batteries may only last a couple months. You can instead put in a wakeup interval of, for example, 3600 (i.e. 1 hour) and the batteries will last a lot longer, but the reading Vera has for the current temperature and light may be up to 1 hour old. &lt;br /&gt;
&lt;br /&gt;
When you have specified those settings, save your changes. Wait a minute for Vera to configure the Z-Wave devices and check the color of the cog wheel next to the sensor as explained [[Device Control Status|here]]. If it's green, everything is okay and the sensor will work. If it's red, Vera was not able to configure the sensor because it probably went to sleep already by the time you saved your changes. Go to the sensor and press the blue button. Within a minute or so it should turn green. &lt;br /&gt;
&lt;br /&gt;
If you have difficulty getting the green cog icon, try pressing the blue button on the sensor, then in Vera's device page, click the '+' button for the device and click 'configure right now'. &lt;br /&gt;
&lt;br /&gt;
There are also a few custom configuration settings for the sensor for things like Sensitivity, Timeout Delay, LED Enabled, Light Threshold, and so on. To set them, click the + button next to the device, choose 'Custom Z-Wave Settings', then 'Add configuration setting', put in the variable number that corresponds to the setting you want to change, choose a data size of '1 byte dec' and enter the desired value, as shown below. Then click 'Save'. Vera will attempt to re-configure the sensor. If it fails, probably because the sensor is asleep, you will see the red cog. Press the blue button on the sensor and you should get a green cog meaning the sensor has been configured with your new settings. (See also: [[ZWave Options]])&lt;br /&gt;
== Basic Configuration ==&lt;br /&gt;
=== Wake Up interval ===&lt;br /&gt;
The unit sleeps for the duration of the Wake Up interval, which defaults to 1800 seconds or 30 minutes. When the interval expires, it wakes up and reports Temperature and Luminosity to the Vera. Note that while all 4 devices in the Vera MIOS screen can be configured for Wake Up intervals, only the setting for the '3-in-1 Sensor' has any effect and controls both Temperature and Luminosity intervals. The Motion Sensor is unaffected by the Wakeup Interval (see On Time below)&lt;br /&gt;
&lt;br /&gt;
To set the Wake Up Interval, click on the spanner for the &amp;quot;3-in-1 sensor&amp;quot; device, click on Setting and set Wakeup Interval to the desired interval. &lt;br /&gt;
&lt;br /&gt;
=== On Time ===&lt;br /&gt;
When the Motion Sensor is tripped, it transmits a tripped command and changes its state to Tripped=1 for the duration of the ON TIME variable. After this time has expired, it sends an Untripped command to the Vera and resets it state to Tripped=0. While the device is in a tripped state, any motion detected resets the interval timer but doesn't report a new trip event to the Vera. During the wait time the Motion Sensor device in the Vera will show Tripped=1 in the Advanced tab.&lt;br /&gt;
&lt;br /&gt;
To set the ON TIME, click on the spanner for the &amp;quot;3-in-1 sensor&amp;quot; device, click on Device Options and set variable 2 (On Time) to 5 (or the desired interval in minutes)&lt;br /&gt;
&lt;br /&gt;
'''Direct Association:''' The unit can be associated directly with another device such as a light. If you've done this, the unit will turn the light on when motion is sensed, then turn it off after the ON TIME. According to the sensor's manual up to four associated devices are supported, but associating more than one device does not work (as of Vera's firmware 1.0.900, see http://bugs.micasaverde.com/view.php?id=705).&lt;br /&gt;
&lt;br /&gt;
Leave Parameter #6, &amp;quot;OnValue&amp;quot;, at the default if you want the sensor tripped events in Vera.&lt;br /&gt;
&lt;br /&gt;
=== Polling Frequency ===&lt;br /&gt;
The unit can only be polled when it is either in Test mode or within 3 seconds after waking up (see Wake Up Interval above). Polling at any other time will fail since the unit will not respond. Also, every time the unit wakes up, it updates Vera with the temperature and luminosity. This means that polling is unnecessary and the polling frequency should be set to 0 (disabled) or a long interval to avoid unnecessary traffic on Vera, which could cause updates to be missed.&lt;br /&gt;
&lt;br /&gt;
An exception to this rule is when Vera is set to Always Awake (see AC Power below). In that case, the unit never wakes up, so never reports its values and must be polled at regular intervals.&lt;br /&gt;
&lt;br /&gt;
=== Example ===&lt;br /&gt;
Consider the following example of how to configure the sensor and the Vera for a common application. Suppose you want to install a motion sensor in your garage to turn the lights on when you enter, keep them on for as long as you move around in the garage, then turn them off 5 minutes after you've left. &lt;br /&gt;
# Put the unit in Test mode by pressing the button on the side&lt;br /&gt;
# Configure the On Time to 5 minutes&lt;br /&gt;
# Create two scenes in Vera:&lt;br /&gt;
## Turn on the light when the unit has tripped (New Scene, Events tab, Add Event, Device=Motion sensor, Type of Event=Armed sensor has tripped, Name=whatever, Tripped=Yes)&lt;br /&gt;
## Turn off the light when the unit sends an untrip command which happens after the On Time interval. (New Scene, Events tab, Add Event, Device=Motion sensor, Type of Event=Armed sensor has tripped, Name=whatever, Tripped=No)&lt;br /&gt;
&lt;br /&gt;
== Advanced Configuration ==&lt;br /&gt;
=== Running from AC Power ===&lt;br /&gt;
==== Overview ====&lt;br /&gt;
It is possible to run the unit from AC power instead of batteries, which will have the following benefits:&lt;br /&gt;
* Allow you to keep the unit awake permanently, allowing you to poll it and customise it without being in Test mode&lt;br /&gt;
* Report continuously every time motion is sensed, as opposed to waiting for the ON TIME duration in between trips&lt;br /&gt;
* Set the unit to report temperature and light levels at higher frequencies up to 1 minute&lt;br /&gt;
* Let the unit act as a Z-Wave repeater, increasing the span of your network&lt;br /&gt;
* Never worry about running down batteries. All of the above options are possible on battery power, but will run your batteries down within a few days&lt;br /&gt;
==== Configure ====&lt;br /&gt;
To do this, you will need to connect a AC to DC transformer that supplies 4.5v to 5.5v at up to 1amp to the battery terminals directly. Ensure that you measure that actual output voltage of the transformer using a multi/voltage meter (don't rely on its advertised rating). Any over-voltage may fry the unit. Also make sure that the polarity is correct. It may be helpful to add a diode in series with the positive terminal to prevent accidentally frying the unit if the polarity is incorrect. It will drop the voltage by 0.6v though. &lt;br /&gt;
&lt;br /&gt;
'''Setting ''Stay Awake'' to On'''&lt;br /&gt;
By default, the unit is constantly asleep and only wakes up at regular intervals to report the luminosity and temperature, before sleeping again. This is to save batteries. While asleep, the unit cannot be programmed from the Vera and cannot be polled for information. To get around this, one normally activates the Test mode by pressing the button on the side of the unit, which keeps it awake for 10 minutes so that it can be programmed. By setting the unit to stay awake constantly, you can program, poll or configure it at any time. It also has the side effect of enabling the unit to become a repeater of Z Wave signals throughout the network.&lt;br /&gt;
&lt;br /&gt;
To set it, click on the spanner for the &amp;quot;3-in-1 sensor&amp;quot; device, click on Device Options and set variable 5 (Stay Awake) to 1 or any number greater than 0.&lt;br /&gt;
&lt;br /&gt;
'''Setting ''On Time'' to ''Always Fire'''''&lt;br /&gt;
When the unit detects motion, it reports it by sending a Tripped command to the Vera. It then waits for the duration of the On Time and then sends un Untripped command to the Vera and waits for the next motion. Since battery life is not a consideration while on AC power, you can set it to 'Always Fire', which sends a Tripped command whenever motion is detected with no waiting period. Note, this will also prevent an Untripped command from being sent.&lt;br /&gt;
&lt;br /&gt;
To set it, click on the spanner for the &amp;quot;3-in-1 sensor&amp;quot; device, click on Device Options and set variable 2 (On Time) to 0.&lt;br /&gt;
&lt;br /&gt;
'''Excluding and Reincluding the unit'''&lt;br /&gt;
To activate these new settings, you will need to exclude and reinclude the unit using the standard Vera process. Remember to save your settings first.  &lt;br /&gt;
&lt;br /&gt;
''' Setting Poll frequency'''&lt;br /&gt;
The unit usually only reports temperate and luminosity every time it wakes up, but since the unit is now constantly awake, you will have to configure a poll frequency to gather that information.&lt;br /&gt;
&lt;br /&gt;
To set it, click on the spanner for the &amp;quot;Motion Sensor&amp;quot; device, click on Settings and set &amp;quot;Poll this node at most every&amp;quot; to the required update frequency. The Wakeup interval setting on this same screen has no effect since it's been overridden by Always Awake setting.&lt;br /&gt;
&lt;br /&gt;
== Known issues ==&lt;/div&gt;</summary>
		<author><name>Solipsia</name></author>	</entry>

	<entry>
		<id>http://wiki.mios.com/index.php/ExpressControls3in1</id>
		<title>ExpressControls3in1</title>
		<link rel="alternate" type="text/html" href="http://wiki.mios.com/index.php/ExpressControls3in1"/>
				<updated>2011-02-20T14:56:36Z</updated>
		
		<summary type="html">&lt;p&gt;Solipsia: /* Basic Configuration */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Hardware]]&lt;br /&gt;
[[Category:Plugins]]&lt;br /&gt;
[[Category:3rd Party]]&lt;br /&gt;
&lt;br /&gt;
== Overview ==&lt;br /&gt;
This unit is functionally identical to the HomeSeer HSM100 device. The user's manual is here: http://www.expresscontrols.com/pdf/EZMotionOwnerManual.pdf &lt;br /&gt;
&lt;br /&gt;
You can add an [[Event]] to your [[Scenes]] 'sensor tripped' or 'armed sensor is tripped' so the scene is executed when the motion sensor is tripped. (See also [[Intro Security]].) You can see the current temperature and light level on Vera's dashboard or on the mobile phone interface. &lt;br /&gt;
&lt;br /&gt;
To pair the sensor with Vera (i.e. add it to Vera's Z-Wave network), bring Vera's dongle near the sensor as you would pair any device, and press the blue button on the 3-in-1 sensor. Reconnect Vera's Z-Wave dongle. &lt;br /&gt;
&lt;br /&gt;
Vera needs to communicate with the sensor to identify what type of device it is and configure it. But the sensor will only talk to Vera within a minute of pressing the blue button. After re-connecting Vera's Z-Wave dongle, wait 60 seconds, and if the sensor shows up as 'Generic IO', go press the blue button again, and again wait 60 seconds. Vera should show it as an 'Express Controls' with 3 embedded devices. Assign it to a room like any other device. &lt;br /&gt;
&lt;br /&gt;
If you want Vera to be able to use the sensor, click the '+' button next to the device. Check the box &amp;quot;Let Vera manage the associations&amp;quot;. Fill in the 'wakeup interval' box. The sensor is normally asleep to conserve the batteries and will only report the temperature and light reading when it periodically wakes up. This is the frequency of the wakeup. The minimum number you can put in is 360, which means 6 minutes (i.e. 6 minutes * 60 seconds/minute = 360 seconds). At 360, you will get a new light/temperature reading every 6 minutes. However, at this rate, the batteries may only last a couple months. You can instead put in a wakeup interval of, for example, 3600 (i.e. 1 hour) and the batteries will last a lot longer, but the reading Vera has for the current temperature and light may be up to 1 hour old. &lt;br /&gt;
&lt;br /&gt;
When you have specified those settings, save your changes. Wait a minute for Vera to configure the Z-Wave devices and check the color of the cog wheel next to the sensor as explained [[Device Control Status|here]]. If it's green, everything is okay and the sensor will work. If it's red, Vera was not able to configure the sensor because it probably went to sleep already by the time you saved your changes. Go to the sensor and press the blue button. Within a minute or so it should turn green. &lt;br /&gt;
&lt;br /&gt;
If you have difficulty getting the green cog icon, try pressing the blue button on the sensor, then in Vera's device page, click the '+' button for the device and click 'configure right now'. &lt;br /&gt;
&lt;br /&gt;
There are also a few custom configuration settings for the sensor for things like Sensitivity, Timeout Delay, LED Enabled, Light Threshold, and so on. To set them, click the + button next to the device, choose 'Custom Z-Wave Settings', then 'Add configuration setting', put in the variable number that corresponds to the setting you want to change, choose a data size of '1 byte dec' and enter the desired value, as shown below. Then click 'Save'. Vera will attempt to re-configure the sensor. If it fails, probably because the sensor is asleep, you will see the red cog. Press the blue button on the sensor and you should get a green cog meaning the sensor has been configured with your new settings. (See also: [[ZWave Options]])&lt;br /&gt;
== Basic Configuration ==&lt;br /&gt;
=== Wake Up interval ===&lt;br /&gt;
The unit sleeps for the duration of the Wake Up interval, which defaults to 1800 seconds or 30 minutes. When the interval expires, it wakes up and reports Temperature and Luminosity to the Vera. Note that while all 4 devices in the Vera MIOS screen can be configured for Wake Up intervals, only the setting for the '3-in-1 Sensor' has any effect and controls both Temperature and Luminosity intervals. The Motion Sensor is unaffected by the Wakeup Interval (see On Time below)&lt;br /&gt;
&lt;br /&gt;
To set the Wake Up Interval, click on the spanner for the &amp;quot;3-in-1 sensor&amp;quot; device, click on Setting and set Wakeup Interval to the desired interval. &lt;br /&gt;
&lt;br /&gt;
=== On Time ===&lt;br /&gt;
When the Motion Sensor is tripped, it transmits a tripped command and changes its state to Tripped=1 for the duration of the ON TIME variable. After this time has expired, it sends an Untripped command to the Vera and resets it state to Tripped=0. While the device is in a tripped state, any motion detected resets the interval timer but doesn't report a new trip event to the Vera. During the wait time the Motion Sensor device in the Vera will show Tripped=1 in the Advanced tab.&lt;br /&gt;
&lt;br /&gt;
To set the ON TIME, click on the spanner for the &amp;quot;3-in-1 sensor&amp;quot; device, click on Device Options and set variable 2 (On Time) to 5 (or the desired interval in minutes)&lt;br /&gt;
&lt;br /&gt;
'''Direct Association:''' The unit can be associated directly with another device such as a light. If you've done this, the unit will turn the light on when motion is sensed, then turn it off after the ON TIME. According to the sensor's manual up to four associated devices are supported, but associating more than one device does not work (as of Vera's firmware 1.0.900, see http://bugs.micasaverde.com/view.php?id=705).&lt;br /&gt;
&lt;br /&gt;
Leave Parameter #6, &amp;quot;OnValue&amp;quot;, at the default if you want the sensor tripped events in Vera.&lt;br /&gt;
&lt;br /&gt;
=== Polling Frequency ===&lt;br /&gt;
The unit can only be polled when it is either in Test mode or within 3 seconds after waking up (see Wake Up Interval above). Polling at any other time will fail since the unit will not respond. Also, every time the unit wakes up, it updates Vera with the temperature and luminosity. This means that polling is unnecessary and the polling frequency should be set to 0 (disabled) or a long interval to avoid unnecessary traffic on Vera, which could cause updates to be missed.&lt;br /&gt;
&lt;br /&gt;
An exception to this rule is when Vera is set to Always Awake (see AC Power below). In that case, the unit never wakes up, so never reports its values and must be polled at regular intervals.&lt;br /&gt;
&lt;br /&gt;
=== Example ===&lt;br /&gt;
Consider the following example of how to configure the sensor and the Vera for a common application. Suppose you want to install a motion sensor in your garage to turn the lights on when you enter, keep them on for as long as you move around in the garage, then turn them off 5 minutes after you've left. &lt;br /&gt;
# Put the unit in Test mode by pressing the button on the side&lt;br /&gt;
# Configure the On Time to 5 minutes&lt;br /&gt;
# Create two scenes in Vera:&lt;br /&gt;
## Turn on the light when the unit has tripped (New Scene, Events tab, Add Event, Device=Motion sensor, Type of Event=Armed sensor has tripped, Name=whatever, Tripped=Yes)&lt;br /&gt;
## Turn off the light when the unit sends an untrip command which happens after the On Time interval. (New Scene, Events tab, Add Event, Device=Motion sensor, Type of Event=Armed sensor has tripped, Name=whatever, Tripped=No)&lt;br /&gt;
&lt;br /&gt;
== Advanced Configuration ==&lt;br /&gt;
=== Running from AC Power ===&lt;br /&gt;
==== Overview ====&lt;br /&gt;
It is possible to run the unit from AC power instead of batteries, which will have the following benefits:&lt;br /&gt;
* Allow you to keep the unit awake permanently, allowing you to poll it and customise it without being in Test mode&lt;br /&gt;
* Report continuously every time motion is sensed, as opposed to waiting for the ON TIME duration in between trips&lt;br /&gt;
* Set the unit to report temperature and light levels at higher frequencies up to 1 minute&lt;br /&gt;
* Let the unit act as a Z-Wave repeater, increasing the span of your network&lt;br /&gt;
* Never worry about running down batteries. All of the above options are possible on battery power, but will run your batteries down within a few days&lt;br /&gt;
==== Configure ====&lt;br /&gt;
To do this, you will need to connect a AC to DC transformer that supplies 4.5v to 5v at up to 1amp to the battery terminals directly. Ensure that you measure that actual output voltage of the transformer using a multi/voltage meter (don't rely on its advertised rating). Any over-voltage may fry the unit. Also make sure that the polarity is correct. &lt;br /&gt;
&lt;br /&gt;
'''Setting ''Stay Awake'' to On'''&lt;br /&gt;
By default, the unit is constantly asleep and only wakes up at regular intervals to report the luminosity and temperature, before sleeping again. This is to save batteries. While asleep, the unit cannot be programmed from the Vera and cannot be polled for information. To get around this, one normally activates the Test mode by pressing the button on the side of the unit, which keeps it awake for 10 minutes so that it can be programmed. By setting the unit to stay awake constantly, you can program, poll or configure it at any time. It also has the side effect of enabling the unit to become a repeater of Z Wave signals throughout the network.&lt;br /&gt;
&lt;br /&gt;
To set it, click on the spanner for the &amp;quot;3-in-1 sensor&amp;quot; device, click on Device Options and set variable 5 (Stay Awake) to 1 or any number greater than 0.&lt;br /&gt;
&lt;br /&gt;
'''Setting ''On Time'' to ''Always Fire'''''&lt;br /&gt;
When the unit detects motion, it reports it by sending a Tripped command to the Vera. It then waits for the duration of the On Time and then sends un Untripped command to the Vera and waits for the next motion. Since battery life is not a consideration while on AC power, you can set it to 'Always Fire', which sends a Tripped command whenever motion is detected with no waiting period. Note, this will also prevent an Untripped command from being sent.&lt;br /&gt;
&lt;br /&gt;
To set it, click on the spanner for the &amp;quot;3-in-1 sensor&amp;quot; device, click on Device Options and set variable 2 (On Time) to 0.&lt;br /&gt;
&lt;br /&gt;
'''Excluding and Reincluding the unit'''&lt;br /&gt;
To activate these new settings, you will need to exclude and reinclude the unit using the standard Vera process. Remember to save your settings first.  &lt;br /&gt;
&lt;br /&gt;
''' Setting Poll frequency'''&lt;br /&gt;
The unit usually only reports temperate and luminosity every time it wakes up, but since the unit is now constantly awake, you will have to configure a poll frequency to gather that information.&lt;br /&gt;
&lt;br /&gt;
To set it, click on the spanner for the &amp;quot;Motion Sensor&amp;quot; device, click on Settings and set &amp;quot;Poll this node at most every&amp;quot; to the required update frequency. The Wakeup interval setting on this same screen has no effect since it's been overridden by Always Awake setting.&lt;br /&gt;
&lt;br /&gt;
== Known issues ==&lt;/div&gt;</summary>
		<author><name>Solipsia</name></author>	</entry>

	<entry>
		<id>http://wiki.mios.com/index.php/ExpressControls3in1</id>
		<title>ExpressControls3in1</title>
		<link rel="alternate" type="text/html" href="http://wiki.mios.com/index.php/ExpressControls3in1"/>
				<updated>2011-02-19T15:12:48Z</updated>
		
		<summary type="html">&lt;p&gt;Solipsia: /* Configure */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Hardware]]&lt;br /&gt;
[[Category:Plugins]]&lt;br /&gt;
[[Category:3rd Party]]&lt;br /&gt;
&lt;br /&gt;
== Overview ==&lt;br /&gt;
This unit is functionally identical to the HomeSeer HSM100 device. The user's manual is here: http://www.expresscontrols.com/pdf/EZMotionOwnerManual.pdf &lt;br /&gt;
&lt;br /&gt;
You can add an [[Event]] to your [[Scenes]] 'sensor tripped' or 'armed sensor is tripped' so the scene is executed when the motion sensor is tripped. (See also [[Intro Security]].) You can see the current temperature and light level on Vera's dashboard or on the mobile phone interface. &lt;br /&gt;
&lt;br /&gt;
To pair the sensor with Vera (i.e. add it to Vera's Z-Wave network), bring Vera's dongle near the sensor as you would pair any device, and press the blue button on the 3-in-1 sensor. Reconnect Vera's Z-Wave dongle. &lt;br /&gt;
&lt;br /&gt;
Vera needs to communicate with the sensor to identify what type of device it is and configure it. But the sensor will only talk to Vera within a minute of pressing the blue button. After re-connecting Vera's Z-Wave dongle, wait 60 seconds, and if the sensor shows up as 'Generic IO', go press the blue button again, and again wait 60 seconds. Vera should show it as an 'Express Controls' with 3 embedded devices. Assign it to a room like any other device. &lt;br /&gt;
&lt;br /&gt;
If you want Vera to be able to use the sensor, click the '+' button next to the device. Check the box &amp;quot;Let Vera manage the associations&amp;quot;. Fill in the 'wakeup interval' box. The sensor is normally asleep to conserve the batteries and will only report the temperature and light reading when it periodically wakes up. This is the frequency of the wakeup. The minimum number you can put in is 360, which means 6 minutes (i.e. 6 minutes * 60 seconds/minute = 360 seconds). At 360, you will get a new light/temperature reading every 6 minutes. However, at this rate, the batteries may only last a couple months. You can instead put in a wakeup interval of, for example, 3600 (i.e. 1 hour) and the batteries will last a lot longer, but the reading Vera has for the current temperature and light may be up to 1 hour old. &lt;br /&gt;
&lt;br /&gt;
When you have specified those settings, save your changes. Wait a minute for Vera to configure the Z-Wave devices and check the color of the cog wheel next to the sensor as explained [[Device Control Status|here]]. If it's green, everything is okay and the sensor will work. If it's red, Vera was not able to configure the sensor because it probably went to sleep already by the time you saved your changes. Go to the sensor and press the blue button. Within a minute or so it should turn green. &lt;br /&gt;
&lt;br /&gt;
If you have difficulty getting the green cog icon, try pressing the blue button on the sensor, then in Vera's device page, click the '+' button for the device and click 'configure right now'. &lt;br /&gt;
&lt;br /&gt;
There are also a few custom configuration settings for the sensor for things like Sensitivity, Timeout Delay, LED Enabled, Light Threshold, and so on. To set them, click the + button next to the device, choose 'Custom Z-Wave Settings', then 'Add configuration setting', put in the variable number that corresponds to the setting you want to change, choose a data size of '1 byte dec' and enter the desired value, as shown below. Then click 'Save'. Vera will attempt to re-configure the sensor. If it fails, probably because the sensor is asleep, you will see the red cog. Press the blue button on the sensor and you should get a green cog meaning the sensor has been configured with your new settings. (See also: [[ZWave Options]])&lt;br /&gt;
== Basic Configuration ==&lt;br /&gt;
=== Wake Up interval ===&lt;br /&gt;
The unit sleeps for the duration of the Wake Up interval, which defaults to 1800 seconds or 30 minutes. When the interval expires, it wakes up and reports Temperature and Luminosity to the Vera. Note that while all 4 devices in the Vera MIOS screen can be configured for Wake Up intervals, only the setting for the '3-in-1 Sensor' has any effect and controls both Temperature and Luminosity intervals. The Motion Sensor is unaffected by the Wakeup Interval (see On Time below)&lt;br /&gt;
&lt;br /&gt;
To set the Wake Up Interval, click on the spanner for the &amp;quot;3-in-1 sensor&amp;quot; device, click on Setting and set Wakeup Interval to the desired interval. &lt;br /&gt;
&lt;br /&gt;
=== On Time ===&lt;br /&gt;
When the Motion Sensor is tripped, it transmits a tripped command and changes its state to Tripped=1 for the duration of the ON TIME variable. After this time has expired, it sends an Untripped command to the Vera and resets it state to Tripped=0. While the device is in a tripped state, any motion detected resets the interval timer but doesn't report a new trip event to the Vera. During the wait time the Motion Sensor device in the Vera will show Tripped=1 in the Advanced tab.&lt;br /&gt;
&lt;br /&gt;
To set the ON TIME, click on the spanner for the &amp;quot;3-in-1 sensor&amp;quot; device, click on Device Options and set variable 2 (On Time) to 5 (or the desired interval in minutes)&lt;br /&gt;
&lt;br /&gt;
'''Direct Association:''' The unit can be associated directly with another device such as a light. If you've done this, the unit will turn the light on when motion is sensed, then turn it off after the ON TIME. According to the sensor's manual up to four associated devices are supported, but associating more than one device does not work (as of Vera's firmware 1.0.900, see http://bugs.micasaverde.com/view.php?id=705).&lt;br /&gt;
&lt;br /&gt;
Leave Parameter #6, &amp;quot;OnValue&amp;quot;, at the default if you want the sensor tripped events in Vera.&lt;br /&gt;
&lt;br /&gt;
=== Example ===&lt;br /&gt;
Consider the following example of how to configure the sensor and the Vera for a common application. Suppose you want to install a motion sensor in your garage to turn the lights on when you enter, keep them on for as long as you move around in the garage, then turn them off 5 minutes after you've left. &lt;br /&gt;
# Put the unit in Test mode by pressing the button on the side&lt;br /&gt;
# Configure the On Time to 5 minutes&lt;br /&gt;
# Create two scenes in Vera:&lt;br /&gt;
## Turn on the light when the unit has tripped (New Scene, Events tab, Add Event, Device=Motion sensor, Type of Event=Armed sensor has tripped, Name=whatever, Tripped=Yes)&lt;br /&gt;
## Turn off the light when the unit sends an untrip command which happens after the On Time interval. (New Scene, Events tab, Add Event, Device=Motion sensor, Type of Event=Armed sensor has tripped, Name=whatever, Tripped=No)&lt;br /&gt;
&lt;br /&gt;
== Advanced Configuration ==&lt;br /&gt;
=== Running from AC Power ===&lt;br /&gt;
==== Overview ====&lt;br /&gt;
It is possible to run the unit from AC power instead of batteries, which will have the following benefits:&lt;br /&gt;
* Allow you to keep the unit awake permanently, allowing you to poll it and customise it without being in Test mode&lt;br /&gt;
* Report continuously every time motion is sensed, as opposed to waiting for the ON TIME duration in between trips&lt;br /&gt;
* Set the unit to report temperature and light levels at higher frequencies up to 1 minute&lt;br /&gt;
* Let the unit act as a Z-Wave repeater, increasing the span of your network&lt;br /&gt;
* Never worry about running down batteries. All of the above options are possible on battery power, but will run your batteries down within a few days&lt;br /&gt;
==== Configure ====&lt;br /&gt;
To do this, you will need to connect a AC to DC transformer that supplies 4.5v to 5v at up to 1amp to the battery terminals directly. Ensure that you measure that actual output voltage of the transformer using a multi/voltage meter (don't rely on its advertised rating). Any over-voltage may fry the unit. Also make sure that the polarity is correct. &lt;br /&gt;
&lt;br /&gt;
'''Setting ''Stay Awake'' to On'''&lt;br /&gt;
By default, the unit is constantly asleep and only wakes up at regular intervals to report the luminosity and temperature, before sleeping again. This is to save batteries. While asleep, the unit cannot be programmed from the Vera and cannot be polled for information. To get around this, one normally activates the Test mode by pressing the button on the side of the unit, which keeps it awake for 10 minutes so that it can be programmed. By setting the unit to stay awake constantly, you can program, poll or configure it at any time. It also has the side effect of enabling the unit to become a repeater of Z Wave signals throughout the network.&lt;br /&gt;
&lt;br /&gt;
To set it, click on the spanner for the &amp;quot;3-in-1 sensor&amp;quot; device, click on Device Options and set variable 5 (Stay Awake) to 1 or any number greater than 0.&lt;br /&gt;
&lt;br /&gt;
'''Setting ''On Time'' to ''Always Fire'''''&lt;br /&gt;
When the unit detects motion, it reports it by sending a Tripped command to the Vera. It then waits for the duration of the On Time and then sends un Untripped command to the Vera and waits for the next motion. Since battery life is not a consideration while on AC power, you can set it to 'Always Fire', which sends a Tripped command whenever motion is detected with no waiting period. Note, this will also prevent an Untripped command from being sent.&lt;br /&gt;
&lt;br /&gt;
To set it, click on the spanner for the &amp;quot;3-in-1 sensor&amp;quot; device, click on Device Options and set variable 2 (On Time) to 0.&lt;br /&gt;
&lt;br /&gt;
'''Excluding and Reincluding the unit'''&lt;br /&gt;
To activate these new settings, you will need to exclude and reinclude the unit using the standard Vera process. Remember to save your settings first.  &lt;br /&gt;
&lt;br /&gt;
''' Setting Poll frequency'''&lt;br /&gt;
The unit usually only reports temperate and luminosity every time it wakes up, but since the unit is now constantly awake, you will have to configure a poll frequency to gather that information.&lt;br /&gt;
&lt;br /&gt;
To set it, click on the spanner for the &amp;quot;Motion Sensor&amp;quot; device, click on Settings and set &amp;quot;Poll this node at most every&amp;quot; to the required update frequency. The Wakeup interval setting on this same screen has no effect since it's been overridden by Always Awake setting.&lt;br /&gt;
&lt;br /&gt;
== Known issues ==&lt;/div&gt;</summary>
		<author><name>Solipsia</name></author>	</entry>

	<entry>
		<id>http://wiki.mios.com/index.php/ExpressControls3in1</id>
		<title>ExpressControls3in1</title>
		<link rel="alternate" type="text/html" href="http://wiki.mios.com/index.php/ExpressControls3in1"/>
				<updated>2011-02-19T15:11:44Z</updated>
		
		<summary type="html">&lt;p&gt;Solipsia: /* On Time */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Hardware]]&lt;br /&gt;
[[Category:Plugins]]&lt;br /&gt;
[[Category:3rd Party]]&lt;br /&gt;
&lt;br /&gt;
== Overview ==&lt;br /&gt;
This unit is functionally identical to the HomeSeer HSM100 device. The user's manual is here: http://www.expresscontrols.com/pdf/EZMotionOwnerManual.pdf &lt;br /&gt;
&lt;br /&gt;
You can add an [[Event]] to your [[Scenes]] 'sensor tripped' or 'armed sensor is tripped' so the scene is executed when the motion sensor is tripped. (See also [[Intro Security]].) You can see the current temperature and light level on Vera's dashboard or on the mobile phone interface. &lt;br /&gt;
&lt;br /&gt;
To pair the sensor with Vera (i.e. add it to Vera's Z-Wave network), bring Vera's dongle near the sensor as you would pair any device, and press the blue button on the 3-in-1 sensor. Reconnect Vera's Z-Wave dongle. &lt;br /&gt;
&lt;br /&gt;
Vera needs to communicate with the sensor to identify what type of device it is and configure it. But the sensor will only talk to Vera within a minute of pressing the blue button. After re-connecting Vera's Z-Wave dongle, wait 60 seconds, and if the sensor shows up as 'Generic IO', go press the blue button again, and again wait 60 seconds. Vera should show it as an 'Express Controls' with 3 embedded devices. Assign it to a room like any other device. &lt;br /&gt;
&lt;br /&gt;
If you want Vera to be able to use the sensor, click the '+' button next to the device. Check the box &amp;quot;Let Vera manage the associations&amp;quot;. Fill in the 'wakeup interval' box. The sensor is normally asleep to conserve the batteries and will only report the temperature and light reading when it periodically wakes up. This is the frequency of the wakeup. The minimum number you can put in is 360, which means 6 minutes (i.e. 6 minutes * 60 seconds/minute = 360 seconds). At 360, you will get a new light/temperature reading every 6 minutes. However, at this rate, the batteries may only last a couple months. You can instead put in a wakeup interval of, for example, 3600 (i.e. 1 hour) and the batteries will last a lot longer, but the reading Vera has for the current temperature and light may be up to 1 hour old. &lt;br /&gt;
&lt;br /&gt;
When you have specified those settings, save your changes. Wait a minute for Vera to configure the Z-Wave devices and check the color of the cog wheel next to the sensor as explained [[Device Control Status|here]]. If it's green, everything is okay and the sensor will work. If it's red, Vera was not able to configure the sensor because it probably went to sleep already by the time you saved your changes. Go to the sensor and press the blue button. Within a minute or so it should turn green. &lt;br /&gt;
&lt;br /&gt;
If you have difficulty getting the green cog icon, try pressing the blue button on the sensor, then in Vera's device page, click the '+' button for the device and click 'configure right now'. &lt;br /&gt;
&lt;br /&gt;
There are also a few custom configuration settings for the sensor for things like Sensitivity, Timeout Delay, LED Enabled, Light Threshold, and so on. To set them, click the + button next to the device, choose 'Custom Z-Wave Settings', then 'Add configuration setting', put in the variable number that corresponds to the setting you want to change, choose a data size of '1 byte dec' and enter the desired value, as shown below. Then click 'Save'. Vera will attempt to re-configure the sensor. If it fails, probably because the sensor is asleep, you will see the red cog. Press the blue button on the sensor and you should get a green cog meaning the sensor has been configured with your new settings. (See also: [[ZWave Options]])&lt;br /&gt;
== Basic Configuration ==&lt;br /&gt;
=== Wake Up interval ===&lt;br /&gt;
The unit sleeps for the duration of the Wake Up interval, which defaults to 1800 seconds or 30 minutes. When the interval expires, it wakes up and reports Temperature and Luminosity to the Vera. Note that while all 4 devices in the Vera MIOS screen can be configured for Wake Up intervals, only the setting for the '3-in-1 Sensor' has any effect and controls both Temperature and Luminosity intervals. The Motion Sensor is unaffected by the Wakeup Interval (see On Time below)&lt;br /&gt;
&lt;br /&gt;
To set the Wake Up Interval, click on the spanner for the &amp;quot;3-in-1 sensor&amp;quot; device, click on Setting and set Wakeup Interval to the desired interval. &lt;br /&gt;
&lt;br /&gt;
=== On Time ===&lt;br /&gt;
When the Motion Sensor is tripped, it transmits a tripped command and changes its state to Tripped=1 for the duration of the ON TIME variable. After this time has expired, it sends an Untripped command to the Vera and resets it state to Tripped=0. While the device is in a tripped state, any motion detected resets the interval timer but doesn't report a new trip event to the Vera. During the wait time the Motion Sensor device in the Vera will show Tripped=1 in the Advanced tab.&lt;br /&gt;
&lt;br /&gt;
To set the ON TIME, click on the spanner for the &amp;quot;3-in-1 sensor&amp;quot; device, click on Device Options and set variable 2 (On Time) to 5 (or the desired interval in minutes)&lt;br /&gt;
&lt;br /&gt;
'''Direct Association:''' The unit can be associated directly with another device such as a light. If you've done this, the unit will turn the light on when motion is sensed, then turn it off after the ON TIME. According to the sensor's manual up to four associated devices are supported, but associating more than one device does not work (as of Vera's firmware 1.0.900, see http://bugs.micasaverde.com/view.php?id=705).&lt;br /&gt;
&lt;br /&gt;
Leave Parameter #6, &amp;quot;OnValue&amp;quot;, at the default if you want the sensor tripped events in Vera.&lt;br /&gt;
&lt;br /&gt;
=== Example ===&lt;br /&gt;
Consider the following example of how to configure the sensor and the Vera for a common application. Suppose you want to install a motion sensor in your garage to turn the lights on when you enter, keep them on for as long as you move around in the garage, then turn them off 5 minutes after you've left. &lt;br /&gt;
# Put the unit in Test mode by pressing the button on the side&lt;br /&gt;
# Configure the On Time to 5 minutes&lt;br /&gt;
# Create two scenes in Vera:&lt;br /&gt;
## Turn on the light when the unit has tripped (New Scene, Events tab, Add Event, Device=Motion sensor, Type of Event=Armed sensor has tripped, Name=whatever, Tripped=Yes)&lt;br /&gt;
## Turn off the light when the unit sends an untrip command which happens after the On Time interval. (New Scene, Events tab, Add Event, Device=Motion sensor, Type of Event=Armed sensor has tripped, Name=whatever, Tripped=No)&lt;br /&gt;
&lt;br /&gt;
== Advanced Configuration ==&lt;br /&gt;
=== Running from AC Power ===&lt;br /&gt;
==== Overview ====&lt;br /&gt;
It is possible to run the unit from AC power instead of batteries, which will have the following benefits:&lt;br /&gt;
* Allow you to keep the unit awake permanently, allowing you to poll it and customise it without being in Test mode&lt;br /&gt;
* Report continuously every time motion is sensed, as opposed to waiting for the ON TIME duration in between trips&lt;br /&gt;
* Set the unit to report temperature and light levels at higher frequencies up to 1 minute&lt;br /&gt;
* Let the unit act as a Z-Wave repeater, increasing the span of your network&lt;br /&gt;
* Never worry about running down batteries. All of the above options are possible on battery power, but will run your batteries down within a few days&lt;br /&gt;
==== Configure ====&lt;br /&gt;
To do this, you will need to connect a AC to DC transformer that supplies 4.5v to 5v at up to 1amp to the battery terminals directly. Ensure that you measure that actual output voltage of the transformer using a multi/voltage meter (don't rely on its advertised rating). Any over-voltage may fry the unit. Also make sure that the polarity is correct. &lt;br /&gt;
&lt;br /&gt;
'''Setting ''Stay Awake'' to On'''&lt;br /&gt;
By default, the unit is constantly asleep and only wakes up at regular intervals to report the luminosity and temperature, before sleeping again. This is to save batteries. While asleep, the unit cannot be programmed from the Vera and cannot be polled for information. To get around this, one normally activates the Test mode by pressing the button on the side of the unit, which keeps it awake for 10 minutes so that it can be programmed. By setting the unit to stay awake constantly, you can program, poll or configure it at any time. It also has the side effect of enabling the unit to become a repeater of Z Wave signals throughout the network.&lt;br /&gt;
&lt;br /&gt;
To set it, click on the spanner for the &amp;quot;3-in-1 sensor&amp;quot; device, click on Device Options and set variable 5 (Stay Awake) to 1 or any number greater than 0.&lt;br /&gt;
&lt;br /&gt;
'''Setting ''On Time'' to ''Always Fire'''''&lt;br /&gt;
When the unit detects motion, it reports it by sending a Tripped command to the Vera. It then ignores any motion for the duration of the 'On Time' variable, after which it sends un Untripped command to the Vera and waits for the next motion. Since battery life is not a consideration while on AC power, you can set it to 'Always Fire', which sends a Tripped command whenever motion is detected with no waiting period. Note, this will also prevent an Untripped command from being sent.&lt;br /&gt;
&lt;br /&gt;
To set it, click on the spanner for the &amp;quot;3-in-1 sensor&amp;quot; device, click on Device Options and set variable 2 (On Time) to 0.&lt;br /&gt;
&lt;br /&gt;
'''Excluding and Reincluding the unit'''&lt;br /&gt;
To activate these new settings, you will need to exclude and reinclude the unit using the standard Vera process. Remember to save your settings first.  &lt;br /&gt;
&lt;br /&gt;
''' Setting Poll frequency'''&lt;br /&gt;
The unit usually only reports temperate and luminosity every time it wakes up, but since the unit is now constantly awake, you will have to configure a poll frequency to gather that information.&lt;br /&gt;
&lt;br /&gt;
To set it, click on the spanner for the &amp;quot;Motion Sensor&amp;quot; device, click on Settings and set &amp;quot;Poll this node at most every&amp;quot; to the required update frequency. The Wakeup interval setting on this same screen has no effect since it's been overridden by Always Awake setting.&lt;br /&gt;
&lt;br /&gt;
== Known issues ==&lt;/div&gt;</summary>
		<author><name>Solipsia</name></author>	</entry>

	<entry>
		<id>http://wiki.mios.com/index.php/ExpressControls3in1</id>
		<title>ExpressControls3in1</title>
		<link rel="alternate" type="text/html" href="http://wiki.mios.com/index.php/ExpressControls3in1"/>
				<updated>2011-02-19T15:10:03Z</updated>
		
		<summary type="html">&lt;p&gt;Solipsia: /* Basic Configuration */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Hardware]]&lt;br /&gt;
[[Category:Plugins]]&lt;br /&gt;
[[Category:3rd Party]]&lt;br /&gt;
&lt;br /&gt;
== Overview ==&lt;br /&gt;
This unit is functionally identical to the HomeSeer HSM100 device. The user's manual is here: http://www.expresscontrols.com/pdf/EZMotionOwnerManual.pdf &lt;br /&gt;
&lt;br /&gt;
You can add an [[Event]] to your [[Scenes]] 'sensor tripped' or 'armed sensor is tripped' so the scene is executed when the motion sensor is tripped. (See also [[Intro Security]].) You can see the current temperature and light level on Vera's dashboard or on the mobile phone interface. &lt;br /&gt;
&lt;br /&gt;
To pair the sensor with Vera (i.e. add it to Vera's Z-Wave network), bring Vera's dongle near the sensor as you would pair any device, and press the blue button on the 3-in-1 sensor. Reconnect Vera's Z-Wave dongle. &lt;br /&gt;
&lt;br /&gt;
Vera needs to communicate with the sensor to identify what type of device it is and configure it. But the sensor will only talk to Vera within a minute of pressing the blue button. After re-connecting Vera's Z-Wave dongle, wait 60 seconds, and if the sensor shows up as 'Generic IO', go press the blue button again, and again wait 60 seconds. Vera should show it as an 'Express Controls' with 3 embedded devices. Assign it to a room like any other device. &lt;br /&gt;
&lt;br /&gt;
If you want Vera to be able to use the sensor, click the '+' button next to the device. Check the box &amp;quot;Let Vera manage the associations&amp;quot;. Fill in the 'wakeup interval' box. The sensor is normally asleep to conserve the batteries and will only report the temperature and light reading when it periodically wakes up. This is the frequency of the wakeup. The minimum number you can put in is 360, which means 6 minutes (i.e. 6 minutes * 60 seconds/minute = 360 seconds). At 360, you will get a new light/temperature reading every 6 minutes. However, at this rate, the batteries may only last a couple months. You can instead put in a wakeup interval of, for example, 3600 (i.e. 1 hour) and the batteries will last a lot longer, but the reading Vera has for the current temperature and light may be up to 1 hour old. &lt;br /&gt;
&lt;br /&gt;
When you have specified those settings, save your changes. Wait a minute for Vera to configure the Z-Wave devices and check the color of the cog wheel next to the sensor as explained [[Device Control Status|here]]. If it's green, everything is okay and the sensor will work. If it's red, Vera was not able to configure the sensor because it probably went to sleep already by the time you saved your changes. Go to the sensor and press the blue button. Within a minute or so it should turn green. &lt;br /&gt;
&lt;br /&gt;
If you have difficulty getting the green cog icon, try pressing the blue button on the sensor, then in Vera's device page, click the '+' button for the device and click 'configure right now'. &lt;br /&gt;
&lt;br /&gt;
There are also a few custom configuration settings for the sensor for things like Sensitivity, Timeout Delay, LED Enabled, Light Threshold, and so on. To set them, click the + button next to the device, choose 'Custom Z-Wave Settings', then 'Add configuration setting', put in the variable number that corresponds to the setting you want to change, choose a data size of '1 byte dec' and enter the desired value, as shown below. Then click 'Save'. Vera will attempt to re-configure the sensor. If it fails, probably because the sensor is asleep, you will see the red cog. Press the blue button on the sensor and you should get a green cog meaning the sensor has been configured with your new settings. (See also: [[ZWave Options]])&lt;br /&gt;
== Basic Configuration ==&lt;br /&gt;
=== Wake Up interval ===&lt;br /&gt;
The unit sleeps for the duration of the Wake Up interval, which defaults to 1800 seconds or 30 minutes. When the interval expires, it wakes up and reports Temperature and Luminosity to the Vera. Note that while all 4 devices in the Vera MIOS screen can be configured for Wake Up intervals, only the setting for the '3-in-1 Sensor' has any effect and controls both Temperature and Luminosity intervals. The Motion Sensor is unaffected by the Wakeup Interval (see On Time below)&lt;br /&gt;
&lt;br /&gt;
To set the Wake Up Interval, click on the spanner for the &amp;quot;3-in-1 sensor&amp;quot; device, click on Setting and set Wakeup Interval to the desired interval. &lt;br /&gt;
&lt;br /&gt;
=== On Time ===&lt;br /&gt;
When the Motion Sensor is tripped, it transmits a tripped command and changes its state to Tripped=1 for the duration of the ON TIME variable. After this time has expired, it sends an Untripped command to the Vera and resets it state to Tripped=0. While it is Tripped=1, it ignores any motion. During this wait time the Motion Sensor device in the Vera will show Tripped=1 in the Advanced tab.&lt;br /&gt;
&lt;br /&gt;
To set the ON TIME, click on the spanner for the &amp;quot;3-in-1 sensor&amp;quot; device, click on Device Options and set variable 2 (On Time) to 5 (or the desired interval in minutes)&lt;br /&gt;
&lt;br /&gt;
'''Direct Association:''' The unit can be associated directly with another device such as a light. If you've done this, the unit will turn the light on when motion is sensed, then turn it off after the ON TIME. According to the sensor's manual up to four associated devices are supported, but associating more than one device does not work (as of Vera's firmware 1.0.900, see http://bugs.micasaverde.com/view.php?id=705).&lt;br /&gt;
&lt;br /&gt;
Leave Parameter #6, &amp;quot;OnValue&amp;quot;, at the default if you want the sensor tripped events in Vera.&lt;br /&gt;
&lt;br /&gt;
=== Example ===&lt;br /&gt;
Consider the following example of how to configure the sensor and the Vera for a common application. Suppose you want to install a motion sensor in your garage to turn the lights on when you enter, keep them on for as long as you move around in the garage, then turn them off 5 minutes after you've left. &lt;br /&gt;
# Put the unit in Test mode by pressing the button on the side&lt;br /&gt;
# Configure the On Time to 5 minutes&lt;br /&gt;
# Create two scenes in Vera:&lt;br /&gt;
## Turn on the light when the unit has tripped (New Scene, Events tab, Add Event, Device=Motion sensor, Type of Event=Armed sensor has tripped, Name=whatever, Tripped=Yes)&lt;br /&gt;
## Turn off the light when the unit sends an untrip command which happens after the On Time interval. (New Scene, Events tab, Add Event, Device=Motion sensor, Type of Event=Armed sensor has tripped, Name=whatever, Tripped=No)&lt;br /&gt;
&lt;br /&gt;
== Advanced Configuration ==&lt;br /&gt;
=== Running from AC Power ===&lt;br /&gt;
==== Overview ====&lt;br /&gt;
It is possible to run the unit from AC power instead of batteries, which will have the following benefits:&lt;br /&gt;
* Allow you to keep the unit awake permanently, allowing you to poll it and customise it without being in Test mode&lt;br /&gt;
* Report continuously every time motion is sensed, as opposed to waiting for the ON TIME duration in between trips&lt;br /&gt;
* Set the unit to report temperature and light levels at higher frequencies up to 1 minute&lt;br /&gt;
* Let the unit act as a Z-Wave repeater, increasing the span of your network&lt;br /&gt;
* Never worry about running down batteries. All of the above options are possible on battery power, but will run your batteries down within a few days&lt;br /&gt;
==== Configure ====&lt;br /&gt;
To do this, you will need to connect a AC to DC transformer that supplies 4.5v to 5v at up to 1amp to the battery terminals directly. Ensure that you measure that actual output voltage of the transformer using a multi/voltage meter (don't rely on its advertised rating). Any over-voltage may fry the unit. Also make sure that the polarity is correct. &lt;br /&gt;
&lt;br /&gt;
'''Setting ''Stay Awake'' to On'''&lt;br /&gt;
By default, the unit is constantly asleep and only wakes up at regular intervals to report the luminosity and temperature, before sleeping again. This is to save batteries. While asleep, the unit cannot be programmed from the Vera and cannot be polled for information. To get around this, one normally activates the Test mode by pressing the button on the side of the unit, which keeps it awake for 10 minutes so that it can be programmed. By setting the unit to stay awake constantly, you can program, poll or configure it at any time. It also has the side effect of enabling the unit to become a repeater of Z Wave signals throughout the network.&lt;br /&gt;
&lt;br /&gt;
To set it, click on the spanner for the &amp;quot;3-in-1 sensor&amp;quot; device, click on Device Options and set variable 5 (Stay Awake) to 1 or any number greater than 0.&lt;br /&gt;
&lt;br /&gt;
'''Setting ''On Time'' to ''Always Fire'''''&lt;br /&gt;
When the unit detects motion, it reports it by sending a Tripped command to the Vera. It then ignores any motion for the duration of the 'On Time' variable, after which it sends un Untripped command to the Vera and waits for the next motion. Since battery life is not a consideration while on AC power, you can set it to 'Always Fire', which sends a Tripped command whenever motion is detected with no waiting period. Note, this will also prevent an Untripped command from being sent.&lt;br /&gt;
&lt;br /&gt;
To set it, click on the spanner for the &amp;quot;3-in-1 sensor&amp;quot; device, click on Device Options and set variable 2 (On Time) to 0.&lt;br /&gt;
&lt;br /&gt;
'''Excluding and Reincluding the unit'''&lt;br /&gt;
To activate these new settings, you will need to exclude and reinclude the unit using the standard Vera process. Remember to save your settings first.  &lt;br /&gt;
&lt;br /&gt;
''' Setting Poll frequency'''&lt;br /&gt;
The unit usually only reports temperate and luminosity every time it wakes up, but since the unit is now constantly awake, you will have to configure a poll frequency to gather that information.&lt;br /&gt;
&lt;br /&gt;
To set it, click on the spanner for the &amp;quot;Motion Sensor&amp;quot; device, click on Settings and set &amp;quot;Poll this node at most every&amp;quot; to the required update frequency. The Wakeup interval setting on this same screen has no effect since it's been overridden by Always Awake setting.&lt;br /&gt;
&lt;br /&gt;
== Known issues ==&lt;/div&gt;</summary>
		<author><name>Solipsia</name></author>	</entry>

	<entry>
		<id>http://wiki.mios.com/index.php/ExpressControls3in1</id>
		<title>ExpressControls3in1</title>
		<link rel="alternate" type="text/html" href="http://wiki.mios.com/index.php/ExpressControls3in1"/>
				<updated>2011-02-19T14:56:07Z</updated>
		
		<summary type="html">&lt;p&gt;Solipsia: /* Basic Configuration */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Hardware]]&lt;br /&gt;
[[Category:Plugins]]&lt;br /&gt;
[[Category:3rd Party]]&lt;br /&gt;
&lt;br /&gt;
== Overview ==&lt;br /&gt;
This unit is functionally identical to the HomeSeer HSM100 device. The user's manual is here: http://www.expresscontrols.com/pdf/EZMotionOwnerManual.pdf &lt;br /&gt;
&lt;br /&gt;
You can add an [[Event]] to your [[Scenes]] 'sensor tripped' or 'armed sensor is tripped' so the scene is executed when the motion sensor is tripped. (See also [[Intro Security]].) You can see the current temperature and light level on Vera's dashboard or on the mobile phone interface. &lt;br /&gt;
&lt;br /&gt;
To pair the sensor with Vera (i.e. add it to Vera's Z-Wave network), bring Vera's dongle near the sensor as you would pair any device, and press the blue button on the 3-in-1 sensor. Reconnect Vera's Z-Wave dongle. &lt;br /&gt;
&lt;br /&gt;
Vera needs to communicate with the sensor to identify what type of device it is and configure it. But the sensor will only talk to Vera within a minute of pressing the blue button. After re-connecting Vera's Z-Wave dongle, wait 60 seconds, and if the sensor shows up as 'Generic IO', go press the blue button again, and again wait 60 seconds. Vera should show it as an 'Express Controls' with 3 embedded devices. Assign it to a room like any other device. &lt;br /&gt;
&lt;br /&gt;
If you want Vera to be able to use the sensor, click the '+' button next to the device. Check the box &amp;quot;Let Vera manage the associations&amp;quot;. Fill in the 'wakeup interval' box. The sensor is normally asleep to conserve the batteries and will only report the temperature and light reading when it periodically wakes up. This is the frequency of the wakeup. The minimum number you can put in is 360, which means 6 minutes (i.e. 6 minutes * 60 seconds/minute = 360 seconds). At 360, you will get a new light/temperature reading every 6 minutes. However, at this rate, the batteries may only last a couple months. You can instead put in a wakeup interval of, for example, 3600 (i.e. 1 hour) and the batteries will last a lot longer, but the reading Vera has for the current temperature and light may be up to 1 hour old. &lt;br /&gt;
&lt;br /&gt;
When you have specified those settings, save your changes. Wait a minute for Vera to configure the Z-Wave devices and check the color of the cog wheel next to the sensor as explained [[Device Control Status|here]]. If it's green, everything is okay and the sensor will work. If it's red, Vera was not able to configure the sensor because it probably went to sleep already by the time you saved your changes. Go to the sensor and press the blue button. Within a minute or so it should turn green. &lt;br /&gt;
&lt;br /&gt;
If you have difficulty getting the green cog icon, try pressing the blue button on the sensor, then in Vera's device page, click the '+' button for the device and click 'configure right now'. &lt;br /&gt;
&lt;br /&gt;
There are also a few custom configuration settings for the sensor for things like Sensitivity, Timeout Delay, LED Enabled, Light Threshold, and so on. To set them, click the + button next to the device, choose 'Custom Z-Wave Settings', then 'Add configuration setting', put in the variable number that corresponds to the setting you want to change, choose a data size of '1 byte dec' and enter the desired value, as shown below. Then click 'Save'. Vera will attempt to re-configure the sensor. If it fails, probably because the sensor is asleep, you will see the red cog. Press the blue button on the sensor and you should get a green cog meaning the sensor has been configured with your new settings. (See also: [[ZWave Options]])&lt;br /&gt;
== Basic Configuration ==&lt;br /&gt;
=== Wake Up interval ===&lt;br /&gt;
The unit sleeps for the duration of the Wake Up interval, which defaults to 1800 seconds or 30 minutes. When the interval expires, it wakes up and reports Temperature and Luminosity to the Vera. Note that while all 4 devices in the Vera MIOS screen can be configured for Wake Up intervals, only the setting for the '3-in-1 Sensor' has any effect and controls both Temperature and Luminosity intervals. The Motion Sensor is unaffected by the Wakeup Interval (see On Time below)&lt;br /&gt;
&lt;br /&gt;
To set the Wake Up Interval, click on the spanner for the &amp;quot;3-in-1 sensor&amp;quot; device, click on Setting and set Wakeup Interval to the desired interval. &lt;br /&gt;
&lt;br /&gt;
=== On Time ===&lt;br /&gt;
When the Motion Sensor is tripped, it transmits a tripped command and changes its state to Tripped=1 for the duration of the ON TIME variable. After this time has expired, it sends an Untripped command to the Vera and resets it state to Tripped=0. While it is Tripped=1, it ignores any motion. During this wait time the Motion Sensor device in the Vera will show Tripped=1 in the Advanced tab.&lt;br /&gt;
&lt;br /&gt;
To set the ON TIME, click on the spanner for the &amp;quot;3-in-1 sensor&amp;quot; device, click on Device Options and set variable 2 (On Time) to 5 (or the desired interval in minutes)&lt;br /&gt;
&lt;br /&gt;
'''Direct Association:''' The unit can be associated directly with another device such as a light. If you've done this, the unit will turn the light on when motion is sensed, then turn it off after the ON TIME. According to the sensor's manual up to four associated devices are supported, but associating more than one device does not work (as of Vera's firmware 1.0.900, see http://bugs.micasaverde.com/view.php?id=705).&lt;br /&gt;
&lt;br /&gt;
Leave Parameter #6, &amp;quot;OnValue&amp;quot;, at the default if you want the sensor tripped events in Vera.&lt;br /&gt;
&lt;br /&gt;
== Advanced Configuration ==&lt;br /&gt;
=== Running from AC Power ===&lt;br /&gt;
==== Overview ====&lt;br /&gt;
It is possible to run the unit from AC power instead of batteries, which will have the following benefits:&lt;br /&gt;
* Allow you to keep the unit awake permanently, allowing you to poll it and customise it without being in Test mode&lt;br /&gt;
* Report continuously every time motion is sensed, as opposed to waiting for the ON TIME duration in between trips&lt;br /&gt;
* Set the unit to report temperature and light levels at higher frequencies up to 1 minute&lt;br /&gt;
* Let the unit act as a Z-Wave repeater, increasing the span of your network&lt;br /&gt;
* Never worry about running down batteries. All of the above options are possible on battery power, but will run your batteries down within a few days&lt;br /&gt;
==== Configure ====&lt;br /&gt;
To do this, you will need to connect a AC to DC transformer that supplies 4.5v to 5v at up to 1amp to the battery terminals directly. Ensure that you measure that actual output voltage of the transformer using a multi/voltage meter (don't rely on its advertised rating). Any over-voltage may fry the unit. Also make sure that the polarity is correct. &lt;br /&gt;
&lt;br /&gt;
'''Setting ''Stay Awake'' to On'''&lt;br /&gt;
By default, the unit is constantly asleep and only wakes up at regular intervals to report the luminosity and temperature, before sleeping again. This is to save batteries. While asleep, the unit cannot be programmed from the Vera and cannot be polled for information. To get around this, one normally activates the Test mode by pressing the button on the side of the unit, which keeps it awake for 10 minutes so that it can be programmed. By setting the unit to stay awake constantly, you can program, poll or configure it at any time. It also has the side effect of enabling the unit to become a repeater of Z Wave signals throughout the network.&lt;br /&gt;
&lt;br /&gt;
To set it, click on the spanner for the &amp;quot;3-in-1 sensor&amp;quot; device, click on Device Options and set variable 5 (Stay Awake) to 1 or any number greater than 0.&lt;br /&gt;
&lt;br /&gt;
'''Setting ''On Time'' to ''Always Fire'''''&lt;br /&gt;
When the unit detects motion, it reports it by sending a Tripped command to the Vera. It then ignores any motion for the duration of the 'On Time' variable, after which it sends un Untripped command to the Vera and waits for the next motion. Since battery life is not a consideration while on AC power, you can set it to 'Always Fire', which sends a Tripped command whenever motion is detected with no waiting period. Note, this will also prevent an Untripped command from being sent.&lt;br /&gt;
&lt;br /&gt;
To set it, click on the spanner for the &amp;quot;3-in-1 sensor&amp;quot; device, click on Device Options and set variable 2 (On Time) to 0.&lt;br /&gt;
&lt;br /&gt;
'''Excluding and Reincluding the unit'''&lt;br /&gt;
To activate these new settings, you will need to exclude and reinclude the unit using the standard Vera process. Remember to save your settings first.  &lt;br /&gt;
&lt;br /&gt;
''' Setting Poll frequency'''&lt;br /&gt;
The unit usually only reports temperate and luminosity every time it wakes up, but since the unit is now constantly awake, you will have to configure a poll frequency to gather that information.&lt;br /&gt;
&lt;br /&gt;
To set it, click on the spanner for the &amp;quot;Motion Sensor&amp;quot; device, click on Settings and set &amp;quot;Poll this node at most every&amp;quot; to the required update frequency. The Wakeup interval setting on this same screen has no effect since it's been overridden by Always Awake setting.&lt;br /&gt;
&lt;br /&gt;
== Known issues ==&lt;/div&gt;</summary>
		<author><name>Solipsia</name></author>	</entry>

	<entry>
		<id>http://wiki.mios.com/index.php/ExpressControls3in1</id>
		<title>ExpressControls3in1</title>
		<link rel="alternate" type="text/html" href="http://wiki.mios.com/index.php/ExpressControls3in1"/>
				<updated>2011-02-19T14:47:20Z</updated>
		
		<summary type="html">&lt;p&gt;Solipsia: Major work on the AC Power section and minor rework elsewhere&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Hardware]]&lt;br /&gt;
[[Category:Plugins]]&lt;br /&gt;
[[Category:3rd Party]]&lt;br /&gt;
&lt;br /&gt;
== Overview ==&lt;br /&gt;
This unit is functionally identical to the HomeSeer HSM100 device. The user's manual is here: http://www.expresscontrols.com/pdf/EZMotionOwnerManual.pdf &lt;br /&gt;
&lt;br /&gt;
You can add an [[Event]] to your [[Scenes]] 'sensor tripped' or 'armed sensor is tripped' so the scene is executed when the motion sensor is tripped. (See also [[Intro Security]].) You can see the current temperature and light level on Vera's dashboard or on the mobile phone interface. &lt;br /&gt;
&lt;br /&gt;
To pair the sensor with Vera (i.e. add it to Vera's Z-Wave network), bring Vera's dongle near the sensor as you would pair any device, and press the blue button on the 3-in-1 sensor. Reconnect Vera's Z-Wave dongle. &lt;br /&gt;
&lt;br /&gt;
Vera needs to communicate with the sensor to identify what type of device it is and configure it. But the sensor will only talk to Vera within a minute of pressing the blue button. After re-connecting Vera's Z-Wave dongle, wait 60 seconds, and if the sensor shows up as 'Generic IO', go press the blue button again, and again wait 60 seconds. Vera should show it as an 'Express Controls' with 3 embedded devices. Assign it to a room like any other device. &lt;br /&gt;
&lt;br /&gt;
If you want Vera to be able to use the sensor, click the '+' button next to the device. Check the box &amp;quot;Let Vera manage the associations&amp;quot;. Fill in the 'wakeup interval' box. The sensor is normally asleep to conserve the batteries and will only report the temperature and light reading when it periodically wakes up. This is the frequency of the wakeup. The minimum number you can put in is 360, which means 6 minutes (i.e. 6 minutes * 60 seconds/minute = 360 seconds). At 360, you will get a new light/temperature reading every 6 minutes. However, at this rate, the batteries may only last a couple months. You can instead put in a wakeup interval of, for example, 3600 (i.e. 1 hour) and the batteries will last a lot longer, but the reading Vera has for the current temperature and light may be up to 1 hour old. &lt;br /&gt;
&lt;br /&gt;
When you have specified those settings, save your changes. Wait a minute for Vera to configure the Z-Wave devices and check the color of the cog wheel next to the sensor as explained [[Device Control Status|here]]. If it's green, everything is okay and the sensor will work. If it's red, Vera was not able to configure the sensor because it probably went to sleep already by the time you saved your changes. Go to the sensor and press the blue button. Within a minute or so it should turn green. &lt;br /&gt;
&lt;br /&gt;
If you have difficulty getting the green cog icon, try pressing the blue button on the sensor, then in Vera's device page, click the '+' button for the device and click 'configure right now'. &lt;br /&gt;
&lt;br /&gt;
There are also a few custom configuration settings for the sensor for things like Sensitivity, Timeout Delay, LED Enabled, Light Threshold, and so on. To set them, click the + button next to the device, choose 'Custom Z-Wave Settings', then 'Add configuration setting', put in the variable number that corresponds to the setting you want to change, choose a data size of '1 byte dec' and enter the desired value, as shown below. Then click 'Save'. Vera will attempt to re-configure the sensor. If it fails, probably because the sensor is asleep, you will see the red cog. Press the blue button on the sensor and you should get a green cog meaning the sensor has been configured with your new settings. (See also: [[ZWave Options]])&lt;br /&gt;
== Basic Configuration ==&lt;br /&gt;
&lt;br /&gt;
=== On Time ===&lt;br /&gt;
When the Motion Sensor is tripped, it transmits a tripped command and changes its state to Tripped=1 for the duration of the ON TIME variable. After this time has expired, it sends an Untripped command to the Vera and resets it state to Tripped=0. While it is Tripped=1, it ignores any motion. During this wait time the Motion Sensor device in the Vera will show Tripped=1 in the Advanced tab.&lt;br /&gt;
&lt;br /&gt;
To set the ON TIME, click on the spanner for the &amp;quot;3-in-1 sensor&amp;quot; device, click on Device Options and set variable 2 (On Time) to 5 (or the desired interval in minutes)&lt;br /&gt;
&lt;br /&gt;
'''Direct Association:''' The unit can be associated directly with another device such as a light. If you've done this, the unit will turn the light on when motion is sensed, then turn it off after the ON TIME. According to the sensor's manual up to four associated devices are supported, but associating more than one device does not work (as of Vera's firmware 1.0.900, see http://bugs.micasaverde.com/view.php?id=705).&lt;br /&gt;
&lt;br /&gt;
Leave Parameter #6, &amp;quot;OnValue&amp;quot;, at the default if you want the sensor tripped events in Vera.&lt;br /&gt;
&lt;br /&gt;
== Advanced Configuration ==&lt;br /&gt;
=== Running from AC Power ===&lt;br /&gt;
==== Overview ====&lt;br /&gt;
It is possible to run the unit from AC power instead of batteries, which will have the following benefits:&lt;br /&gt;
* Allow you to keep the unit awake permanently, allowing you to poll it and customise it without being in Test mode&lt;br /&gt;
* Report continuously every time motion is sensed, as opposed to waiting for the ON TIME duration in between trips&lt;br /&gt;
* Set the unit to report temperature and light levels at higher frequencies up to 1 minute&lt;br /&gt;
* Let the unit act as a Z-Wave repeater, increasing the span of your network&lt;br /&gt;
* Never worry about running down batteries. All of the above options are possible on battery power, but will run your batteries down within a few days&lt;br /&gt;
==== Configure ====&lt;br /&gt;
To do this, you will need to connect a AC to DC transformer that supplies 4.5v to 5v at up to 1amp to the battery terminals directly. Ensure that you measure that actual output voltage of the transformer using a multi/voltage meter (don't rely on its advertised rating). Any over-voltage may fry the unit. Also make sure that the polarity is correct. &lt;br /&gt;
&lt;br /&gt;
'''Setting ''Stay Awake'' to On'''&lt;br /&gt;
By default, the unit is constantly asleep and only wakes up at regular intervals to report the luminosity and temperature, before sleeping again. This is to save batteries. While asleep, the unit cannot be programmed from the Vera and cannot be polled for information. To get around this, one normally activates the Test mode by pressing the button on the side of the unit, which keeps it awake for 10 minutes so that it can be programmed. By setting the unit to stay awake constantly, you can program, poll or configure it at any time. It also has the side effect of enabling the unit to become a repeater of Z Wave signals throughout the network.&lt;br /&gt;
&lt;br /&gt;
To set it, click on the spanner for the &amp;quot;3-in-1 sensor&amp;quot; device, click on Device Options and set variable 5 (Stay Awake) to 1 or any number greater than 0.&lt;br /&gt;
&lt;br /&gt;
'''Setting ''On Time'' to ''Always Fire'''''&lt;br /&gt;
When the unit detects motion, it reports it by sending a Tripped command to the Vera. It then ignores any motion for the duration of the 'On Time' variable, after which it sends un Untripped command to the Vera and waits for the next motion. Since battery life is not a consideration while on AC power, you can set it to 'Always Fire', which sends a Tripped command whenever motion is detected with no waiting period. Note, this will also prevent an Untripped command from being sent.&lt;br /&gt;
&lt;br /&gt;
To set it, click on the spanner for the &amp;quot;3-in-1 sensor&amp;quot; device, click on Device Options and set variable 2 (On Time) to 0.&lt;br /&gt;
&lt;br /&gt;
'''Excluding and Reincluding the unit'''&lt;br /&gt;
To activate these new settings, you will need to exclude and reinclude the unit using the standard Vera process. Remember to save your settings first.  &lt;br /&gt;
&lt;br /&gt;
''' Setting Poll frequency'''&lt;br /&gt;
The unit usually only reports temperate and luminosity every time it wakes up, but since the unit is now constantly awake, you will have to configure a poll frequency to gather that information.&lt;br /&gt;
&lt;br /&gt;
To set it, click on the spanner for the &amp;quot;Motion Sensor&amp;quot; device, click on Settings and set &amp;quot;Poll this node at most every&amp;quot; to the required update frequency. The Wakeup interval setting on this same screen has no effect since it's been overridden by Always Awake setting.&lt;br /&gt;
&lt;br /&gt;
== Known issues ==&lt;/div&gt;</summary>
		<author><name>Solipsia</name></author>	</entry>

	<entry>
		<id>http://wiki.mios.com/index.php/Luup_Scenes_Events</id>
		<title>Luup Scenes Events</title>
		<link rel="alternate" type="text/html" href="http://wiki.mios.com/index.php/Luup_Scenes_Events"/>
				<updated>2011-01-16T17:23:41Z</updated>
		
		<summary type="html">&lt;p&gt;Solipsia: /* Samples */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Development]]&lt;br /&gt;
== Adding Lua code to scenes and events ==&lt;br /&gt;
&lt;br /&gt;
You can add Lua script to scenes and events for simple tasks, like making a scene or event conditional.  Conditional meaning &amp;quot;do something only '''if''' some condition is met&amp;quot;, such as attaching a condition to your &amp;quot;Come Home&amp;quot; scene so it is only run '''if''' the temperature is over 70 degrees.  Basic conditional expressions are easy, and, if that's all you're looking to do, skip to the walk-through below.&lt;br /&gt;
&lt;br /&gt;
If you're more technically inclined you can also do very advanced things too.  For an overview of all the advanced things you can do with Vera's Luup engine, and how scenes and events fit in, see the [[Luup_Intro]] page.&lt;br /&gt;
&lt;br /&gt;
To add Lua code to a scene, create the [[Scenes]] and click 'Luup scene'.  Fill in your Lua code in the input box.  To do a simple condition, see the sample below.  Or if you want to do advanced scripting you can use any [[http://lua.org Lua]] commands as described in the [[http://www.lua.org/manual/5.1/ Lua reference manual]] as well as the variables and functions that the Luup engine adds to Lua documented here: [[Luup_Lua_extensions]].  The Lua code will be run every time the scene is activated either by the user or a scene or a timer.  The Lua code is run before the commands that you included in the scene.  If your Lua code ends with this: &amp;quot;return false&amp;quot; then the commands in the scene will not be run.&lt;br /&gt;
&lt;br /&gt;
You can also add Lua code to an event by clicking 'Luup event'.  Since events are attached to scenes anyway, there is usually little difference between adding the code to an event, or to the scene the event is part of.  If the Lua code in an event returns false, then the event is aborted, meaning the scene that the event is attached to will not be triggered by the event.  The main reason for attaching Lua code to an event is if you have multiple events to a scene.  For example, you may have a scene called &amp;quot;Turn lights on in hallway&amp;quot; which is triggered by 2 events: 1) The front door opens, and 2) the motion sensor in the hallway is tripped.  Perhaps whenever the front door opens you always want the scene to be activated, but you only want the motion sensor to activate the scene before 10:00.  In this case, you would add Lua code to the motion sensor's event which does something like (pseudo-code): &amp;quot;if time&amp;gt;10:00 return false&amp;quot;.  That way the event from the motion sensor will be aborted if it's after 10:00, but the event from the front door will always activate the scene regardless.&lt;br /&gt;
&lt;br /&gt;
When you edit the Lua code in a scene or event you must click 'Save' before the code is saved.  Then you can activate the scene or trigger the event to see what happens when your code is run.  If you're doing some advanced scripting that you'll need to debug this can be tedious, but there are easy ways to test your Lua script immediately without saving first as explained in [[Lua_Debugging]].&lt;br /&gt;
&lt;br /&gt;
If you're doing advanced Lua scripting, you should note that all the Lua code in your scenes and events run in a single Lua instance, which is separate from any Lua plugins.  This means if you set a global variable in one scene, or create a function inside the Lua code in a scene, then in another scene's Lua code you can use that global variable or call that function.  You do not need to worry about conflicting with a Luup plugin, though, since they have their own Lua instance, meaning they have their own global variables and functions.&lt;br /&gt;
&lt;br /&gt;
== Walk-through #1 -- At 12 noon, turn off the interior lights if the temperature is over 80 degrees  ==&lt;br /&gt;
&lt;br /&gt;
Before you start, in Vera's setup interface go to 'Devices' and click the '+' button next to the thermostat. Make note of the Device #. &lt;br /&gt;
&lt;br /&gt;
In this walkthrough we'll assume it's Device #3, but use the actual device number of''your'' thermostat. Next, visit [[Luup Variables]] to get a list of all the variables for devices. A variable is a piece of information about the current state of a device, such as whether it's on or off, it's current temperature, etc. &lt;br /&gt;
&lt;br /&gt;
Look down at ''Thermostat'', and copy the name of the service/variable which corresponds to the current temperature, namely.  In this case, it's&lt;br /&gt;
&lt;br /&gt;
  urn:upnp-org:serviceId:TemperatureSensor1 CurrentTemperature&lt;br /&gt;
&lt;br /&gt;
Notice that it states the &amp;lt;tt&amp;gt;CurrentTemperature&amp;lt;/tt&amp;gt; is in Celsius. So type in &amp;quot;80 degrees Fahrenheit to Celsius&amp;quot; in Google and you'll see that it's 26.6 degrees Celsius. &lt;br /&gt;
&lt;br /&gt;
Now, the first step is to create the scene that turns off the lights. In Vera's setup interface, click 'Scenes', and click 'Add Scene' to add a new scene to one of the rooms. It's not important which room you choose. Scenes are categorized in rooms just to help you keep track of them if you have a lot of scenes. You can also put the scene in 'Global Scenes', or, you can create dummy rooms on the 'Rooms' tab if you want to have more &amp;quot;rooms&amp;quot; to organize your scenes with. After you click 'Add Scene', type in a description to remember your scene by, such as &amp;quot;Lights off 12:00 if 80&amp;quot;. Under the 'Commands' area you'll see all the rooms. Click '+' next to the rooms that have lights you want to control, and choose &amp;quot;Off&amp;quot; in the pull-down. At this point, you have a normal scene, and, if you were to save your changes now, whenever you click the scene on the dashboard or on a remote control, the lights should turn off. &lt;br /&gt;
&lt;br /&gt;
Second, next to the scene's description click 'add timer'. You can give the timer a description too so that if you have multiple timers you can see in the logs which one is activating the scene. Choose &amp;quot;Day of week based&amp;quot;. If you want this scene to only run on certain days of the week, just check off which days you want this scene to run on. Otherwise, you can leave them all unchecked (or check them all) to do it every day. Leave the pull-down at &amp;quot;a certain time of day&amp;quot;, and choose 12&amp;amp;nbsp;: 00&amp;amp;nbsp;: 00 from the pull-downs. At this point, if you were to save your changes, the lights would turn off automatically at 12 noon. &lt;br /&gt;
&lt;br /&gt;
Third, the last step is to add the condition. To the right of the scene's description you'll see the button &amp;quot;Luup Scene&amp;quot;. Click it and in the code box, copy and paste the following: &lt;br /&gt;
&lt;br /&gt;
  local lul_temp=luup.variable_get(&amp;quot;urn:upnp-org:serviceId:TemperatureSensor1&amp;quot;,&amp;quot;CurrentTemperature&amp;quot;,3)&lt;br /&gt;
  if( tonumber(lul_temp)&amp;amp;lt;26.6 ) then&lt;br /&gt;
    return false&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
Don't forget to change the &amp;quot;3&amp;quot; to whatever is the actual device number of your thermostat. Assign the result of &amp;lt;tt&amp;gt;luup.variable_get&amp;lt;/tt&amp;gt; to a variable first, rather than putting it directly in the &amp;lt;tt&amp;gt;tonumber()&amp;lt;/tt&amp;gt;, because &amp;lt;tt&amp;gt;luup.variable_get&amp;lt;/tt&amp;gt; actually returns 2 values: the value of the variable, and the time when the variable was modified. The '&amp;lt;tt&amp;gt;tonumber&amp;lt;/tt&amp;gt;' is needed because all of a device's variables are stored as plain text--not numbers--so if you want to do arithmetic or numeric comparison of a variable, you need to put &amp;lt;tt&amp;gt;tonumber()&amp;lt;/tt&amp;gt; around &amp;lt;tt&amp;gt;luup.variable_get&amp;lt;/tt&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;luup.variable_get&amp;lt;/tt&amp;gt; is documented in [[Luup Lua extensions]]. &lt;br /&gt;
&lt;br /&gt;
Now click 'Update', and then click 'Save' to save everything. The &amp;quot;return false&amp;quot; means &amp;quot;don't run this scene&amp;quot;. So if the current temperature is &amp;amp;lt;26.6, the scene will be aborted and won't run. The timer will make it trigger every day at 12 noon. &lt;br /&gt;
&lt;br /&gt;
To test it, you can click the scene button on the dashboard. The lights will turn off only if the temperature is over 80 degrees. If it's less than 80 degrees, the scene won't do anything. Since this scene is something that happens automatically and you probably won't execute manually, you can go to the scene again and check the &amp;quot;Hidden&amp;quot; box so the scene doesn't show up on&amp;amp;nbsp;Vera's 'Dashboard' and on your remote controls, like the iPhone. If you want to have a scene that turns off the lights which you can run whenever you want from 'Dashboard'' or your remote control, you should create another scene that has the same commands and simply don't add the timers and Luup conditions, and don't check the &amp;quot;Hidden&amp;quot; box. &lt;br /&gt;
&lt;br /&gt;
You can substitute other service/variables and device ID's to make other types of conditions. The &amp;quot;if&amp;quot; statement above also supports nesting with ( and ), as well as the keywords 'and' and 'or'. So the following means the scene would abort if the temperature is &amp;amp;lt;26.6 and &amp;amp;gt;25, unless it's &amp;amp;lt;23: &lt;br /&gt;
&lt;br /&gt;
  local lul_temp=luup.variable_get(&amp;quot;urn:upnp-org:serviceId:TemperatureSensor1&amp;quot;,&amp;quot;CurrentTemperature&amp;quot;,3)&lt;br /&gt;
  if( (tonumber(lul_temp)&amp;amp;lt;26.6&lt;br /&gt;
    and tonumber(lul_temp)&amp;amp;gt;25)&lt;br /&gt;
    or tonumber(lul_temp)&amp;amp;lt;23 ) then&lt;br /&gt;
      return false&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
If the scene doesn't run, it's possible&amp;amp;nbsp;there is&amp;amp;nbsp;a syntax error. The easiest way to test this is to copy the Lua code from the scene, then go to Devices, Luup Plugins, and &amp;quot;Test Luup code&amp;quot;. Paste the code in the box and click 'go'. If the info box above the 'go' button has a check and says &amp;quot;Message sent successful&amp;quot;, your code is okay. If there's an error, it says: &amp;quot;Code failed&amp;quot;. &lt;br /&gt;
&lt;br /&gt;
To see if that's true, use putty, or telnet or ssh to log-in to Vera, as explained in detail in [[Lua Debugging]], and type: &lt;br /&gt;
&lt;br /&gt;
   cd /var/log/cmh&lt;br /&gt;
   tail -f LuaUPnP.log | grep '^01'&lt;br /&gt;
&lt;br /&gt;
Now click 'Save' in Vera's setup page, even if it's gray, as that will cause Vera to restart the Luup engine and log any syntax errors. See: [[Lua Debugging]] for in-depth details on how to debug.&lt;br /&gt;
&lt;br /&gt;
== Samples ==&lt;br /&gt;
&lt;br /&gt;
This page is a wiki which anyone can edit.  If you have some Lua code you think other users might find useful, feel free to add it here.&lt;br /&gt;
&lt;br /&gt;
=== Misc actions ===&lt;br /&gt;
&lt;br /&gt;
Did you see the sample here already: http://wiki.micasaverde.com/index.php/Luup_Scenes_Events&lt;br /&gt;
&lt;br /&gt;
====Turn an appliance switch or a Danfoss thermostat on for device #5====&lt;br /&gt;
&lt;br /&gt;
  luup.call_action(&amp;quot;urn:upnp-org:serviceId:SwitchPower1&amp;quot;,&amp;quot;SetTarget&amp;quot;,{ newTargetValue=&amp;quot;1&amp;quot; },5)&lt;br /&gt;
&lt;br /&gt;
====Turn an appliance switch or a Danfoss thermostat off====&lt;br /&gt;
&lt;br /&gt;
  luup.call_action(&amp;quot;urn:upnp-org:serviceId:SwitchPower1&amp;quot;,&amp;quot;SetTarget&amp;quot;,{ newTargetValue=&amp;quot;0&amp;quot; },5)&lt;br /&gt;
&lt;br /&gt;
====Do something if switch device #5 is on====&lt;br /&gt;
&lt;br /&gt;
  local lul_tmp = luup.variable_get(&amp;quot;urn:upnp-org:serviceId:SwitchPower1&amp;quot;,&amp;quot;Status&amp;quot;,5)&lt;br /&gt;
  if( lul_tmp==&amp;quot;1&amp;quot; ) then&lt;br /&gt;
     --something to do goes here&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
====Dim switch #6 to 30%====&lt;br /&gt;
&lt;br /&gt;
  luup.call_action(&amp;quot;urn:upnp-org:serviceId:Dimming1&amp;quot;,&amp;quot;SetLoadLevelTarget&amp;quot;,{ newLoadlevelTarget=&amp;quot;30&amp;quot; },6)&lt;br /&gt;
&lt;br /&gt;
====Arm motion sensor #7====&lt;br /&gt;
&lt;br /&gt;
  luup.variable_set(&amp;quot;urn:micasaverde-com:serviceId:SecuritySensor1&amp;quot;,&amp;quot;Armed&amp;quot;,&amp;quot;1&amp;quot;,7)&lt;br /&gt;
&lt;br /&gt;
====Disarm motion sensor #7====&lt;br /&gt;
&lt;br /&gt;
  luup.variable_set(&amp;quot;urn:micasaverde-com:serviceId:SecuritySensor1&amp;quot;,&amp;quot;Armed&amp;quot;,&amp;quot;0&amp;quot;,7)&lt;br /&gt;
&lt;br /&gt;
Note, arming and disarming isn't a concept within UPnP or Z-Wave.  It's just a flag that the Luup engine uses, and is stored in a variable we created called &amp;quot;Armed&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
====Run Scene #5====&lt;br /&gt;
&lt;br /&gt;
Thanks &amp;quot;denix&amp;quot; on the forum for the correct syntax.&lt;br /&gt;
&amp;quot;Actually, the 4th parameter IS required, but it's not used. Otherwise the command fails with an error message&amp;quot;&lt;br /&gt;
&lt;br /&gt;
  luup.call_action(&amp;quot;urn:micasaverde-com:serviceId:HomeAutomationGateway1&amp;quot;,&amp;quot;RunScene&amp;quot;,{ SceneNum=&amp;quot;5&amp;quot; }, 0)&lt;br /&gt;
&lt;br /&gt;
In this case we left the device number off (the 4th parameter to &amp;lt;tt&amp;gt;luup.call_action&amp;lt;/tt&amp;gt;), because the &amp;quot;&amp;lt;tt&amp;gt;RunScene&amp;lt;/tt&amp;gt;&amp;quot; action is handled by the Luup engine itself--not by some device within Z-Wave, etc.&lt;br /&gt;
&lt;br /&gt;
However, normally you don't need to &amp;lt;tt&amp;gt;luup.call_action&amp;lt;/tt&amp;gt; in Lua code.  Rather, whatever actions, or commands, you want to run, you put into the scene itself, and the only Lua code is to simply check if some condition is true and abort the scene if the condition isn't met.&lt;br /&gt;
&lt;br /&gt;
====Change the Temperature on Thermostat (Cool) device #19====&lt;br /&gt;
  luup.call_action(&amp;quot;urn:upnp-org:serviceId:TemperatureSetpoint1_Cool&amp;quot;,&lt;br /&gt;
                   &amp;quot;SetCurrentSetpoint&amp;quot;, { NewCurrentSetpoint=&amp;quot;68&amp;quot; },&lt;br /&gt;
                   19)&lt;br /&gt;
&lt;br /&gt;
====Change the Temperature on a Thermostat (Heat) device #19====&lt;br /&gt;
  luup.call_action(&amp;quot;urn:upnp-org:serviceId:TemperatureSetpoint1_Heat&amp;quot;,&lt;br /&gt;
                   &amp;quot;SetCurrentSetpoint&amp;quot;,{ NewCurrentSetpoint=&amp;quot;68&amp;quot; },&lt;br /&gt;
                   19)&lt;br /&gt;
&lt;br /&gt;
===='Privacy' mode for Foscam FI8908[w]====&lt;br /&gt;
&lt;br /&gt;
 local IP_address      = '&amp;lt;IP address of camera&amp;gt;'&lt;br /&gt;
 local username        = '&amp;lt;username&amp;gt;'&lt;br /&gt;
 local password        = '&amp;lt;password&amp;gt;'&lt;br /&gt;
 local timeout         = 5&lt;br /&gt;
 &lt;br /&gt;
 function move_up()&lt;br /&gt;
 &lt;br /&gt;
  luup.inet.wget( 'http://'..IP_address..'/decoder_control.cgi?command=0' , timeout, username, password )&lt;br /&gt;
 &lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 -- center the camera; takes some time, so we have to wait 2 minutes for the command to complete&lt;br /&gt;
 &lt;br /&gt;
 luup.inet.wget( 'http://'..IP_address..'/decoder_control.cgi?command=25', timeout, username, password )&lt;br /&gt;
 &lt;br /&gt;
 luup.call_delay( 'move_up', 120 )&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Blinking lights====&lt;br /&gt;
&lt;br /&gt;
http://forum.micasaverde.com/index.php?topic=5127.0&lt;br /&gt;
&lt;br /&gt;
=== Calculate sunrise and sunset ===&lt;br /&gt;
&lt;br /&gt;
See http://forum.micasaverde.com/index.php?topic=2073.msg8132#msg8132&lt;br /&gt;
&lt;br /&gt;
=== Access the web ===&lt;br /&gt;
==== Invoke URL by GET request ====&lt;br /&gt;
Based on code by Jim/jgc94131&lt;br /&gt;
  require('ltn12')&lt;br /&gt;
  local http=require('socket.http')&lt;br /&gt;
  local response_body = {}&lt;br /&gt;
  local request_body = ''&lt;br /&gt;
  socket.http.TIMEOUT = 4&lt;br /&gt;
  local r, c, h = socket.http.request{&lt;br /&gt;
    url = 'http://website/page?parameter1=value&amp;amp;parameter2=value',&lt;br /&gt;
    method = &amp;quot;GET&amp;quot;,&lt;br /&gt;
    port = 80,&lt;br /&gt;
    headers = {&lt;br /&gt;
      [&amp;quot;Content-Length&amp;quot;] = string.len(request_body),&lt;br /&gt;
      [&amp;quot;Content-Type&amp;quot;] =  &amp;quot;application/x-www-form-urlencoded&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    source = ltn12.source.string(request_body),&lt;br /&gt;
    sink = ltn12.sink.table(response_body)&lt;br /&gt;
  } &lt;br /&gt;
&lt;br /&gt;
=== Access the current time  ===&lt;br /&gt;
&lt;br /&gt;
The Lua function &lt;br /&gt;
&lt;br /&gt;
  os.date (format, time)&lt;br /&gt;
&lt;br /&gt;
converts a time value `time` into a human readable date/time string, according to `format`. If you leave out the optional `time` parameter, it defaults to current time. The `format` parameter defaults to a fairly complete format. If you specify '*t' as the format, it will return a table instead of a formatted string. &lt;br /&gt;
&lt;br /&gt;
  t = os.date('*t')&lt;br /&gt;
 t =&amp;amp;gt; {year=2010, month=2, day=19, yday=50, wday=6, hour=22, min=45, sec=45, isdst=false}&lt;br /&gt;
&lt;br /&gt;
The fields are year, month, day of month, day of year, day of week, hour in 24 hour clock, minutes, seconds and if it's Daylight Savings Time.&lt;br /&gt;
&lt;br /&gt;
Current hour: &lt;br /&gt;
&lt;br /&gt;
  os.date('*t').hour&lt;br /&gt;
&lt;br /&gt;
Current minute: &lt;br /&gt;
&lt;br /&gt;
  os.date('*t').min&lt;br /&gt;
&lt;br /&gt;
Current second: &lt;br /&gt;
&lt;br /&gt;
  os.date('*t').sec&lt;br /&gt;
&lt;br /&gt;
Do something between 16:00 and 21:15: &lt;br /&gt;
&lt;br /&gt;
 local t = os.date('*t')&lt;br /&gt;
 local current_second = t.hour * 3600 + t.min * 60 + t.sec     -- number of seconds since midnight&lt;br /&gt;
 local min_time_in_seconds = 16 * 3600 +  0 * 60             -- 16:00&lt;br /&gt;
 local max_time_in_seconds = 21 * 3600 + 15 * 60             -- 21:15&lt;br /&gt;
 &lt;br /&gt;
 if (current_second &amp;amp;gt; min_time_in_seconds) and (current_second &amp;amp;lt; max_time_in_seconds)&lt;br /&gt;
 then&lt;br /&gt;
 -- do something&lt;br /&gt;
 else&lt;br /&gt;
 return false&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
See http://forum.micasaverde.com/index.php?topic=2015.0 and http://www.lua.org/manual/5.1/manual.html#5.8.&lt;br /&gt;
&lt;br /&gt;
=== Set Z-Wave parameters ===&lt;br /&gt;
&lt;br /&gt;
See http://forum.micasaverde.com/index.php?topic=1937.msg7803#msg7803&lt;br /&gt;
&lt;br /&gt;
===  a scene if the temperature is outside of a range ===&lt;br /&gt;
&lt;br /&gt;
add snippets here...&lt;/div&gt;</summary>
		<author><name>Solipsia</name></author>	</entry>

	</feed>