Ping sensor Delay

I am new to MiCasa and have never used Luup code before and am looking for some advice.

My goal is to all the MiCasa system to know when I am home and when I am not home. I installed a Ping Sensor plugin which checks if my Cell Phone is connected to the WiFi. If it is connected then I must be home and if it is not connected then I must not be home. I added a notification (text message) which is sent whenever my phone is connected, this was for proof of concept purposes. The problem I am having is that I receive several notifications that I have arrived home throughout the night. This can happen as I sit in one place (with strong WiFi signal) or as I move about and switch from one AP to another.

I suspect the solution to this problem is to set up an arm/bypass delay. What I would like help with is creating an event or writing a Luup code event that will be triggered when my phone is not detected by the ping sensor. It will wait 10 minutes and then check to if my phone is responding to pings. If it is responding then I never left or I am back so the sensor should remain set to Bypass. If I my phone is still not detected then the sensor should be set to Armed.

A second Scene (easy one) will be triggered by my arrival home only if the sensor is armed. It will then set the sensor to Bypass and ?do stuff?.
This would mean that the sensor is set to Bypass as soon as I arrive home, and remains in Bypass for 10min after I ?leave?, it will only rearm if I am gone for more than 10min.

If you have not already, I advise you that you search the forum for this topic. There are numerous discussions about what you want to do and how to work around some short commings.

  • Garrett

I created a scene with no “devices” selections, I added a trigger

Device: #16 Alan’s Phone Detector

What type of even is the trigger?: A sensor (Door/window/motion/etc.) is tripped
Name for this trigger: Alan WiFi disconnect

Device is not Tripped

Then i added the following Luup code in the Luup tab:

if(luup.variable_get(“urn:schemas-demo-ted-striker:device:PingSensor:1”,“Tripped”,16)==“1”) then
luup.variable_set(“urn:schemas-demo-ted-striker:device:PingSensor:1”,“Armed”,“0”,16)
else
luup.variable_set(“urn:schemas-demo-ted-striker:device:PingSensor:1”,“Armed”,“1”,16)
end

Then I save and exit. When i press “Run” on the scene the code executes but nothing changes on the device.
The device is set to Bypass and is not tripped. When i run the scene i expect that the Luup code will determine that the sensor is not tripped and set then Arm the sensor; but nothing happens.

I got the variables from the device itself
Alan’s Phone Detector:
device_type: urn:schemas-demo-ted-striker:device:PingSensor:1
id: 16

and have just noticed that there are now more than one “Armed” variables available

It appears that my code is creating variables instead of setting them.

I deleted the Ping sensor and started with a new one (to get rid of the variables i created). Then i changed my code to:

if(luup.variable_get(“urn:micasaverde-com:serviceId:SecuritySensor1”,“Tripped”,18)==“1”) then
luup.variable_set(“urn:micasaverde-com:serviceId:SecuritySensor1”,“Armed”,“0”,18)
else
luup.variable_set(“urn:micasaverde-com:serviceId:SecuritySensor1”,“Armed”,“1”,18)
end

The difference is the sensor type which i was able to find by hovering the mouse over the variable name. Now my code runs properly (i think).

As a follow up I was able to add a delay to the Luup code:

luup.call_delay(“test”,600)

function test()
if(luup.variable_get(“urn:micasaverde-com:serviceId:SecuritySensor1”,“Tripped”,18)==“1”) then
luup.variable_set(“urn:micasaverde-com:serviceId:SecuritySensor1”,“Armed”,“0”,18)
else
luup.variable_set(“urn:micasaverde-com:serviceId:SecuritySensor1”,“Armed”,“1”,18)
end
end