I recently created some sensors and statistics to monitor my ISP (Comcast) data cap after I went over last month.
I’m using VnStat on my router (VnStat supports many platforms), which you can query via REST API, ssh, etc. Using some math we can calculate how much data is being used per month, per day and based on how much being used per day we can estimate how much data you’re going to use by the end of the month.
I am converting GiB from VnStat to GB (opnsense_vnstat_total) as that is the unit of measurement my data cap is calculated in. Update the 1229 value in cap_used_estimated and cap_used_actual to use your data cap amount for calculation.
Hey @robwolff3 great stuff, your dashboard looks amazing and I definitely like to know more about it (how you set it up, the different parts, etc…)
Also in regards to the vnstat network monitoring, i have been unable to replicate your setup (specifically the sensor), would you mind sharing how you setup your router and vnstat?
Could you kindly advise where do you get the URL for the curl command? where you have XXXX listed…
And if you could advise which files these need to be configured in. Sorry, im still new to home assistant and trying to get things done
Thanks
This looks great! I would encourage you @robwolff3 to add actual tracking from Comcast as well. Here is a docker container that will login and scrape your data from the Xfinity portal. I have found this has worked really well (been running it for about a year) and has Home Assistant over MQTT support.
Create an extra user in xfinity that you can dedicate to this, they do not need many permissions. I created a dedicated gmail account for this as the container will reset the password as required and use the gmail account to recover it. You will need the credentials for both below. Make sure the gmail account is one of the app specific passwords and the xfinity is not using two factor.
I run the docker container on another machine. My a snip-it of docker compose looks like this (you don’t need any of the labels if you don’t use traefik and set your timezone appropriately):
Thank you @bencorrado and @robwolff3! I was able to get everything working and setup as desired.
In case anyone else comes by, i setup the xfinity usage monitor nearly exactly how @bencorrado did it (see post above). I then copied the template sensors from @robwolff3 (replacing sensor.opn_vnstat_total with sensor.xfinity_usage).
@RobZed Thanks for the setup on this. The only thing I needed to update was the sensor template under xfinity_remaining_usage. Pulls everything perfect now with the docker container.
Has anyone come up with a tidy way to deal with how VnStat reports the values when they are still under 1 GiB? What I have run into can be seen here in this truncated table from VnStat:
The above is from the “Daily Statistics” table in VnStat, but the same basic problem exists with the monthly as well. The Curl query is looking for the value in “GiB”, but VnStat presents it in MiB whenever that value is less than 1 GiB.
I have been able to see the values in MiB, but they show up as a “211.37M” string. But once the 1 GiB boundary has been crossed the values are then a number vs a string. So in essence it is a string value vs a numerical value issue. And I don’t see a way to force VnStat to always present the data as GiB regardless if it is a sub 1 GiB value.
My end goal is that I want to display actual near real-time daily usage based on VnStat daily values, but this (changing) MiB vs GiB has tripped me up.
Edit to add:
Opted to use utility_meter: to extract the usage info for a days use and graphing. So far seems to be doing what I want and expect it to.
# Daily Internet usage from VnStat
utility_meter:
daily_internet:
source: sensor.opnsense_vnstat_total
cycle: daily
The basic issue I outlined for GiB values from VnStat when below 1GiB does still exist. But in my case it will only be present for a few hours of the first day of each month. I can live with that.