If you want to monitor current bandwidth on a SNMP accessible network device, such as routers and wifi access points. Here is a tutorial on how to configure it in Home Assistant. Hopefully someone else will find it useful.
SNMP Sensor
Grabs data via SNMP from my router addressing the WAN port IN/OUT traffic via the OID:
Next we want to make it look good in the Home Assistant UI.
The code here was used to take the data in the input slider, and first create a sensor that shows us Mbps by coverting bps to Mbps. Then, I choose to setup a statistics sensor for the IN/OUT.
Finally got around to setting this up, works perfectly!!
If anyone is wanting to set this up and needs to find their OID’s I can recommend an Android app called: SNMP Traffic Grapher. Made it really easy to find the internet VLAN OID’s for my Asus router running MerlinWRT.
WARNING (MainThread) [homeassistant.components.sensor.statistics] mean requires at least one data point
ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
File "C:\Users\xbmc\AppData\Local\Programs\Python\Python36-32\lib\site-packages\homeassistant\helpers\template.py", line 99, in async_render
return self._compiled.render(kwargs).strip()
File "C:\Users\xbmc\AppData\Local\Programs\Python\Python36-32\lib\site-packages\jinja2\asyncsupport.py", line 76, in render
return original_render(self, *args, **kwargs)
File "C:\Users\xbmc\AppData\Local\Programs\Python\Python36-32\lib\site-packages\jinja2\environment.py", line 1008, in render
return self.environment.handle_exception(exc_info, True)
File "C:\Users\xbmc\AppData\Local\Programs\Python\Python36-32\lib\site-packages\jinja2\environment.py", line 780, in handle_exception
reraise(exc_type, exc_value, tb)
File "C:\Users\xbmc\AppData\Local\Programs\Python\Python36-32\lib\site-packages\jinja2\_compat.py", line 37, in reraise
raise value.with_traceback(tb)
File "<template>", line 1, in top-level template code
File "C:\Users\xbmc\AppData\Local\Programs\Python\Python36-32\lib\site-packages\jinja2\filters.py", line 542, in do_int
return int(value)
jinja2.exceptions.UndefinedError: 'None' has no attribute 'state'
WARNING (MainThread) [homeassistant.components.sensor.template] Could not render template Internet Speed, the state is unknown.
WARNING (MainThread) [homeassistant.core] Unable to find service input_slider/select_value
If i just run the snmp sensors it works, they display a huge number.
One thing that hits me is that we are referring to some input_slider's but never define them? (i added them like @firstof9 wrote but sadly that didn’t solve the issue).
It seems to work now, the values seem a bit low but time will tell, i did a network speed test and it maxed my line at about 100 Mbps both in and out but the Home assistant only showed 20 Mbps.
Neat! Would you mind sharing how you did the configuration for the status of the network devices? (i.e. online/offline)? I was looking to do a similar thing.
From yesterday i keep getting: WARNING (MainThread) [homeassistant.components.input_slider] Invalid value: -1085498964.4708297 (range 0.0 - 1000000000000.0)
and the up speed seem to have stuck.
I did update to 0.42.4 yesterday, could that have made it?
Is there a way to reset the values?
This is great. Took a bit of work as my OID for my router is different. Had to change the last number to a 4 for my ASUS RT-AC87U.
Also had to make a few alterations as some items were named differently.
The problem I’m having now is that my Speedtest Upload Average value is reporting results that are impossible for me. I have 100/40 internet, and I just down a test on speedtest.net (which gave correct values), but this sensor gave me 68 for my upload speed when 40 is my max. The result is very close to the download average. So maybe I’ve crossed my wires somewhere, but I can’t see it.
I also have an Asus router. RT-N66U
You may have the SNMP oid wrong and be monitoring the br0 interface, which is EVERYTHING which might explain different figures
Bear in mind its probably different across certain routers, especially the DSL and cable variants
For me:
eth0 = WAN
br0 = Bridge
eth1 = Wifi 2.4G
eth2 = Wifi 5G
vlan1 = LAN switch
I dont know what their oids would be and cant figure that out at the moment as Im at work, but definitely worth checking out
My RT-AC87U has 9 interfaces. Number 4 is eth0 and is what I’m using and I’ve confirmed that by SSH’ing into my router and looking at ifconfig, eth0 has the correct IP address, so it’s definatly my WAN interface.
Now that I look at it, the data for the SNMP sensors is correct, so there must be something in the automations that isn’t liked. I don’t get why when downloading a file the up is counting so much data.
Maybe I made a mistake in my config posted earlier.