Page 1 of 1

Make your presence known

Posted: Friday 31 March 2017 15:30
by MatthijsD
Probably not the first to explain this, but I did a quick search and didn't really found anything.
So here goes:

I wanted to make my presence know at home for Domoticz.
Did some research on this forum and found a Python script that looks for an IP in the network. If found, your presence is know.
But, this didn't really go well, probably an outdated script.

So, I looked for something else.
I remembered I had the app Automate (https://play.google.com/store/apps/deta ... b.automate) installed on my phone and began thinking about a way to make my presence know with this and quickly saw my Wi-Fi connection as a good presence status.

I made this:
- I have a dummy On/Off switch in Domoticz "MyPresence"
- When Wi-Fi status changed, check connected to "MyWifiName"?
- Yes: HTTP request to JSON url "MyPresence" On
- No: HTTP request to JSON url "MyPresence" Off

The Events I made in Domoticz are now made with the check if "MyPresence" is on or off.
In example, when I'm home, our livingroom lights turn on when my dusk sensor goes On.
Now, with this setup: The lights won't go on when me or my girlfriend aren't at home.

Also, when everybody is gone, all lights will turn off automatically.

I hope this has some use for someone!
If you want to know more, I could post some screenshots if you want.

I've had some people asking me how I made this in Automate, so I made this explanation:
HOWTO
Automate.jpg
Automate.jpg (366.47 KiB) Viewed 2845 times
This 'flow' has been running for days without stopping, so it's pretty stable as far as I can see.

Re: Make your presence known

Posted: Friday 31 March 2017 16:02
by Siewert308SW
The script linked below does the trick for me for over 1.5 year

https://www.domoticz.com/wiki/Presence_detection

Re: Make your presence known

Posted: Friday 31 March 2017 16:30
by MatthijsD
Siewert308SW wrote:The script linked below does the trick for me for over 1.5 year

https://www.domoticz.com/wiki/Presence_detection
That's the one I'm talking about, but unfortunately my knowledge on Python is to low to fix the issues I'm having :(
But, I'm pretty happy with solution mentioned above :)

Re: Make your presence known

Posted: Friday 31 March 2017 16:33
by Siewert308SW
MatthijsD wrote:
Siewert308SW wrote:The script linked below does the trick for me for over 1.5 year

https://www.domoticz.com/wiki/Presence_detection
That's the one I'm talking about, but unfortunately my knowledge on Python is to low to fix the issues I'm having :(
But, I'm pretty happy with solution mentioned above :)
Could be more specific, what issues?

Re: Make your presence known

Posted: Friday 31 March 2017 19:00
by MatthijsD
Siewert308SW wrote:
MatthijsD wrote:
Siewert308SW wrote:The script linked below does the trick for me for over 1.5 year

https://www.domoticz.com/wiki/Presence_detection
That's the one I'm talking about, but unfortunately my knowledge on Python is to low to fix the issues I'm having :(
But, I'm pretty happy with solution mentioned above :)
Could be more specific, what issues?
After running the script, I get this:

Code: Select all

23:27:13- pid file exists
23:27:13- Seems to be an old file, ignoring.
23:27:13- script started.
Traceback (most recent call last):
  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 435, in open
    response = meth(req, response)
  File "/usr/lib/python2.7/urllib2.py", line 548, in http_response
    'http', request, response, code, msg, hdrs)
  File "/usr/lib/python2.7/urllib2.py", line 473, in error
    return self._call_chain(*args)
  File "/usr/lib/python2.7/urllib2.py", line 407, in _call_chain
    result = func(*args)
  File "/usr/lib/python2.7/urllib2.py", line 556, in http_error_default
    raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
urllib2.HTTPError: HTTP Error 404: Not Found
I had more errors, but this is as far as my knowledge goes (and my patience) ;)

Re: Make your presence known

Posted: Friday 31 March 2017 19:40
by Siewert308SW
Looks like your copy/past from a windows box to Pi.
Unzip and upload the script to your pi and see if it solves the errors.
eth_device_online.zip
(2.15 KiB) Downloaded 95 times

Re: Make your presence known

Posted: Wednesday 05 April 2017 16:50
by MatthijsD
Siewert308SW wrote:Looks like your copy/past from a windows box to Pi.
Unzip and upload the script to your pi and see if it solves the errors.
eth_device_online.zip
Thnx, I'll give it another try.
It's not on a Pi, but on a Synology NAS tho.

Re: Make your presence known

Posted: Wednesday 05 April 2017 17:25
by MatthijsD
Siewert308SW wrote:Looks like your copy/past from a windows box to Pi.
Unzip and upload the script to your pi and see if it solves the errors.
eth_device_online.zip

Code: Select all

17:23:26- script started.
Traceback (most recent call last):
  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 429, in open
    response = self._open(req, data)
  File "/usr/lib/python2.7/urllib2.py", line 447, in _open
    '_open', req)
  File "/usr/lib/python2.7/urllib2.py", line 407, in _call_chain
    result = func(*args)
  File "/usr/lib/python2.7/urllib2.py", line 1228, in http_open
    return self.do_open(httplib.HTTPConnection, req)
  File "/usr/lib/python2.7/urllib2.py", line 1198, in do_open
    raise URLError(err)
urllib2.URLError: <urlopen error [Errno 111] Connection refused>
:cry:

Re: Make your presence known

Posted: Wednesday 05 April 2017 17:28
by Siewert308SW
MatthijsD wrote:
Siewert308SW wrote:Looks like your copy/past from a windows box to Pi.
Unzip and upload the script to your pi and see if it solves the errors.
eth_device_online.zip

Code: Select all

17:23:26- script started.
Traceback (most recent call last):
  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 429, in open
    response = self._open(req, data)
  File "/usr/lib/python2.7/urllib2.py", line 447, in _open
    '_open', req)
  File "/usr/lib/python2.7/urllib2.py", line 407, in _call_chain
    result = func(*args)
  File "/usr/lib/python2.7/urllib2.py", line 1228, in http_open
    return self.do_open(httplib.HTTPConnection, req)
  File "/usr/lib/python2.7/urllib2.py", line 1198, in do_open
    raise URLError(err)
urllib2.URLError: <urlopen error [Errno 111] Connection refused>
:cry:
I see, so your running a Synology box.
My best guess thats the issue, correct me if i'm wrong but a Synology box needs a other approach on this script.
Who has a Synology and runs this script and can help this guy out?

Re: Make your presence known

Posted: Wednesday 05 April 2017 18:18
by MatthijsD
Siewert308SW wrote: I see, so your running a Synology box.
My best guess thats the issue, correct me if i'm wrong but a Synology box needs a other approach on this script.
Who has a Synology and runs this script and can help this guy out?
I used a tutorial for Synology, that used the same script: https://www.domoticz.com/forum/viewtopi ... =28&t=9921
But, help is welcome.
The Automate app is pretty good, but error sensitive :(