Help with safety functions

Hi
I am new with my Vera. In need of help for my safety functions.

Desired function
LEAVING HOME
Keypad sets after 30 s motion sensor Arm. This allows me to close and lock the door. Scene 1

BURGLARY
If the motion sensor is triggered the siren will sound after 30 s. Scene 2

COMING HOME
Motion sensor is triggered. But through the keypad is motion sensor in the Bypass and siren in Off. No alarm. scene 3

Problem
When I get home starts Scene 2 … Scene 3 will not start occasioned Scene 2 is completed. Therefore, the siren will sound, alarm.

I do not know how to solve the problem. I want to stop (pause) Scene 2 when Scene 3 starts but I can not do it.

Grateful for help. / Lars-Eric

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?

/Lars-Eric

Hi LEPSWED,

What files did you use to create the virtual switch? Anyway, you may find this post useful: http://forum.micasaverde.com/index.php/topic,8023.msg51862.html#msg51862

Hi,
First of all, thanks for your reply mcvflorin

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?

Very grateful for help/LEP

Read this concerning the virtual switches:
http://forum.micasaverde.com/index.php/topic,8965.msg58849.html#msg58849

Are you running on UI5? Then you can use this plugin for the virtual switch:
http://apps.mios.com/plugin.php?id=1408

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.

But I don’t know if this is the best solution to the question (http://forum.micasaverde.com/index.php/topic,8948.msg58500.html#msg58500). Maybe mcvflorin has a much better approach.

I am running UI4

I misunderstood the function of a Virtual Switch.

Uses a door / window sensor instead of virtual switch where Tripp status is used.

Scrip
-check if motion sensor is armed
-if yes wait 30 seconds
-check if door / window sensor is trigged
-if yes run sirene

How is the script designed with a door / window sensor?

I think it would be smart if you read the basics about luup/lua:

http://wiki.micasaverde.com/index.php/Main_Page
http://wiki.micasaverde.com/index.php/Luup_Intro
http://wiki.micasaverde.com/index.php/Luup_Scenes_Events

With that information you should be able to get your scenes running.

Basically you just have to adjust the following line:
virtual = luup.variable_get(“urn:upnp-org:serviceId:VSwitch1”,“Status”,DEVICEID)

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=“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 (:slight_smile: between “MotionSensor"and “1”? Should it be"MotionSensor1”?

Did you add the sirene to the scene ind “devices”? It is not run from the lua code…

Start Testing with a Script like this (tests if both switches are on, but no delay):

[code]armed = luup.variable_get(“urn:upnp-org:serviceId:VSwitch1”,“Status”,104)
switch = luup.variable_get(“urn:upnp-org:serviceId:VSwitch1”,“Status”,105)

if(armed==“1”)then
if(switch==“1”)then
return true
end
return false
end
return false[/code]

You can even simplify this, but like this you can’t add a delay later on:

[code]armed = luup.variable_get(“urn:upnp-org:serviceId:VSwitch1”,“Status”,104)
switch = luup.variable_get(“urn:upnp-org:serviceId:VSwitch1”,“Status”,105)

if((armed==“1”) and (switch==“1”))then
return true
end
return false[/code]

[tt]urn:micasaverde-com:serviceId:SecuritySensor1[/tt]

Rule of thumb for variable_get: if your string contains “schemas” anywhere in it, you’ve got the wrong string.

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.

urn: schemas-micasaverde-com: device: Motion Sensor: 1

I do not see what is wrong and how the string should look like ???

The device is a EZMotion Wireless 3-in-1 Sensor

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

urn: schemas-micasaverde-com: device: Motion Sensor: 1

I do not see what is wrong and how the string should look like ???

The device is a EZMotion Wireless 3-in-1 Sensor[/quote]
Try:

urn:micasaverde-com:serviceID:SecuritySensor1

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

no success ???

I want a delay of 30 s in the script. After trigg of scene a 30 s delay before next action in script

At last … after hours of reading in the forum, I have now a new solution that works :smiley:

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?

glad you got it working!

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