Scripts for scenes

From MiOS
(Difference between revisions)
Jump to: navigation, search
Line 5: Line 5:
 
2. Create a timer and set it to run every minute.<br>  
 
2. Create a timer and set it to run every minute.<br>  
  
3. In the Luup Code section put the following code:<br> <source lang="lua">local l_deviceNo = 22
+
3. In the Luup Code section put the following code:<br> <source lang="lua">local deviceNo = 22
local l_time = 15
+
local period = 15
  
 
local SS_SID = "urn:micasaverde-com:serviceId:SecuritySensor1"
 
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 armed = luup.variable_get(SS_SID, "Armed", deviceNo)
   local l_lastTrip = luup.variable_get(SS_SID, "LastTrip", l_deviceNo) or os.time()
+
if armed == "1" then
   l_lastTrip = tonumber(l_lastTrip)
+
   local lastTrip = luup.variable_get(SS_SID, "LastTrip", deviceNo) or os.time()
   if (os.difftime(os.time(), l_lastTrip) / 60) >= l_time then
+
   lastTrip = tonumber(lastTrip)
 +
   if (os.difftime(os.time(), lastTrip) / 60) >= period then
 
       return true
 
       return true
 
   end
 
   end
 
end
 
end
  
return false</source><br> ''l_deviceNo'' is the sensor's device number, which you can get by going into its Toolbox, in the Advanced tab.<br>  
+
return false</source><br> ''deviceNo'' is the sensor's device number, which you can get by going into its Toolbox, in the Advanced tab.<br>  
 +
 
 +
''period'' is the time (in minutes) the sensor hasn't been tripped before running the scene.<br>
 +
 
 +
'''Note:''' The sensor must be armed for this to work, but this can be easily changed.<br>
 +
 
 +
 
 +
 
 +
== Scene that runs only if a security sensor has been tripped for 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:
 +
 
 +
<source lang="lua">local deviceNo = 22
 +
local period = 15
 +
 
 +
local SS_SID = "urn:micasaverde-com:serviceId:SecuritySensor1"
 +
 
 +
local armed = luup.variable_get(SS_SID, "Armed", deviceNo) or "0"
 +
if armed == "1" then
 +
    local tripped = luup.variable_get(SS_SID, "Tripped", deviceNo) or "0"
 +
    if tripped == "0" then
 +
        luup.variable_set(SS_SID, "TripPeriod", "0", deviceNo)
 +
    else
 +
        local tripPeriod = luup.variable_get(SS_SID, "TripPeriod", deviceNo) or 0
 +
        tripPeriod = tonumber(tripPeriod)
 +
        tripPeriod = tripPeriod + 1
 +
        luup.variable_set(SS_SID, "TripPeriod", tripPeriod, deviceNo)
 +
        if tripPeriod == period then
 +
            return true
 +
        end
 +
    end
 +
end
 +
 
 +
return false</source>
 +
 
 +
''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.<br>
+
''period'' is the time (in minutes) the sensor has been tripped before running the scene.
  
'''Note''': The sensor must be armed for this to work, but this can be easily changed.<br>
+
'''Note:''' The sensor must be armed for this to work, but this can be easily changed.
  
 
<br>  
 
<br>  
  
 
[[Category:User_Instructions]]
 
[[Category:User_Instructions]]

Revision as of 11:15, 15 February 2011

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 deviceNo = 22
local period = 15
 
local SS_SID = "urn:micasaverde-com:serviceId:SecuritySensor1"
 
local armed = luup.variable_get(SS_SID, "Armed", deviceNo)
if armed == "1" then
   local lastTrip = luup.variable_get(SS_SID, "LastTrip", deviceNo) or os.time()
   lastTrip = tonumber(lastTrip)
   if (os.difftime(os.time(), lastTrip) / 60) >= period then
       return true
   end
end
 
return false

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

period 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.


Scene that runs only if a security sensor has been tripped for 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 deviceNo = 22
local period = 15
 
local SS_SID = "urn:micasaverde-com:serviceId:SecuritySensor1"
 
local armed = luup.variable_get(SS_SID, "Armed", deviceNo) or "0"
if armed == "1" then
    local tripped = luup.variable_get(SS_SID, "Tripped", deviceNo) or "0"
    if tripped == "0" then
        luup.variable_set(SS_SID, "TripPeriod", "0", deviceNo)
    else
        local tripPeriod = luup.variable_get(SS_SID, "TripPeriod", deviceNo) or 0
        tripPeriod = tonumber(tripPeriod)
        tripPeriod = tripPeriod + 1
        luup.variable_set(SS_SID, "TripPeriod", tripPeriod, deviceNo)
        if tripPeriod == period then
            return true
        end
    end
end
 
return false

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

period is the time (in minutes) the sensor has been tripped before running the scene.

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


Personal tools