Need help with Ping Sensor and Sleep ()?

Hey everyone - I need some help with a scene that I put together. I’m using UI4.

Here is my setup: My wife and I both have smartphones. I’ve configured my home network to assign static IP’s to these devices. Next, I setup a ping sensor for each phone within Vera. This enables Vera to know when me, my wife or both of us are home or away.

Here’s the problem. I’d like to use this setup to automatically do a few things like arm/disarm the motion sensors, turn off coffee maker (if on), turn down/up the thermostat, etc…But, sometimes when we are home, the phones will sometimes miss a ping which causes Vera to arm my motion sensors and turn off my coffee maker! So, is there a way to wait another ping cycle (or two) to see if it misses another ping before it arms my motion sensors? I tried luup.sleep() but I believe other events never got triggered when it was “sleeping” because of a bug with this function. My luup code below is triggered by an event (missing a ping). The sleep bug/issue is mentioned here. [url=http://wiki.micasaverde.com/index.php/Luup_Lua_extensions#function:_sleep]http://wiki.micasaverde.com/index.php/Luup_Lua_extensions#function:_sleep[/url]

Any ideas around this? Will sleep() ever be fixed?

Thanks everyone!

local dad_phone = 54
local mom_phone= 55

local MainSensor = 61
local GarageSensor = 40
local UpstairsSensor = 66

local coffeemaker = 39
 
local SS_SID = "urn:micasaverde-com:serviceId:SecuritySensor1"
local dadtripped = luup.variable_get(SS_SID, "Tripped", dad_phone)
local momtripped = luup.variable_get(SS_SID, "Tripped", mom_phone)
   
    if dadtripped == "0" and momtripped =="0"
        then
           luup.variable_set(SS_SID, "Armed", "1", MainSensor)
           luup.variable_set(SS_SID, "Armed", "1", GarageSensor)
           luup.variable_set(SS_SID, "Armed", "1", UpstairsSensor)
     end

P.S. I left out the coffee maker and the thermostat since it wasn’t working as expected.

Not really useful to you in your current situation, but if you were on UI5 you could use the countdown timer plug-in:

http://forum.micasaverde.com/index.php/topic,9425.0.html

You could check [tt]urn:micasaverde-com:serviceId:HaDevice1/LastUpdate[/tt] against the current time.

Just an example to get the idea:

local HADEVICE_SID = "urn:micasaverde-com:serviceId:HaDevice1"
local devid = 37
local delay = 15 * 60 -- 15 min

local lup = luup.variable_get( HADEVICE_SID, "LastUpdate", devid )

if os.time() - tonumber( lup ) > delay
 then
  SBS_announcement( ... )
 end

You need to count the missed pings in order to avoid a false positive.
Global variables should work or if using UI5 there are some non-code ideas you could try.

I’d say use a luup.call_delay that after one or two minutes if the trigger matches what the call_delay sees then you have a positive. It would also be good to re-check the value after a period to be sure.

I’ve set this up myself now. And it appears that the timer plug-in for UI5 is the answer.

The iPhone is mostly offline but connects periodically. Probably dependent upon mail and app settings.

I got something allready running here at home.
I use the following:
1x Pingsensor
1x Countdowntimer
2 scenes.

scene#1
trigger: pingsensor
when True (so phone is pinged) restart countdowntimer

Scene#2:
trigger: countdowntimer is 0
Do your thing.

I also use the variablecontainer to store some information and use it as variable for conditions within the scenes.
e.g. When my phone because ping-able AND my bedroom light is on, the scene of coming home is not executed because my phone battery was probably death :wink:

[quote=“The-Source, post:7, topic:170722”]I got something allready running here at home.
I use the following:
1x Pingsensor
1x Countdowntimer
2 scenes.

scene#1
trigger: pingsensor
when True (so phone is pinged) restart countdowntimer

As a newbi to all things Vera…did you create these scenes using the Vera UI or are you writing luup code? I need to do the same thing and I don’t see how to do the scenes you set up.

Scene#2:
trigger: countdowntimer is 0
Do your thing.

I also use the variablecontainer to store some information and use it as variable for conditions within the scenes.
e.g. When my phone because ping-able AND my bedroom light is on, the scene of coming home is not executed because my phone battery was probably death ;)[/quote]

@The-Source:
I did the exact same config. 1 Ping Sensor, 1 Countdown Timer, 2 Scenes. But the problem I found was that my iPhone would go offline sometimes and not come back. It would ‘sleep’ for long enough that it didn’t make sense to use this.

Other simple ways I’ve found to use this is, a successful ping is a confirmation of locality, but unsuccessful one doesn’t mean anything. So, per se, you use a virtual switch that is ‘off’ when away. It could be automatically set to ‘on’ when the ping is successful. But that is about as far as reliability goes. :confused:

That is one of the reasons that my away scene only is triggered after 20mins, at night its never activated because my WiFi is not in powersave mode, so always connected. In my router I configured the DHCP server that my phone always get the same ip.
The 20mins delay is also chosen that when I’m out for a quick stop at the supermarket the scene won’t be activated. (supermarket is @ 1min cycle distance :wink: )

The Ping sensor is good, but you’re right it’s only one verification action, and even then its only looking for the phone’s IP, not the person;)

It’s a goog brain exercise to think up some logic that can be used; checking a light on is good, but easily accidently done.

A motion and/or a door sensor could work e.g If the door is not opened after the IP is found, no need to check again, until door is opened again or no motion is seen. Etc.

The phone ping happens every 15 seconds, so it must miss 80 pings before my away seen will be activated, one good ping resets my countdown timer to 20 minutes.
Before you setup your home for it you could also let the vera mail you to test this out.
My (android) phone has the option to keep wifi enabled even when the phone is locked for some time. I think a iPhone has this option also ???

Interesting,

I’ve just noticed that receiving a Prowl Notification wakes up my iPad long enough for it to connect to the network in order to reset the ping sensor :wink: So, it looks like there’s a way to check if the phone/IP is actually there.

Thought Process.

  • Door Sensor is Tripped
  • IOS Notification Sent
  • PING Sensor For “My Phone” tripped as IP is found
  • PLAY Sonos Scene which plays TTS “Welcome Home xxxxxx”