Scripts for scenes

From MiOS
Revision as of 14:13, 11 February 2011 by Mcvflorin (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Scene that runs only if a security sensor hasn't been tripped in a set period of time

1. Create a new scene. In that scene:

2. Create a timer and set it to run every minute.

3. In the Luup Code section put the following code:
local l_deviceNo = 22
local l_time = 15
 
local SS_SID = "urn:micasaverde-com:serviceId:SecuritySensor1"
local l_armed = luup.variable_get(SS_SID, "Armed", l_deviceNo)
if l_armed == "1" then
   local l_lastTrip = luup.variable_get(SS_SID, "LastTrip", l_deviceNo) or os.time()
   l_lastTrip = tonumber(l_lastTrip)
   if (os.difftime(os.time(), l_lastTrip) / 60) >= l_time then
       return true
   end
end
 
return false

l_deviceNo is the sensor's device number, which you can get by going into its Toolbox, in the Advanced tab.

l_time is the time (in minutes) the sensor hasn't been tripped before running the scene.

Note: The sensor must be armed for this to work, but this can be easily changed.

Personal tools