I’ve got the UPnP integration set up to connect to my router and give me some network stats, it’s great!
but there’s an issue… an issue that I’ve mentioned in the title of the post… it measures it in bytes. And this means that it very quickly reaches some sort of limit and resets itself to zero
I’ve got a DDWRT router, and the UPnP integration has given me…
bytes received
btyes sent
kB/s received
kB/s sent
packets received
packets sent
packets /s received
packets /s sent
I want…
Gigabytes Sent this day
Gigabtyes Sent this month
Gigabytes Sent this year
Gigabytes Received this day
Gigabytes Received this month
Gigabytes Received this year
Does anyone know how I can get the end result I want?
Or maybe instead of trying to do something with the UPnP is there a way to get the data straight out of DDWRT?
My router has the information in it, and I know there is some sort of API or some way to get that data out because this app exists and is able to pull that data.
What if I figure out what the max value is (found it, it’s the 32bit integer limit, 4billion-sh), the value that it resets at… then make an automation where anytime the sensor goes down from the previous reading, it increments a counter, and then use that to calculate out the gigabytes… and repeat for all 6 sensors I want.
If you want some values that are going to outlive HA reboots, we’ll need some input_numbers.
I like your idea of rollovers, but…if the router reboots, is the data cleared? Our code will probably assume this was a rollover and incorrectly add 4gb. Maybe it doesn’t reset the values on reboot?
Well, let’s hope not!
We could just store the rollover counter in these inputs. I’d do one for day/month/year tx and rx (so 6 booleans)
sensor:
- platform: template
sensors:
ddwrt_gb_day:
friendly_name: "DDWRT GB Per Day"
# Add current usage to rollover value. Add uint32 max / 1000000 to the value.
value_template: "{{ state_attr('sensor.ddwrt_bytes_received') | float / 1000000 + (states('input_number.ddwrt_tx_day') | float) * 4.295 }}"
ddwrt_gb_month:
friendly_name: "DDWRT GB Per Month"
# Add current usage to rollover value
value_template: "{{ state_attr('sensor.ddwrt_bytes_received') | float / 1000000+ (states('input_number.ddwrt_tx_month') | float) * 4.295 }}"
ddwrt_gb_year:
friendly_name: "DDWRT GB Per Year"
# Add current usage to rollover value
value_template: "{{ state_attr('sensor.ddwrt_bytes_received') | float / 1000000 + (states('input_number.ddwrt_tx_year') | float) * 4.295 }}"
...
# Repeat for Rx sensors
Now just need to handle rollover condition.
- alias: DDWRT Rollover
trigger:
platform: state
entity_id: sensor.ddwrt_gb_day
condition:
# The only way for from_state to be less than to_state is if there was a rollover
# ...OR if it's a new day and the rollover counter reset.
- condition: template
entity_id: input_number.ddwrt_tx_day
# When this value is reset (set to 0), skip this trigger.
value_template "{{ not is_state('input_number.ddwrt_tx_day', '0') }}"
- condition: template
# Otherwise, only process if this state decreases in value.
value_template: "{{ (trigger.from_state.state | float) < (trigger.to_state.state | float) }}"
action:
- service: input_number.set_value
data_template:
entity_id: input_number.ddwrt_tx_day
# Add another rollover to the value
value: "{{ states('input_number.ddwrt_tx_day') + 1}}"
- service: input_number.set_value
data_template:
entity_id: input_number.ddwrt_tx_month
# Add another rollover to the value
value: "{{ states('input_number.ddwrt_tx_month') + 1}}"
- service: input_number.set_value
data_template:
entity_id: input_number.ddwrt_tx_year
# Add another rollover to the value
value: "{{ states('input_number.ddwrt_tx_year') + 1}}"
# Clear the daily counter every day.
# Also do one for monthly counter and yearly counter....
- alias: DDWRT Daily Clear
trigger:
platform: time
at: "00:00:00"
action:
- service: input_number.set_value
data:
entity_id: input_number.ddrwt_tx_day
value: 0
You are an absolute boss. I was waking up this morning about to go the counter route, realized the counters got reset upon reboot and came here to see if any other suggestions were made, and here you are totally solving my problem entirely! You’re amazing!
Yeah, I’m struggling at the moment to get things working. I had to adjust from what you gave me a bit, and it’s mosty working, but the roll-over automation isn’t triggering. This is what I’ve got, do you see the issue?
Also, while using 2 single quotes is valid, I would recommend mixing double and single quotes. My guess is you’re using the gui? It has a strange preference to use those double single quotes…I don’t get it.
Either way, there is a random double quote at the end of that followed by a single quote. Remove the double quote.
Change the number to something lower manually. It should trigger without you having to do it yourself. No need to change it back, it will update to the correct value on the next upnp poll interval.
You’ll want a way to reset those rollover counters though. Just open the service tab and set them all to 0 if this actually works.
I just downloaded the app dd wrt companion but cannot log in! I’ve tried root/admin, root/(router maintenance password), admin/(router maintenance password) and lots more besides.
HA found it’s way in to get the data without me doing anything, the device and its entities just suddenly appeared, so it cannot be that hard.
Any advice?
I’ve also just set up the utility meter to gather energy usage weekly and monthly. I’ll see how that goes.
now it work, the “daily_gb_clear”, he set it on “0” at time: “00:00:00”
But i dont know, HA build for all automation two output:
automation.ing_fritzbox_rollover / automation.ing_fritzbox_rollover_2
automation.ing_fritzbox_daily_gb_clear / automation.ing_fritzbox_daily_gb_clear_2
…
- platform: template
sensors:
ing_fritzbox_sent_gb_day:
friendly_name: "ING-Fritzbox Upload GB Per Day"
# Add current usage to rollover value. Add uint32 max / 1000000 to the value.
value_template: "{{ (states('sensor.ing_fritzbox_kb_s_sent') | float / 1000000 + (states('input_number.ing_fritzbox_sent_day') | float) * 4.295 ) | round(2) | default('unknown')}}"
unit_of_measurement: 'GB'
ing_fritzbox_sent_gb_month:
friendly_name: "ING-Fritzbox Upload GB Per Month"
# Add current usage to rollover value
value_template: "{{ (states('sensor.ing_fritzbox_kb_s_sent') | float / 1000000 + (states('input_number.ing_fritzbox_sent_month') | float) * 4.295 ) | round(2) | default('unknown')}}"
unit_of_measurement: 'GB'
ing_fritzbox_sent_gb_year:
friendly_name: "ING-Fritzbox Upload GB Per Year"
# Add current usage to rollover value
value_template: "{{ (states('sensor.ing_fritzbox_kb_s_sent') | float / 1000000 + (states('input_number.ing_fritzbox_sent_year') | float) * 4.295 ) | round(2) | default('unknown')}}"
unit_of_measurement: 'GB'
ing_fritzbox_received_gb_day:
friendly_name: "ING-Fritzbox Download GB Per Day"
# Add current usage to rollover value. Add uint32 max / 1000000 to the value.
value_template: "{{ (states('sensor.ing_fritzbox_kb_s_received') | float / 1000000 + (states('input_number.ing_fritzbox_received_day') | float) * 4.295 ) | round(2) | default('unknown')}}"
unit_of_measurement: 'GB'
ing_fritzbox_received_gb_month:
friendly_name: "ING-Fritzbox Download GB Per Month"
# Add current usage to rollover value
value_template: "{{ (states('sensor.ing_fritzbox_kb_s_received') | float / 1000000 + (states('input_number.ing_fritzbox_received_month') | float) * 4.295 ) | round(2) | default('unknown')}}"
unit_of_measurement: 'GB'
ing_fritzbox_received_gb_year:
friendly_name: "ING-Fritzbox Download GB Per Year"
# Add current usage to rollover value
value_template: "{{ (states('sensor.ing_fritzbox_kb_s_received') | float / 1000000 + (states('input_number.ing_fritzbox_received_year') | float) * 4.295 ) | round(2) | default('unknown')}}"
unit_of_measurement: 'GB'
Template Output:
# Network Transfer per Day for 7 Days
- type: 'custom:button-card'
template: card_graph
entity: sensor.ing_fritzbox_received_gb_day
variables:
ulm_card_graph_color: "var(--google-blue)"
ulm_card_graph_name: Tagestransfer
ulm_card_graph_entity: sensor.ing_fritzbox_received_gb_day
ulm_card_graph_color2: "var(--google-green)"
ulm_card_graph_entity2: sensor.ing_fritzbox_sent_gb_day
ulm_card_graph_hours: 168
ulm_card_graph_type: fill
ulm_card_graph_points: 0.04166666666
ulm_card_graph_group_by: date