Could you help me with the command_line sensor? I have done everything on PfSense side and the python script (pffa_get_system_stats.py) works when tested on Windows Python but Hass.io says only “Command failed: python3 custom_components/pfSense/pff_get_system_stats.py <api_secret>”.
Any ideas what could be wrong? The pffa_get_system_stats.py is copied from your (bthoven) message. I have hass.io installed on raspberry pi 3 and I am on the newest HA version. Also tried to change the path of the script to “config/custom_components/pfSense/pff_get_system_stats.py”
Edit: There is typo in bthoven’s code, pffa_get_system_stats.py is missing letter ‘a’ in its name but this does not change the fact that I still do not get it working.
Edit2: Got it working with @gremblin first messages command_line method. So I put the .py files to python_scripts folder and call it there. Thanks gremblin for this guide!
Just one more question. I got all the data in hass now. But I try to parse gateway_status to sensor but I’m not getting it. Could anyone help with that?
Basically the json in like this
data: gateway_status: ipv4 address: delay
Compared to the system_stats json that is in this thread
data: stats: temp
so there is one extra step. The system_stats is parsed like this:
value_template: ‘{{ value_json[“data”][“stats”][“temp”] }}’
But I’m not getting any value from gateway_status with this
value_template: ‘{{ value_json[“data”][“gateway_status”][“ipv4 address”][“delay”] }}’
The ipv4 address is my ip. And there is also ipv6 address in the json, thats why there is one extra layer compared to the system_stats.
Edit: Got it working again, the problem was that the data was in the same file so I just added another json file where to save the data from pfsense and now the parsing works like this:
value_template: ‘{{ value_json[“data”][“gateway_status”][“ipv4 address”][“delay”] }}’
Any ideas how to get the value with value_template?
Just notice that the cpu temperature is updated at much higher frequency (in seconds) than the cpu load and memory usage (in several hours, when checking from HA ui). It is strange because all these values are derived from the same json file. Do you know why?
This is a bit off topic, but I figured a few of you might be interested in this. Here is how to setup a bandwidth SNMP polling for your pfSence WAN interface. This will give you the following entities for your viewing pleasure:
You will need to enable SNMP read access on your firewall, I used the community string of “public”. Be sure to change the host IP below to your pfSense internal interface.
I think we should keep on topic or post links to complete and/or improved alternatives (Faux API includes significantly more sensors than the bandwidth).
Did you figure out how to parse the ip4 address? I was looking at this and could only get it to work by hard coding the IP, which I would rather not do.
Hi I see this topic is a few months old but I’m having the same problem mentioned above; I have Home Assistant (not Hass.io) running in a docker container; when I run the python instruction in the command line I get the following error:
Traceback (most recent call last):
File "custom_components/pfSense/pffa_get_system_stats.py", line 3, in <module>
from PfsenseFauxapi import PfsenseFauxapi
File "/config/home-assistant/custom_components/pfSense/PfsenseFauxapi.py", line 24, in <module>
from __version__ import __version__
File "/config/home-assistant/custom_components/pfSense/__version__.py", line 1
<!DOCTYPE html>
^
SyntaxError: invalid syntax
I tried the solution @bthoven sugested but no changes. Any clue or suggestion?
I dont think you really need the version. It doesn’t look like it’s being used for any logic. Try deleting that import and just hard code it. You could just hard code it to what’s in that file. Something like:
__version__ = '20190317.1'
You can just delete that line and replace it with the above.
I modify it a now is not generating any error when executing from command line, but when I press CTRL+C I get the following:
Traceback (most recent call last):
File "custom_components/pfSense/pffa_get_system_stats.py", line 27, in <module>
PfsenseFauxapi.system_stats())
File "/config/home-assistant/custom_components/pfSense/PfsenseFauxapi.py", line 91, in system_stats
return self._api_request('GET', 'system_stats')
File "/config/home-assistant/custom_components/pfSense/PfsenseFauxapi.py", line 125, in _api_request
verify=self.use_verified_https
File "/home/chapter/.local/lib/python3.6/site-packages/requests/api.py", line 75, in get
return request('get', url, params=params, **kwargs)
File "/home/chapter/.local/lib/python3.6/site-packages/requests/api.py", line 60, in request
return session.request(method=method, url=url, **kwargs)
File "/home/chapter/.local/lib/python3.6/site-packages/requests/sessions.py", line 533, in request
resp = self.send(prep, **send_kwargs)
File "/home/chapter/.local/lib/python3.6/site-packages/requests/sessions.py", line 646, in send
r = adapter.send(request, **kwargs)
File "/home/chapter/.local/lib/python3.6/site-packages/requests/adapters.py", line 449, in send
timeout=timeout
File "/home/chapter/.local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 672, in urlopen
chunked=chunked,
File "/home/chapter/.local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 376, in _make_request
self._validate_conn(conn)
File "/home/chapter/.local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 994, in _validate_conn
conn.connect()
File "/home/chapter/.local/lib/python3.6/site-packages/urllib3/connection.py", line 334, in connect
conn = self._new_conn()
File "/home/chapter/.local/lib/python3.6/site-packages/urllib3/connection.py", line 157, in _new_conn
(self._dns_host, self.port), self.timeout, **extra_kw
File "/home/chapter/.local/lib/python3.6/site-packages/urllib3/util/connection.py", line 74, in create_connection
sock.connect(sa)
KeyboardInterrupt
Notice how the counters in the second walk align with the network interfaces from the first walk. In this case for em1 I want to use 1.3.6.1.2.1.31.1.1.1.6.2 . Let me know if you need more help.
I would do this from a linux device, I believe you need to have the “snmp” package installed. You will need to setup snmp polling on pfsense and allow the linux device to poll it.
Hrm. It looks like you interrupted it before it received any data. Do you get your stats_file (“pfSense_stats.json” in my example) to print? I’m not sure what the default timeout is for GET call, but it looks like it attempted to make the connection.