Hi @revin. I’ve updated the code in the first post.
Try replacing
numclients = health[0]['num_user']
with
numclients = len(clients)
And see if it is solved.
@thundergreen Sure it is, but I am not that experienced in python to build it myself.
@juan11perez After having read the docs of the module’s developer, I do not think you can read 3 APs with the same script. So it is better to make 3 different scripts.
will this automaticall download the library? u use this library if i well understand from unificontrol import UnifiClient
any helo here? Getting this error:
bash-5.0# python3 unifi.py
Traceback (most recent call last):
File "unifi.py", line 18, in <module>
stat = client.stat_sysinfo()
File "/usr/local/lib/python3.8/site-packages/unificontrol/metaprogram.py", line 125, in wrapper
return instance(client, *a, **kw)
File "/usr/local/lib/python3.8/site-packages/unificontrol/metaprogram.py", line 103, in __call__
return client._execute(url, self._method, rest_dict, need_login=self._need_login)
File "/usr/local/lib/python3.8/site-packages/unificontrol/unifi.py", line 110, in _execute
response = resp.json()
File "/usr/local/lib/python3.8/site-packages/requests/models.py", line 900, in json
return complexjson.loads(self.text, **kwargs)
File "/usr/local/lib/python3.8/site-packages/simplejson/__init__.py", line 525, in loads
return _default_decoder.decode(s)
File "/usr/local/lib/python3.8/site-packages/simplejson/decoder.py", line 370, in decode
obj, end = self.raw_decode(s)
File "/usr/local/lib/python3.8/site-packages/simplejson/decoder.py", line 400, in raw_decode
return self.scan_once(s, idx=_w(s, idx).end())
simplejson.errors.JSONDecodeError: Expecting value: line 2 column 1 (char 1)
my config:
host = '192.168.1.1'
username = 'hassio'
password = 'HassIo123'
site = 'default'
port = '443'
mac = 'E0:63:DA:CE:08:C1' ## the mac address of your AP device
You will have to pip3 install unificontrol the module first.
As for the other part, I am running home assistant core on windows, so i cannot really help if you’re running the hassOs on raspberry pi etc. as I have zero experience with that. Sorry.
Also, I’ve updated the script in the first post, so check if this solves any problems. Make sure to read the whole script and perhaps comment out anything that might not work for you.
@revin Hey, have you tried with my suggested edit numclients = len(clients) to see if the clients are reported correctly?
I only have one AP so I cannot really test your situation.
After reading the developer’s docs, I assume that this change will only return the clients per AP.
I’ve changed the code for the new one. I made no change except my config (user, server…) and it gives me this error:
hass@hass:~/1/unifi$ python3 unifi_ap_1.py
Traceback (most recent call last):
File "unifi_ap_1.py", line 46, in <module>
wifi0clients = sum(1 for _ in re.finditer(r'\b%s\b' % re.escape('wifi0'), str(clients)))
NameError: name 're' is not defined
edit:
Now it works. I had to add to the script “import re” and also modify print (f) to print (final). The output is:
@revin My knowledge of python is also very basic.
In this case I just read the info provided on the endpoints, and then try to extract any useful information.
What you can do is print the results of the endpoints and find out what info you want to extract based on your system
# for example #
devs = client.list_devices(mac)
clients = client.list_clients()
print (clients)
print (devs)
# etc #
Also, have a look at the module’s documentation where all the available endpoints and commands are listed!
Hi,
There is a method to call for statistics with 5 minute granularity (see the docs here)
Maybe you can specify there the tx, rx attributes.
However, I do not personally use it so I can’t really help any further.
Trying to make this work on a HASSOS installation, could you let me know what sensor configuration you are using? I’ve tried to use command line but its not working!