So i found the part about SNMP here very helpful but i couldn’t wrap my head around the template and the stats part.
and the values i measured was way off (sometimes 1500Mbs when the router reported 500Mbs and other times 160Mbs when the router reported 140Mbs ) but i think i have found the problem and an alternative solution
i believe (not at all sure) that the change rate on the statistics is just how much the value changes for each update without any regards to time, but what you really want for this (turning the running total into Mb/s) is the derivative of the value you get from the router and luckily enough there is a build in sensor for that that will calculate the derivation and take the time between updates into account.
i have done it like this:
platform: snmp
name: 'ER lite WAN In'
host: 192.168.3.1
baseoid: 1.3.6.1.2.1.31.1.1.1.6.2
community: 'public'
version: '2c'
scan_interval: 10
platform: derivative
source: sensor.er_lite_wan_in
unit_time: s
unit: B
name: erl_wan_in_derivative
platform: template
sensors:
erl_wan_in_mbps:
value_template: "{{ ((states('sensor.erl_wan_in_derivative')|float*8)/1000000)|round(2) }}"
unit_of_measurement: 'Mbps'
entity_id: sensor.erl_wan_in_derivative
friendly_name: Internet in Dev
i did a little test with this where i integrated both this and the approach described other places in this thread where i would pick to points where i had a value on each and calculate how many MB had been transferred in that time span and then calculate an error for each of the approaches and i think the results speak for them self:
glad to hear it helped you.
keep in mind when comparing this to whatever you use to verify against that what ever you are comparing to is probably doing the same thing but at a different Δt so they might not be the same but booth values can be true. (because they are essentially average transfer rates over different times.)
I was using the erx’s built in monitoring for comparison, it has a 2 sec updating bar graph that has about 80 seconds of history visible. Comparing this to my previous sensor ( averaged over a minute) the old sensor was obviously reading up to10x too high. Your version of the sensor is spot on compared to the erx’s monitor.
Thanks, the derivative method has been giving me more accurate readings. Except every once in a while, it was resulting up with a really large negative numbers (which screws up the graph view). Not sure what’s causing it (possibly my router misreporting…), but added a max function to ignore those results.
I’m wondering if with this data I can create a new template sensor or something like that to view the total traffic by day and month, would be possible?
I cant see your image. The host is blocked here. Just drag your image file into the post on the forum.
EDIT: ok that is because the sensors do not have a unit. You will probably want to change that from bytes to MB anyway. Also you have a few errors in your templates (using the in sensor for the out template).
If you are on version 0.117.x this should work:
sensor:
- platform: snmp
name: 'ERX WAN In'
host: 192.168.1.1
baseoid: 1.3.6.1.2.1.31.1.1.1.6.4
community: 'public'
version: '2c'
scan_interval: 10
- platform: snmp
name: 'ERX WAN Out'
host: 192.168.1.1
baseoid: 1.3.6.1.2.1.31.1.1.1.10.4
community: 'public'
version: '2c'
scan_interval: 10
- platform: derivative
source: sensor.erx_wan_in
unit_time: s
unit: B
name: erx_wan_in_derivative
- platform: derivative
source: sensor.erx_wan_out
unit_time: s
unit: B
name: erx_wan_out_derivative
- platform: template
sensors:
erx_wan_in_mbps:
value_template: "{{ (states('sensor.erx_wan_in_derivative')|float*8/1000000)|round(2) }}"
unit_of_measurement: 'Mbps'
friendly_name: Internet in Dev
erx_wan_out_mbps:
value_template: "{{ (states('sensor.erx_wan_out_derivative')|float*8/1000000)|round(2) }}"
unit_of_measurement: 'Mbps'
friendly_name: Internet out Dev
erx_wan_download_mib:
value_template: "{{ (states('sensor.erx_wan_in')|float/1000000)|round(2) }}"
unit_of_measurement: 'MiB'
friendly_name: Internet in Dev
erx_wan_upload_mib:
value_template: "{{ (states('sensor.erx_wan_out')|float/1000000)|round(2) }}"
unit_of_measurement: 'MiB'
friendly_name: Internet out Dev
utility_meter:
wan_in_monthly:
source: sensor.erx_wan_download_mib
cycle: monthly
wan_in_daily:
source: sensor.erx_wan_download_mib
cycle: daily
wan_out_monthly:
source: sensor.erx_wan_upload_mib
cycle: monthly
wan_out_daily:
source: sensor.erx_wan_upload_mib
cycle: daily