Presence detection

Moderator: leecollings

Post Reply
pkrabben
Posts: 55
Joined: Sunday 09 April 2017 15:55
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.5877
Location: Almere
Contact:

Presence detection

Post 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
User avatar
lonebaggie
Posts: 86
Joined: Tuesday 31 January 2017 13:21
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: England
Contact:

Re: Presence detection

Post 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
gerard76
Posts: 53
Joined: Wednesday 22 March 2017 9:13
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.8153
Contact:

Re: Presence detection

Post by gerard76 »

Stable even
User avatar
emme
Posts: 909
Joined: Monday 27 June 2016 11:02
Target OS: Raspberry Pi / ODroid
Domoticz version: latest
Location: Milano, Italy
Contact:

Re: Presence detection

Post 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!!!
The most dangerous phrase in any language is:
"We always done this way"
User avatar
lonebaggie
Posts: 86
Joined: Tuesday 31 January 2017 13:21
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: England
Contact:

Re: Presence detection

Post 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
User avatar
emme
Posts: 909
Joined: Monday 27 June 2016 11:02
Target OS: Raspberry Pi / ODroid
Domoticz version: latest
Location: Milano, Italy
Contact:

Re: Presence detection

Post 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....
The most dangerous phrase in any language is:
"We always done this way"
Leemur
Posts: 2
Joined: Saturday 15 April 2017 22:52
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Presence detection

Post 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
Ray-Man
Posts: 29
Joined: Friday 12 December 2014 19:03
Target OS: Linux
Domoticz version: 2021.1
Location: Zwolle
Contact:

Re: Presence detection

Post by Ray-Man »

This was exactly what I was looking for (had the same problem). Many many many thanks for sorting this out! :D
LennartIsHigh
Posts: 11
Joined: Thursday 02 November 2017 16:50
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.9700
Location: Rotterdam
Contact:

Re: Presence detection

Post 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.
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests