Best practice for history_stats

I’m trying to watch my energy usage (without shelling out $200+ for some fancy meter reader, but it may get to that point :sweat_smile:) and I know that HVAC systems are huge energy draws.

In an attempt to gamify my HVAC usage, I’m creating a “last month’s HVAC usage” and a “this month’s HVAC usage”. This month’s HVAC usage looks weird, but I have data.

Here’s my sensor config:

- unique_id: last_month
  platform: history_stats
  name: HVAC Heating Previous Month - Heat
  entity_id: climate.thermostat
  state: "heat"
  type: time
  start: "{{ now().replace(day=1, month=now().month-1, hour=0, minute=0, second=0, microsecond=0) }}"
  end: "{{ now().replace(day=1, hour=0, minute=0, second=0, microsecond=0) }}"

- unique_id: this_month
  platform: history_stats
  name: HVAC Heating Current Month - Heat
  entity_id: climate.thermostat
  state: "heat"
  type: time
  start: "{{ now().replace(day=1, hour=0, minute=0, second=0, microsecond=0 ) }}"
  end: "{{ now() }}"

Two questions:

First, I’m guessing the reason why I have sudden drops in data is due to recorder dropping the 11th day’s history (since the default is 10 days). Can someone confirm?

Second, with the history retention in mind, what is the best practice for keeping track of stuff like this? I assume the most straight-forward way would be to increase my history to 60-90 days but I imagine the database would grow exponentially.

Or is it better to have a “yesterday” HVAC use and have automation add this number to a counter-helper?

Thanks!

Check this out: https://www.shelly.cloud/en/products/shop/shelly-em-120a/shelly-em-50a

It’s inexpensive and works really well with home assistant.

You can go even lower cost if you are into DIY: Peacefair PZEM-004T V3 Energy Monitor — ESPHome

1 Like

Not necessary (and very bad practice). Read up on long-term statistics, which are kept indefinitely.

You might then have a look at the Plotly graph card from HACS, which creates charts out of them.

@Stiltjack your answer seems to be more on the right track of what I’m looking for. Though @tom_l, I appreciate the suggestions! Definitely looking into those down the road.

In the mean time, it looks like if I want to retain statistics in the long term, I’ll have to figure out how to retain the data and then report on it.

I’ll keep looking into this and report back. It doesn’t seem straight forward.

It happens automatically if the state_class is set to measurement, total or total_increasing. Have a look at Developer Tools | Statistics - you’ll probably find you’re already retaining quite a lot.

1 Like