I have created a virtual on/off switch called “Larm On_Off”. Scene 1 arms the motion sensor and Scene 3 bypasses the motion sensor depending on the virtual switch.
I want to do a lua script to Scene 2 to run the sirene basically on following:
-check if motion sensor is armed
-if yes wait 30 seconds
-check if virtual switch “alarm system” is on
-if yes run sirene
How to do this script? Where can I find a script?
I have no competences on Vera and lua so I am very happy for your help.
I created the virtual switch with the help of forcing the siren to be controlled by a door / window sensor, so I got my virtual switch. Right or wrong?
Then I realized that I had to make a lua, but know nothing about it.
I know what the function needs to be done. The one I have described, so how do I do? From the beginning?
Your script would look something like this (replace DEVICEID with your devices ID’s):
--check if motion sensor is armed:
armed = luup.variable_get("urn:micasaverde-com:serviceId:SecuritySensor1","armed",DEVICEID)
if ((armed == "1")) then
--wait 30 seconds
function virtual()
--check if virtual switch is on
virtual = luup.variable_get("urn:upnp-org:serviceId:VSwitch1","Status",DEVICEID)
if ((virtual == "1")) then
return true
end
luup.call_delay('virtual', 30)
end
return false
I didn’t test this, but it should work.
So basically you create a scene. Then you set the motion sensor as a trigger. You also set the sirene to ON in the scene. Then you add the luup code above. This means every time motion is detected the scene will be run. When the scene runs the script runs first. Only if the script returns no “false” the scene will run through completely, if the script returns false the scene will stop and the actions you defined are not made.
So when you come home the motion sensor is triggered. This will start the scene. The luup code then checks if your sensor is armed, if not, the scene stops. If the sensor is armed the code waits for 30 seconds, then it checks if your virtual switch is on. If not the scene will stop. If yes the scene is run completly and activates your sirene.
–check if motion sensor is armed:
armed = luup.variable_get(“urn:schemas-micasaverde-com:device:MotionSensor:1”,“Armed”,37)
if ((armed == “1”)) then
–wait 30 seconds
function tripped()
–check if motion sensor is tripped
tripped = luup.variable_get(“urn:schemas-micasaverde-com:device:MotionSensor:1”,“Tripped”,44)
if ((tripped == “1”)) then
return true
end
end
luup.call_delay(‘tripped’, 30)
end
return false
[quote=“LEPSWED, post:8, topic:170094”]I have written this script but it doesnt work
–check if motion sensor is armed:
armed = luup.variable_get(“urn:schemas-micasaverde-com:device:MotionSensor:1”,“Armed”,37)
if ((armed == “1”)) then
–wait 30 seconds
function tripped()
–check if motion sensor is tripped
tripped = luup.variable_get(“urn:schemas-micasaverde-com:device:MotionSensor:1”,“Tripped”,44)
if ((tripped == “1”)) then
return true
end
end
luup.call_delay(‘tripped’, 30)
end
return false
The siren is not being activated. Whats wrong?[/quote]
Is it just the colon ( between “MotionSensor"and “1”? Should it be"MotionSensor1”?
After examining various scrip, I realize that there is something wrong in “variable_get” and (“urn: schemas-micasaverde-com: device: Motion Sensor: 1”, “Armed”, 37)
I’ll get the string for the item under the Advanced tab and device_typ.
[quote=“LEPSWED, post:13, topic:170094”]After examining various scrip, I realize that there is something wrong in “variable_get” and (“urn: schemas-micasaverde-com: device: Motion Sensor: 1”, “Armed”, 37)
I’ll get the string for the item under the Advanced tab and device_typ.
You can hover with your mouse over the variable in the [tt]Advanced[/tt] tab and the [tt]serviceId[/tt] will be shown (depending on browser, maybe). Make sure you get capitalization right.
Hurray, hurray, I have now come forward with the help of you … ;D
Now working variables as shown below
check if motion sensor is armed:
local participation luup.variable_get = (“urn: micasaverde-com: serviceId: SecuritySensor1”, “Armed”, 37)
if participation == “1” then
- check if motion sensor is armed:
local tripped luup.variable_get = (“urn: micasaverde-com: serviceId: SecuritySensor1”, “tripped”, 44)
if tripped == “1” then
return true
End
End
return false
Now I want 30 seconds of delay
I have tried
check if motion sensor is armed:
local participation luup.variable_get = (“urn: micasaverde-com: serviceId: SecuritySensor1”, “Armed”, 37)
if participation == “1” then
- wait 30 seconds
tripped function ()
- check if motion sensor is armed:
local tripped luup.variable_get = (“urn: micasaverde-com: serviceId: SecuritySensor1”, “tripped”, 44)
if tripped == “1” then
return true
End
End
luup.call_delay (‘tripped’, 30)
End
return false
At last … after hours of reading in the forum, I have now a new solution that works
loop.sleep
check if motion sensor is armed:
participation luup.variable_get = (“urn: micasaverde-com: serviceId: SecuritySensor1”, “Armed”, 37)
if ((armed == “1”)) then
luup.sleep (30000)
- check if code lock is on
tripped luup.variable_get = (“urn: micasaverde-com: serviceId: SecuritySensor1”, “tripped”, 44)
if ((tripped == “1”)) then
return true
End
End
return false
Does anyone see disadvantages loop.sleep? Might there be disadvantages in scripet above?
Hi,
I still have problems I tried to solve during the week, read forums, testing, testing, testing …
I want to check the sensor if it is Armed after 30 seconds. If it is Armed then the siren sounded. If the sensor is in Bypass scene to stop, no sound.
This feature works to control the sensor (Armed / Bypass)
check if motion sensor is armed:
armed = luup.variable_get = (“urn: micasaverde-com: serviceId: SecuritySensor1”, “Armed”, 37)
if ((armed == “1”)) then
return true
else
return false
End
return false
When I add luup.call_delay, nothing works. The siren will sound regardless of the sensor is Armed or Bypass. Have tried many different solutions, such as
Function checkSensor()
check if motion sensor is armed:
armed = luup.variable_get = (“urn: micasaverde-com: serviceId: SecuritySensor1”, “Armed”, 37)
if ((armed == “1”)) then
return true
else
return false
End
End
return false
luup.call_delay (‘checkSensor’, 30)
What is wrong, great need of help, I’m starting to give up