Page 4 of 4

Re: Python plugin: Ubiquiti Unifi Presence

Posted: Wednesday 25 May 2022 17:39
by wizzard72
I added the UDR to the devices list. I don't know if the UDR has an accessible API and if the API is compatible with Dream Machine Pro and the Unifi Controller.

You can test if there is an API and if it's compatible with the Dream Machine Pro or the Unifi Controller. Follow these steps:
1. Login to the UDR
2. Try this URL (change the IP Address and if needed the site name. Site name is ' default'): https://192.168.0.1/api/s/default/stat/device
3. If you see a json output, then use the Unifi Controller setting in the plugin hardware page
4. If it's not working try this URL (change the IP Address and if needed the site name. Site name is ' default'): https://192.168.0.1/proxy/network/api/s ... tat/device
5. If you see a json output, then use the Dream Machine Pro setting in the plugin hardware page
6. If it's not working then the UDR doesn't work with the plugin.

Re: Python plugin: Ubiquiti Unifi Presence

Posted: Wednesday 25 May 2022 17:42
by wizzard72
peter68 wrote: Tuesday 14 December 2021 20:27 Hi,
I like this plugin, however i can't seem to get it working.
Running unifi-controller on cloudkey (gen1) and domoticz on RPI4.
Just installed a fresh installation of domoticz to test some things.
The plugin is installed succesfull, my phone device is created as it should. But it keeps telling me that i'm not at home, or at least not on the network.
I running my unifi site not as the default site on the controller.
I created a seperate user that only have access to this secondary site. With these credentials in can log in into the controller and have directly access to the right site.
This is the logging i get in domoticz:

021-12-14 20:13:30.812 unifi hardware started.
2021-12-14 20:13:30.812 Status: unifi: (unifi) Entering work loop.
2021-12-14 20:13:30.812 Status: unifi: (unifi) Started.
2021-12-14 20:13:31.216 unifi: (unifi) Debug logging mask set to: PYTHON PLUGIN QUEUE IMAGE DEVICE CONNECTION MESSAGE
2021-12-14 20:13:31.216 unifi: (unifi) setVersionCheck - Plugin allowed to start (triggered by: onStart)
2021-12-14 20:13:31.216 unifi: (unifi) onStart: Found devicestable.txt file
2021-12-14 20:13:31.216 unifi: (unifi) Number of icons loaded = 3
2021-12-14 20:13:31.216 unifi: (unifi) onStart: Items = UnifiPresenceAnyone
2021-12-14 20:13:31.216 unifi: (unifi) onStart: Icon 101 Name = UnifiPresence
2021-12-14 20:13:31.216 unifi: (unifi) onStart: Items = UnifiPresenceOverride
2021-12-14 20:13:31.216 unifi: (unifi) onStart: Icon 102 Name = UnifiPresence
2021-12-14 20:13:31.216 unifi: (unifi) onStart: Items = UnifiPresenceDevice
2021-12-14 20:13:31.216 unifi: (unifi) onStart: Icon 103 Name = UnifiPresence
2021-12-14 20:13:31.216 unifi: (unifi) login: called
2021-12-14 20:13:31.214 Status: unifi: (unifi) Initialized version 2.9.1, author 'Wizzard72'
2021-12-14 20:13:32.282 unifi: (unifi) login: Login successful into Unifi Controller
2021-12-14 20:13:32.306 unifi: (unifi) detect Unifi Devices: Invalid login, or login has expired
2021-12-14 20:13:32.306 unifi: (unifi) create_devices: Plugin Name = unifi
2021-12-14 20:13:32.306 unifi: (unifi) create_devices: Found phone to monitor from configuration = Peter=8c:b8:4a:xx:xx:xx
2021-12-14 20:13:32.306 unifi: (unifi) UpdateDevice: Update (sValue): Off --> On (unifi - Peter)
2021-12-14 20:13:32.306 (unifi - Peter) Updating device from 0:'Off' to have values 1:'On'.
2021-12-14 20:13:32.314 unifi: (unifi) UpdateDevice: Update (sValue): On --> Off (unifi - Peter)
2021-12-14 20:13:32.314 (unifi - Peter) Updating device from 1:'On' to have values 0:'Off'.
2021-12-14 20:13:32.322 unifi: (unifi) onStart: Geo Phone with name 'Geo Peter' is detected from config.
2021-12-14 20:13:32.322 unifi: (unifi) onStart: Phone Naam = OverRide | 00:00:00:00:00:00 | 255 | Off | No | No
2021-12-14 20:13:32.322 unifi: (unifi) onStart: Phone Naam = Peter | 8c:b8:4a:xx:xx:xx | 50 | Off | No | No
2021-12-14 20:13:32.322 unifi: (unifi) onStart: Phone Naam = Geo Peter | 11:11:11:11:11:11 | 80 | | No | GEO
2021-12-14 20:13:32.322 unifi: (unifi) Pushing 'PollIntervalDirective' on to queue
2021-12-14 20:13:32.323 (unifi) Processing 'PollIntervalDirective' message
2021-12-14 20:13:32.323 unifi: (unifi) Heartbeat interval set to: 5.
2021-12-14 20:13:35.029 unifi: (unifi) Pushing 'onHeartbeatCallback' on to queue
2021-12-14 20:13:35.079 (unifi) Processing 'onHeartbeatCallback' message
2021-12-14 20:13:35.079 unifi: (unifi) Calling message handler 'onHeartbeat'.
2021-12-14 20:13:35.079 unifi: (unifi) onHeartbeat: called
2021-12-14 20:13:35.079 unifi: (unifi) onHeartbeat: Attempting to reconnect Unifi Controller
2021-12-14 20:13:35.079 unifi: (unifi) login: called
2021-12-14 20:13:36.078 unifi: (unifi) login: Login successful into Unifi Controller
2021-12-14 20:13:36.079 unifi: (unifi) onHeartbeat: Requesting Unifi Controller details
2021-12-14 20:13:36.102 unifi: (unifi) request_details: Invalid login, or login has expired
2021-12-14 20:13:36.102 unifi: (unifi) login: called
2021-12-14 20:13:37.126 unifi: (unifi) login: Login successful into Unifi Controller
2021-12-14 20:13:37.149 unifi: (unifi) request_online_phones: Invalid login, or login has expired
2021-12-14 20:13:37.149 unifi: (unifi) login: called
2021-12-14 20:13:38.128 unifi: (unifi) login: Login successful into Unifi Controller
2021-12-14 20:13:40.033 unifi: (unifi) Pushing 'onHeartbeatCallback' on to queue

In the log from the unifi controller i see that user domoticz is logged in. But the domoticz log says that login is succesfull and directly invalid.

Some ideas, anyone?
regards, Peter.
Try to enter the site name with lowercase characters.

Re: Python plugin: Ubiquiti Unifi Presence

Posted: Wednesday 25 May 2022 17:44
by wizzard72
Ptje wrote: Sunday 02 January 2022 14:51 Sorry, I forgot that this is a English Site. This plugin works very fine. But does it work only with two telefoon mac's ? Or can I make it work with more ?

Met vriendelijke groet,
Peter
The plugin can handle 20 phones. Check for input errors.

Re: Python plugin: Ubiquiti Unifi Presence

Posted: Thursday 26 May 2022 8:28
by Edems88
wizzard72 wrote: Wednesday 25 May 2022 17:39 I added the UDR to the devices list. I don't know if the UDR has an accessible API and if the API is compatible with Dream Machine Pro and the Unifi Controller.

You can test if there is an API and if it's compatible with the Dream Machine Pro or the Unifi Controller. Follow these steps:
1. Login to the UDR
2. Try this URL (change the IP Address and if needed the site name. Site name is ' default'): https://192.168.0.1/api/s/default/stat/device
3. If you see a json output, then use the Unifi Controller setting in the plugin hardware page
4. If it's not working try this URL (change the IP Address and if needed the site name. Site name is ' default'): https://192.168.0.1/proxy/network/api/s ... tat/device
5. If you see a json output, then use the Dream Machine Pro setting in the plugin hardware page
6. If it's not working then the UDR doesn't work with the plugin.
Hi,

It works, thank you!
Using the Dream Machine Pro setting

Re: Python plugin: Ubiquiti Unifi Presence

Posted: Tuesday 31 May 2022 13:54
by Edems88
Edems88 wrote: Thursday 26 May 2022 8:28
wizzard72 wrote: Wednesday 25 May 2022 17:39 I added the UDR to the devices list. I don't know if the UDR has an accessible API and if the API is compatible with Dream Machine Pro and the Unifi Controller.

You can test if there is an API and if it's compatible with the Dream Machine Pro or the Unifi Controller. Follow these steps:
1. Login to the UDR
2. Try this URL (change the IP Address and if needed the site name. Site name is ' default'): https://192.168.0.1/api/s/default/stat/device
3. If you see a json output, then use the Unifi Controller setting in the plugin hardware page
4. If it's not working try this URL (change the IP Address and if needed the site name. Site name is ' default'): https://192.168.0.1/proxy/network/api/s ... tat/device
5. If you see a json output, then use the Dream Machine Pro setting in the plugin hardware page
6. If it's not working then the UDR doesn't work with the plugin.
Hi,

It works, thank you!
Using the Dream Machine Pro setting
Something is not good, it goes well for 1-2 days, after that I get such mistakes.

Code: Select all

 2022-05-31 13:53:01.767 Error: UDR: 'onHeartbeat' failed 'SSLError':'HTTPSConnectionPool(host='192.168.0.1', port=443): Max retries exceeded with url: /proxy/network/api/s/default/stat/device (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate (_ssl.c:1056)')))'.
2022-05-31 13:53:01.771 Error: UDR: Exception traceback:
2022-05-31 13:53:01.774 Error: UDR: ----> Line 1110 in '/home/pi/domoticz/plugins/Domoticz-Unifi-Presence/plugin.py', function onHeartbeat
2022-05-31 13:53:01.774 Error: UDR: ----> Line 516 in '/home/pi/domoticz/plugins/Domoticz-Unifi-Presence/plugin.py', function onHeartbeat
2022-05-31 13:53:01.775 Error: UDR: ----> Line 716 in '/home/pi/domoticz/plugins/Domoticz-Unifi-Presence/plugin.py', function request_details
2022-05-31 13:53:01.786 Error: UDR: ----> Line 546 in '/usr/lib/python3/dist-packages/requests/sessions.py', function get
2022-05-31 13:53:01.787 Error: UDR: ----> Line 533 in '/usr/lib/python3/dist-packages/requests/sessions.py', function request
2022-05-31 13:53:01.787 Error: UDR: ----> Line 646 in '/usr/lib/python3/dist-packages/requests/sessions.py', function send
2022-05-31 13:53:01.787 Error: UDR: ----> Line 516 in '/usr/lib/python3/dist-packages/requests/adapters.py', function send 

Re: Python plugin: Ubiquiti Unifi Presence

Posted: Thursday 02 June 2022 21:50
by wizzard72
I saw this error before. Because it happens after hours or days it's not easy to troubleshoot. I added some test code to solve this. So update the plugin and restart the plugin. Let me know if the error occurs.

Re: Python plugin: Ubiquiti Unifi Presence

Posted: Friday 03 June 2022 21:50
by CronoS
The plugin on the UDR is working correctly for me for a few days.. I stopped using the DZvents script; plugin is working OK...

Re: Python plugin: Ubiquiti Unifi Presence

Posted: Monday 15 August 2022 12:25
by madvisionz
wizzard72 wrote: Wednesday 25 May 2022 17:39 I added the UDR to the devices list. I don't know if the UDR has an accessible API and if the API is compatible with Dream Machine Pro and the Unifi Controller.

You can test if there is an API and if it's compatible with the Dream Machine Pro or the Unifi Controller. Follow these steps:
1. Login to the UDR
2. Try this URL (change the IP Address and if needed the site name. Site name is ' default'): https://192.168.0.1/api/s/default/stat/device
3. If you see a json output, then use the Unifi Controller setting in the plugin hardware page
4. If it's not working try this URL (change the IP Address and if needed the site name. Site name is ' default'): https://192.168.0.1/proxy/network/api/s ... tat/device
5. If you see a json output, then use the Dream Machine Pro setting in the plugin hardware page
6. If it's not working then the UDR doesn't work with the plugin.
I'm running a UDM-SE and can't get script to run. DzVents script not working anymore (worked before with USG) so now I'm trying this plugin.
First URL shows 404 and second URL 401.
Running Domoticz on Synology and log is showing:

Error: (UnifiPresence) failed to load 'plugin.py', Python Path used was '/usr/local/domoticz/var/plugins/Domoticz-Unifi-Presence/:/var/packages/py3k/target/usr/local/lib/python38.zip:/var/packages/py3k/target/usr/local/lib/python3.8:/var/packages/py3k/target/usr/local/lib/python3.8/lib-dynload:/var/packages/py3k/target/usr/local/lib/python3.8/site-packages'.
Error: (Unifi Presence) Module Import failed, exception: 'ModuleNotFoundError'
Error: (Unifi Presence) Module Import failed: ' Name: requests'
Error: (Unifi Presence) Error Line details not available.

any ideas?

Re: Python plugin: Ubiquiti Unifi Presence

Posted: Monday 15 August 2022 13:22
by waltervl
Seems that the python module 'requests' is not installed or not correctly installed.
See also https://www.domoticz.com/wiki/Using_Pyt ... ules_Fails

Re: Python plugin: Ubiquiti Unifi Presence

Posted: Saturday 25 May 2024 12:00
by CronoS
I have used this plugin for quite some time without any issue's in combination with a Dream Router, but I enabled MFA on my account which will be enforced in July by Unifi. Is there any way to use this Plugin in combination with MFA (or to workaround MFA?)? I now get a MFA prompt everytime the plugin account tries to login into the UDR; so it is not usable basically anymore.

Re: Python plugin: Ubiquiti Unifi Presence

Posted: Friday 14 June 2024 11:11
by CronoS
CronoS wrote: Saturday 25 May 2024 12:00 I have used this plugin for quite some time without any issue's in combination with a Dream Router, but I enabled MFA on my account which will be enforced in July by Unifi. Is there any way to use this Plugin in combination with MFA (or to workaround MFA?)? I now get a MFA prompt everytime the plugin account tries to login into the UDR; so it is not usable basically anymore.
For who it will help. You can create a local user account only in the UDR; that account doesn't have MFA and that is usable for the plugin

Re: Python plugin: Ubiquiti Unifi Presence

Posted: Thursday 26 September 2024 1:02
by bert
would have loved to have known this a few weeks earlier - so to anyone struggling:

The plugin stopped working after my last update of Domoticz (it had been a while since I updated last; specifically for the risk of breaking stuff)

Anyway, found a fork of the original work that worked for me:
https://github.com/lacha07/Domoticz-Unifi-Presence

Thanks Lacha07!!


The above fork fixes the Errors I encountered in the original plug-in when starting Domoticz

Code: Select all

2024-09-25 23:45:24.890  Unifi Presence: login: Login successful into Unifi Controller
2024-09-25 23:45:24.897  Error: Unifi Presence: Call to function 'onStart' failed, exception details:
2024-09-25 23:45:24.899  Error: Unifi Presence: Traceback (most recent call last):
2024-09-25 23:45:24.899  Error: Unifi Presence:   File "/usr/local/lib/python3.9/dist-packages/urllib3/connectionpool.py", line 466, in _make_request
2024-09-25 23:45:24.899  Error: Unifi Presence:     self._validate_conn(conn)
2024-09-25 23:45:24.899  Error: Unifi Presence:   File "/usr/local/lib/python3.9/dist-packages/urllib3/connectionpool.py", line 1095, in _validate_conn
2024-09-25 23:45:24.899  Error: Unifi Presence:     conn.connect()
2024-09-25 23:45:24.899  Error: Unifi Presence:   File "/usr/local/lib/python3.9/dist-packages/urllib3/connection.py", line 730, in connect
2024-09-25 23:45:24.899  Error: Unifi Presence:     sock_and_verified = _ssl_wrap_socket_and_match_hostname(
2024-09-25 23:45:24.899  Error: Unifi Presence:   File "/usr/local/lib/python3.9/dist-packages/urllib3/connection.py", line 909, in _ssl_wrap_socket_and_match_hostname
2024-09-25 23:45:24.899  Error: Unifi Presence:     ssl_sock = ssl_wrap_socket(
2024-09-25 23:45:24.899  Error: Unifi Presence:   File "/usr/local/lib/python3.9/dist-packages/urllib3/util/ssl_.py", line 469, in ssl_wrap_socket
2024-09-25 23:45:24.899  Error: Unifi Presence:     ssl_sock = _ssl_wrap_socket_impl(sock, context, tls_in_tls, server_hostname)
2024-09-25 23:45:24.899  Error: Unifi Presence:   File "/usr/local/lib/python3.9/dist-packages/urllib3/util/ssl_.py", line 513, in _ssl_wrap_socket_impl
2024-09-25 23:45:24.899  Error: Unifi Presence:     return ssl_context.wrap_socket(sock, server_hostname=server_hostname)
2024-09-25 23:45:24.899  Error: Unifi Presence:   File "/usr/lib/python3.9/ssl.py", line 500, in wrap_socket
2024-09-25 23:45:24.899  Error: Unifi Presence:     return self.sslsocket_class._create(
2024-09-25 23:45:24.899  Error: Unifi Presence:   File "/usr/lib/python3.9/ssl.py", line 1040, in _create
2024-09-25 23:45:24.899  Error: Unifi Presence:     self.do_handshake()
2024-09-25 23:45:24.899  Error: Unifi Presence:   File "/usr/lib/python3.9/ssl.py", line 1309, in do_handshake
2024-09-25 23:45:24.899  Error: Unifi Presence:     self._sslobj.do_handshake()
2024-09-25 23:45:24.899  Error: Unifi Presence: ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate (_ssl.c:1123)
2024-09-25 23:45:24.899  Error: Unifi Presence:
2024-09-25 23:45:24.899  Error: Unifi Presence: During handling of the above exception, another exception occurred:
2024-09-25 23:45:24.899  Error: Unifi Presence:
2024-09-25 23:45:24.899  Error: Unifi Presence: Traceback (most recent call last):
2024-09-25 23:45:24.899  Error: Unifi Presence:   File "/usr/local/lib/python3.9/dist-packages/urllib3/connectionpool.py", line 789, in urlopen
2024-09-25 23:45:24.899  Error: Unifi Presence:     response = self._make_request(
2024-09-25 23:45:24.899  Error: Unifi Presence:   File "/usr/local/lib/python3.9/dist-packages/urllib3/connectionpool.py", line 490, in _make_request
2024-09-25 23:45:24.899  Error: Unifi Presence:     raise new_e
2024-09-25 23:45:24.899  Error: Unifi Presence: urllib3.exceptions.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate (_ssl.c:1123)
2024-09-25 23:45:24.899  Error: Unifi Presence:
2024-09-25 23:45:24.899  Error: Unifi Presence: The above exception was the direct cause of the following exception:
2024-09-25 23:45:24.899  Error: Unifi Presence:
2024-09-25 23:45:24.899  Error: Unifi Presence: Traceback (most recent call last):
2024-09-25 23:45:24.899  Error: Unifi Presence:   File "/usr/local/lib/python3.9/dist-packages/requests/adapters.py", line 667, in send
2024-09-25 23:45:24.899  Error: Unifi Presence:     resp = conn.urlopen(
2024-09-25 23:45:24.899  Error: Unifi Presence:   File "/usr/local/lib/python3.9/dist-packages/urllib3/connectionpool.py", line 843, in urlopen
2024-09-25 23:45:24.899  Error: Unifi Presence:     retries = retries.increment(
2024-09-25 23:45:24.899  Error: Unifi Presence:   File "/usr/local/lib/python3.9/dist-packages/urllib3/util/retry.py", line 519, in increment
2024-09-25 23:45:24.899  Error: Unifi Presence:     raise MaxRetryError(_pool, url, reason) from reason  # type: ignore[arg-type]
2024-09-25 23:45:24.899  Error: Unifi Presence: urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='xxx.xxx.xxx.xxx', port=8443): Max retries exceeded with url: /api/s/Default/stat/device (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate (_ssl.c:1123)')))
2024-09-25 23:45:24.899  Error: Unifi Presence:
2024-09-25 23:45:24.899  Error: Unifi Presence: During handling of the above exception, another exception occurred:
2024-09-25 23:45:24.899  Error: Unifi Presence:
2024-09-25 23:45:24.899  Error: Unifi Presence: Traceback (most recent call last):
2024-09-25 23:45:24.899  Error: Unifi Presence:   File "/opt/domoticz/userdata/plugins/Domoticz-Unifi-Presence/plugin.py", line 474, in login
2024-09-25 23:45:24.899  Error: Unifi Presence:     self.InitAfterLogin()
2024-09-25 23:45:24.899  Error: Unifi Presence:   File "/opt/domoticz/userdata/plugins/Domoticz-Unifi-Presence/plugin.py", line 528, in InitAfterLogin
2024-09-25 23:45:24.899  Error: Unifi Presence:     self.detectUnifiDevices()
2024-09-25 23:45:24.900  Error: Unifi Presence:   File "/opt/domoticz/userdata/plugins/Domoticz-Unifi-Presence/plugin.py", line 953, in detectUnifiDevices
2024-09-25 23:45:24.900  Error: Unifi Presence:     r = self._session.get("{}/api/s/{}/stat/device".format(self._baseurl, self._site, verify=self._verify_ssl), cookies=self._Cookies)
2024-09-25 23:45:24.900  Error: Unifi Presence:   File "/usr/local/lib/python3.9/dist-packages/requests/sessions.py", line 602, in get
2024-09-25 23:45:24.900  Error: Unifi Presence:     return self.request("GET", url, **kwargs)
2024-09-25 23:45:24.900  Error: Unifi Presence:   File "/usr/local/lib/python3.9/dist-packages/requests/sessions.py", line 589, in request
2024-09-25 23:45:24.900  Error: Unifi Presence:     resp = self.send(prep, **send_kwargs)
2024-09-25 23:45:24.900  Error: Unifi Presence:   File "/usr/local/lib/python3.9/dist-packages/requests/sessions.py", line 703, in send
2024-09-25 23:45:24.900  Error: Unifi Presence:     r = adapter.send(request, **kwargs)
2024-09-25 23:45:24.900  Error: Unifi Presence:   File "/usr/local/lib/python3.9/dist-packages/requests/adapters.py", line 698, in send
2024-09-25 23:45:24.900  Error: Unifi Presence:     raise SSLError(e, request=request)
2024-09-25 23:45:24.900  Error: Unifi Presence: requests.exceptions.SSLError: HTTPSConnectionPool(host='xxx.xxx.xxx.xxx', port=8443): Max retries exceeded with url: /api/s/Default/stat/device (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate (_ssl.c:1123)')))
2024-09-25 23:45:24.900  Error: Unifi Presence:
2024-09-25 23:45:24.900  Error: Unifi Presence: During handling of the above exception, another exception occurred:
2024-09-25 23:45:24.900  Error: Unifi Presence:
2024-09-25 23:45:24.900  Error: Unifi Presence: Traceback (most recent call last):
2024-09-25 23:45:24.900  Error: Unifi Presence:   File "/opt/domoticz/userdata/plugins/Domoticz-Unifi-Presence/plugin.py", line 1108, in onStart
2024-09-25 23:45:24.900  Error: Unifi Presence:     _plugin.onStart()
2024-09-25 23:45:24.900  Error: Unifi Presence:   File "/opt/domoticz/userdata/plugins/Domoticz-Unifi-Presence/plugin.py", line 265, in onStart
2024-09-25 23:45:24.900  Error: Unifi Presence:     self.login()
2024-09-25 23:45:24.900  Error: Unifi Presence:   File "/opt/domoticz/userdata/plugins/Domoticz-Unifi-Presence/plugin.py", line 493, in login
2024-09-25 23:45:24.900  Error: Unifi Presence:     Domoticz.Error(r.status.code+" to "+Paramters["Mode4"])
2024-09-25 23:45:24.900  Error: Unifi Presence: AttributeError: 'Response' object has no attribute 'status'