I have a sensor that tracks/increments internet usage in gigabits. So, the value increments up (and the state changes) as bandwidth is consumed in Gigabits (rounded to 3 decimal places).
I’ve tried the following automation based on the last change but it won’t toggle on/off reliably -
switch:
input_boolean:
josh_online:
name: Josh is online
initial: off
icon: mdi:wifi
I also tried this as well to pick up on the integer value changing - but this did not work - I also tried just using toggle but that did not work either.
Thanks! One follow-up. I’ve set up the history_stats sensor but I’m unclear as to what “state” to use for a bandwidth number that is going up. I was reading the binary sensor state: ‘on’ but I know that isn’t right. Do I need a value template for the state to see it going up?
Thanks!
I misguided you. You don’t need a history statistics sensor, but a statistics sensor. This can measure another sensor over a periode of time. Please find below an example that I have tested with my power consumption.
sensor:
- platform: statistics
name: Power Consumption Normal Last Minute
entity_id: sensor.power_consumption_normal
max_age:
minutes: 1
binary_sensor:
- platform: template
sensors:
power_consumption_normal_changed:
friendly_name: Power Consumption Normal Changed
value_template: >-
{{ state_attr('sensor.power_consumption_normal_last_minute_mean', 'change') > 0 }}
Yes, very helpful. I’ve implemented it and for some reason the ‘change’ attribute does not return to zero when I stop streaming data. I also created a second sensor on the primary scraped data stream (with more digits) but it stays above zero and the binary sensor never switches off. Does it need to collect more data to operate effectively possibly? Definitely on the right track. Thanks again for the help. I’ll keep an eye on it and see if things change.
Config is same as you suggested above.
Example stat output:
mean: 0.96
count: 6
max_value: 0.966
median: 0.96
min_value: 0.957
sampling_size: 20
standard_deviation: 0
total: 5.77
variance: 0
change: 0.009000000000000008
average_change: 0.0018000000000000017
max_age: 2018-06-07T04:17:28.037370+00:00
min_age: 2018-06-07T04:16:35.169894+00:00
unit_of_measurement: Gb
friendly_name: Josh Data Today mean
icon: mdi:calculatormean
Thanks. I did something similar last night. The root cause is i’m using a rounded number. I chose the raw data field with the number of bits and rounded/adjusted as you are suggesting. Here is where i’m at. Looks promising. I;ll let it run for the day and report back. Thanks
So, the statistics are coming through
And I can see the binary sensor change:
But I cannot see the history stats. They are not showing any results.
Any thoughts? Thanks
Yes, for the duration of time that I am on-line based on inbound data usage (scraped from a router page). The data usage all works well but I can’t seem to get the history sensor to populate off of the binary sensor.
It did work when I had a regular binary sensor (with my original automation binary sensor approach) but since i’ve been trying the history_stats, it won’t populate with the hours (and minuutes) that it is ‘True’, True, ‘On’, on, etc. I’ve tried every combo I can think of…
The history stats in the above example measures how long you have been online in the first minute of the current hour. In think.
You should set the duration differently.
What I would do is set the end time to now() and have a duration of 1 hour ‘1:00:00’. This sensor will then show how long you have been online in the last 60 minutes.