Get the total time a input boolean was turned on and the average by dividing with a counter number

Senior citizen - my bad.

1 Like

No worries and thanks for taking the time to make the change.

Sorry to reawaken the thread but I landed here with a very similar question

I want to track how long my hot water is on each day
Iā€™ve created the History Stats sensor

#Track Hot Water History
  - platform: history_stats
    name: Hot Water ON today
    entity_id: sensor.hot_water
    state: "On"
    type: time
    start: "{{ now().replace(hour=0, minute=0, second=0) }}"
    end: "{{ now() }}"

Now, I may be misunderstanding this, but that reads to me that it will only give me the time today from midnight until nowā€¦

And having only just set it up it seems this is what itā€™s doing, since it has no data for past days:

This is fine, but what I really want to do is track the total for a 24hr period and have that stored day after day (in the standard history) so that I can see that today it was on for 3 hours, yesterday 2 hours etc

Iā€™m guessing that if I used

start: "{{ 0 }}"
end: "{{ now() }}"

It would simply give me the sum total from all time, which isnā€™t what i want either

Can anyone advise how I can do this daily?

You need to use the History Stats sensor with a (daily) Utility Meter sensor.

I actually found a way to do this after posting which I wasnā€™t sure would work but have just found that it doesā€¦ Frustratingly canā€™t find the post to link it now, but basically;

I created an apex graph card which does the tracking with the existing sensor

(code below)

type: custom:apexcharts-card
apex_config:
  chart:
    height: 140%
  dataLabels:
    background:
      enabled: false
    style:
      colors:
        - var(--primary-text-color)
graph_span: 1w
span:
  end: day
header:
  show: true
  title: Daily Hot Water (Time On)
experimental:
  color_threshold: true
yaxis:
  - id: left
    min: ~0
    apex_config:
      forceNiceScale: true
series:
  - entity: sensor.hot_water_daily_on
    type: column
    yaxis_id: left
    float_precision: 2
    show:
      datalabels: true
    group_by:
      func: last
      duration: 1d
    color_threshold:
      - color: '#e45e65'
        value: 4.5
      - color: '#e0b400'
        value: 3
      - color: '#0da035'
        value: 1.5
      - color: '#039BE5'
        value: 0
card_mod:
  class: top-level-chart

Thatā€™s fine as long as you donā€™t want more than about 10 days of history. Recorderā€™s default storage duration for the state history of all entities is 10 days (older data is discarded).

What I proposed stores data in a separate table within the database that is not purged and can accumulate indefinitely.

Oh thatā€™s interesting - I had been looking (for other things) to get data older than 10 days (for this I actually donā€™t think I mindā€¦ tho may later!)

Is it because a Utility Meter sensor has a special status? Any harm in whacking other things into that?

Long term statistics are stored in a table within the database that isnā€™t periodically purged. The data in this table is collected from entities that meet the criteria explained in the following documentation:
Long term Statistics

Entities produced by the Utility Meter integration meet the criteria.