Page 1 of 1

Presence detection

Posted: Sunday 09 April 2017 16:00
by pkrabben
Hi All

I'm new to domoticz and trying hard to get a high learning curve.
I managed to do the basic light switching and now looking into scripting

I found this script about presence detection https://www.domoticz.com/wiki/Presence_detection
I tried this but for some reason my virtual switch (phone) keeps at the off state :-(

I checked that I can ping my Phone => ok
I checked that the check_device_online.py_192.168.3.217.pid file is created (so the script is running)=> ok

Do you have some more tips for me what to check so I can get this running.

Thanks in advance for your reply
Grtz
Paul

Re: Presence detection

Posted: Tuesday 11 April 2017 15:13
by lonebaggie
Beat Version now has new hardware device

System Alive Checker

This will create a switch that will change state when the ping fails or succeeds

Re: Presence detection

Posted: Tuesday 11 April 2017 15:22
by gerard76
Stable even

Re: Presence detection

Posted: Tuesday 11 April 2017 15:29
by emme
Ping Hardware under RaspBerry PI is quite odd and gives false off sometimes.
This is not related to Domoticz, but its an hardware limitation...
By design, the onboard LAN share a USB BUS instead of being rietcly connected to the CPU.
this means it has to share resurces with all others devices (this also explain why rPI does not use Gbit ethernet ;) )

so... ping could be considered once the device looks to be stable in its state for about 30secs... (obtained by otherdevices_lastpdate) after this perid, you are about 90% sure about its status ;)

...but I repeat.. this is valid for Raspberry PI.... windows should be much more stable!!!

Re: Presence detection

Posted: Tuesday 11 April 2017 15:46
by lonebaggie
Thanks for the update .

Im running on Pi 3 . I use to check if my LIghtwaveRF LInk is down . Which apart from me testing it, it never has been. From what you are saying if the PI is under load the ping test fail and give a false reading.

Good to know, I will do some further testing and see if I need another solution

Re: Presence detection

Posted: Tuesday 11 April 2017 15:56
by emme
keep in mind that it is NOT ALWAYS true.... it depends on many facors:
- available power
- cpu load
- network (local) load
- usb load
- other stuff

it could be... that it could give false results... that's why a delayed check would be a great workaround.... :P

PI is a great device... but of course it has some limits....

Re: Presence detection

Posted: Saturday 15 April 2017 23:02
by Leemur
Hello,
I'm new to this but I think I found out where the issue is coming from:

Code: Select all

  # currentstate = subprocess.call('ping -q -c1 -W 1 '+ device + ' > /dev/null', shell=True)
  currentstate = subprocess.call('sudo arping -q -c1 -w 1 '+ device + ' > /dev/null', shell=True)
I guess the script usedto use a regular ping to check the presence of the device, and now it is using arping
In ping command the option -W 1 meant timeout of 1 second
Problem is that with arping the -w 1 means a timeout of 1 microsecond! This is clearly too short for any device to be able to reply in time (usually the ping is around 100-500 milliseconds)
I removed -w 1 to use the default timeout and it solve the problem \o/

Hope it helps
Cheers

Re: Presence detection

Posted: Wednesday 19 April 2017 16:30
by Ray-Man
This was exactly what I was looking for (had the same problem). Many many many thanks for sorting this out! :D

Re: Presence detection

Posted: Thursday 26 April 2018 14:24
by LennartIsHigh
Somehow if I check if the script is working I do get this message in SSH.

Code: Select all

14:17:35- according to domoticz, 192.168.1.15 is offline
14:17:36- 192.168.1.15 online, tell domoticz it's back
Traceback (most recent call last):
  File "check_device_online.py", line 117, in <module>
    domoticzrequest("http://" + domoticzserver + "/json.htm?type=command&param=switchlight&idx=" + switchid + "&switchcmd=On&level=0" + "&passcode=" + domoticzpasscode)
  File "check_device_online.py", line 96, in domoticzrequest
    response = urllib2.urlopen(request)
  File "/usr/lib/python2.7/urllib2.py", line 154, in urlopen
    return opener.open(url, data, timeout)
  File "/usr/lib/python2.7/urllib2.py", line 437, in open
    response = meth(req, response)
  File "/usr/lib/python2.7/urllib2.py", line 550, in http_response
    'http', request, response, code, msg, hdrs)
  File "/usr/lib/python2.7/urllib2.py", line 475, in error
    return self._call_chain(*args)
  File "/usr/lib/python2.7/urllib2.py", line 409, in _call_chain
    result = func(*args)
  File "/usr/lib/python2.7/urllib2.py", line 558, in http_error_default
    raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
urllib2.HTTPError: HTTP Error 400: Bad Request
I already deleted the -w 1 in the .py file but the status of my "device" will still not be updated in Domoticz. I'm sort of a noob in all this so any information would help.