Page 1 of 1
Presence detection
Posted: Saturday 19 January 2019 16:13
by remko2000
I am trying to implement the following scripts:
https://www.domoticz.com/wiki/Presence_detection
In the script I only change these 3 rules (into my own data):
domoticzserver="192.168.2.1:8080"
domoticzusername = "admin"
domoticzpassword = "admin"
but I'm stuck after following al the steps. If I start my script manually in my terminal with:
python check_device_online.py MYIP xxxx 10 120
I get first
script started
and than some errrors:
File "check_device_online.py", line 101, in <module>
lastreported = domoticzstatus()
File "check_device_online.py", line 79, in domoticzstatus
json_object = json.loads(domoticzrequest(domoticzurl))
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 431, in open
response = self._open(req, data)
File "/usr/lib/python2.7/urllib2.py", line 449, in _open
'_open', req)
File "/usr/lib/python2.7/urllib2.py", line 409, in _call_chain
result = func(*args)
File "/usr/lib/python2.7/urllib2.py", line 1227, in http_open
return self.do_open(httplib.HTTPConnection, req)
File "/usr/lib/python2.7/urllib2.py", line 1197, in do_open
raise URLError(err)
urllib2.URLError: <urlopen error [Errno 110] Connection timed out>
the status in domoticz of my switch does not change.
If I open the log
check_device_online.py_myip.pid
it's empty. What can be the problem?
Re: Presence detection
Posted: Tuesday 22 January 2019 16:38
by pipiche
Python Plugin required at least Phython3.4 and above !
https://www.domoticz.com/wiki/Using_Python_plugins
So first you need to cross-check that Python3 is used by domoticz and not 2.7 as I see in the log
Re: Presence detection
Posted: Friday 08 February 2019 18:43
by unclekoen
Hee i am also into this.
I started the script manualy, no error, but also no change in the switch. Where can i find some kind of a log file??
When i do “python -V” i get version 2.7.13.
The wiki is also writing:
Check if the script works
Now we need to check if the script works when we activate it by hand. Go to the scripts directory (cd /home/pi/domoticz/scripts/) and then activate the script with the correct parameters:
python check_device_online.py IP_PHONE IDX INTERVAL TIMEOUT. For testing you can use a interval of 10 seconds and a timeout of 30 seconds, so you don't have to wait very long to see the switch turn on/off in Domoticz.
If everything works good, you should see some output like: Script already running, exiting or Needs more parameters. If you get other errors (unclear errors, that doesn't seem to be related to the script), maybe you don't have 'python' (not 'python3' !!) correctly (sudo apt-get install python), or you made a mistake when you copied the script.
Re: Presence detection (python version, syntax error)
Posted: Saturday 09 February 2019 8:26
by unclekoen
remko2000 wrote: ↑Saturday 19 January 2019 16:13
and than some errrors:
When waiting a minute i also get the same errors.
Off course, when installing Raspbian full version, Python 2.7 and 3.5 is installed.
To change the default version i used this website:
https://linuxconfig.org/how-to-change-f ... bian-linux
Python -V is nicely showing: Python 3.5.3
But next problem has appeared:
File "check_device_online.py", line 56
print datetime.datetime.now().strftime("%H:%M:%S") + "- pid file exists"
^
SyntaxError: invalid syntax
(with the ^ on the second e in line)
Re: Presence detection (forget this script)
Posted: Saturday 09 February 2019 9:13
by unclekoen
Forget this script.
There is a built in Ping in Domiticz. See here:
https://www.domoticz.com/wiki/System_Al ... %28Ping%29
Setup and working under 5 minutes.
Re: Presence detection
Posted: Friday 15 February 2019 18:30
by gschmidt
I tried system alive checker....problem is that 2 of my android phones (and they have both a fixed ip adrress on my router) constantly are kicked out....with the python presence detection script on domoticz wiki they don't, but this script is a 2.7 version and gives errors in domoticz log because domoticz is running python 3.5.3 which uses a different library for urllib2.
Still looking for a good presence detection plug-in or working py script....
Re: Presence detection
Posted: Friday 15 February 2019 18:48
by EscApe
Re: Presence detection
Posted: Friday 15 February 2019 19:33
by gschmidt
Nope...I have a router running pfsense firewall software...this blocks ssh access port 22 by default...besides that ssh to your main router is dangerous when the pi/domoticz is hacked
Re: Presence detection
Posted: Friday 15 February 2019 19:39
by gschmidt
I am not an experienced programmer...but I find it strange that the system alive checker plugin which uses the same arping library as the python script has a problem with keeping mobiles alive in the network?
Re: Presence detection (python version, syntax error)
Posted: Friday 15 February 2019 19:54
by gschmidt
unclekoen wrote: ↑Saturday 09 February 2019 8:26
remko2000 wrote: ↑Saturday 19 January 2019 16:13
and than some errrors:
When waiting a minute i also get the same errors.
Off course, when installing Raspbian full version, Python 2.7 and 3.5 is installed.
To change the default version i used this website:
https://linuxconfig.org/how-to-change-f ... bian-linux
Python -V is nicely showing: Python 3.5.3
But next problem has appeared:
File "check_device_online.py", line 56
print datetime.datetime.now().strftime("%H:%M:%S") + "- pid file exists"
^
SyntaxError: invalid syntax
(with the ^ on the second e in line)
This is because the script is written in python 2 at a time that Domoticz python version was probably the same...
urllib2 is not used in python 3...in 3 the print command should have parenthesis:
print (datetime.datetime.now().strftime("%H:%M:%S") + "- pid file exists")
there is a conversion possible...haven't tried it yet
https://docs.python.org/2/library/2to3.html
Re: Presence detection
Posted: Monday 18 February 2019 6:50
by unclekoen
gschmidt wrote: ↑Friday 15 February 2019 18:30
I tried system alive checker....problem is that 2 of my android phones (and they have both a fixed ip adrress on my router) constantly are kicked out....with the python presence detection script on domoticz wiki they don't, but this script is a 2.7 version and gives errors in domoticz log because domoticz is running python 3.5.3 which uses a different library for urllib2.
Still looking for a good presence detection plug-in or working py script....
The script is 4 years old. chopperrob doen't wants to communicate anymore (
www.chopperrob.nl), so i think this is a dead end. Unless someone else wants to rewrite the script.
I have 2 phones connected. Mine is very relax and reliable (maybe a very small time out time, i help this wit a time out time of 5 minutes (300 sec)). My girlfriends phone is not relax, continuously losing it's wifi, for some ours (when inactive). Maybe it's a setting in her phone. But at daytime, her phone my be a bit less active

so it's working good enough for me.
Re: Presence detection
Posted: Monday 18 February 2019 22:23
by gschmidt
Chopperrob's script is rocksolid when it comes to presence detection, the virtual switches are working properly eventhough it is a 2.7 script.
The only thing what annoys me is the log of domoticz which generates tonnes of errors.
I spent some time in trying to convert the script to 3.5, but i get stucked with the import of the python 3 module
urllib.request
The problem is when I run the script I get an error that
urllib.request is not found.
But when I enter "import urllib.request" manually in the python 3 console of the Rpi (which runs Domoticz),
it returns that the "<class 'urllib.request.Request'>" is available.....
I can't figure out why the script not recognizes the module...must be an environment issue somehow
I created a thread a few days ago at
viewtopic.php?f=65&t=27003, but nobody is responding

Re: Presence detection
Posted: Saturday 23 February 2019 12:35
by gschmidt
unclekoen wrote: ↑Monday 18 February 2019 6:50
gschmidt wrote: ↑Friday 15 February 2019 18:30
I tried system alive checker....problem is that 2 of my android phones (and they have both a fixed ip adrress on my router) constantly are kicked out....with the python presence detection script on domoticz wiki they don't, but this script is a 2.7 version and gives errors in domoticz log because domoticz is running python 3.5.3 which uses a different library for urllib2.
Still looking for a good presence detection plug-in or working py script....
The script is 4 years old. chopperrob doen't wants to communicate anymore (
www.chopperrob.nl), so i think this is a dead end. Unless someone else wants to rewrite the script.
I have 2 phones connected. Mine is very relax and reliable (maybe a very small time out time, i help this wit a time out time of 5 minutes (300 sec)). My girlfriends phone is not relax, continuously losing it's wifi, for some ours (when inactive). Maybe it's a setting in her phone. But at daytime, her phone my be a bit less active

so it's working good enough for me.
Jippie.....I think I found the solution for the chopperrob Presence Detection script at
https://www.domoticz.com/wiki/Presence_detection working properly under Python 3
I have the modified script at
viewtopic.php?f=65&t=27003