View Total Time Heating is On for Last/This Month - Value/Sensor

Hi,

I’m trying to see how long my heating has been on each month. I can see the data in history but can’t seem to extract it to a total value.

So I have the Hive Intergration and have implemented the history stats for the heating entity.

But it is showing me 0 for the last month and this month. Either I’m doing the history stats wrong or it doesn’t count histroic data.

sensor:
  - platform: history_stats
    name: Annex - Heating on This Month
    entity_id: sensor.annex_heating_activity
    state: "Heat"
    type: time
    start: "{{ now().replace(day=1, hour=0, minute=0, second=0, microsecond=0 ) }}"
    end: "{{ now() }}"


template:
  - sensor:
      - name: Annex Heating Activity
        state: "{{ state_attr('climate.annex', 'hvac_action') }}"

I coudl already see the data in the history view for the entity (see screenshot). Is there a way of counting how many hours each month my heating has been set to “heat”?

Any help would be appricated.
I just want to see how many hours the heating has been on for both my thermostats.
Thanks!

try lower case ‘heat’ … I am not sure if the sensor is case-sensitive to that but it could be

1 Like

Ahh. Good to know.

Managed to get the template to work and it now states “heating”.
So swapped the value from “Heat” to “heating”. And BINGO.

I was so close but missed that.Wouldn’t have got there without you.

Thanks.

Although I have a new problem.
I have two states “heating” and “heating - boost”.

How can i make my sensor value count both or mayeb sum togehter both sensor values?

Either two sensors or combine into one, below example will set ‘true’ if either applies, then your hist_stats can count on ‘true’
Check the {{}} piece in developer tools>templates to be sure it works

template:
  - sensor:
      - name: Annex Heating Activity
        state: {{ state_attr('climate.annex', 'hvac_action') in ('heating','heating - boost') }}

Hmm.

Okay so I got it tracking it for a new sensor. But I can’t seem to pull same data from the Hive intergration for the last month. Or at least I can but only when it was manually set. If it’s set to “auto” there seems to be no way of filtering when auto is pulling heat and when auto is just in auto mode.

I guess I need to somehow pull the hvac action attribute instead of the status.
How do I find the name of the attribute and then referance that in my sensor

See below where “.hvac_action” is the attbitute I’m trying to pull from the intergration (if thats the right name).

  - platform: history_stats
    name: House - Heating on This Month - HVAC
    entity_id: climate.house.hvac_action
    state: "heating"
    type: time
    start: "{{ now().replace(day=1, hour=0, minute=0, second=0, microsecond=0 ) }}"
    end: "{{ now() }}"

History stats uses info from history, i.e. depending on how you setup ‘recorder’ it only keeps data for a limited amount of days , with me I limited it to 10days and thus all older data gets purged
History - Home Assistant (home-assistant.io)

If you want to keep it (much) longer then you have to setup a long term statistic solutioin, read here on statistics vs. long term
Statistics - Home Assistant (home-assistant.io)

Ah okay. That would be why I can only see till the 29th.

So maybe I just stick with my sensor that is working from now.
How do I know if this will store further back than 10 days?

template:
  - sensor:
      - name: Annex Heating Activity
        state: "{{ state_attr('climate.annex', 'hvac_action') }}"

I have the below in my yaml file. And it gives me what I want currently. But how do I make this log for at least a few months or forever? So I can work out how long my heating is on each month.

Can I literally just changed “histoy_stats” to “statistics”

sensor:
  - platform: history_stats
    name: Annex - Heating on This Month
    entity_id: sensor.annex_heating_activity
    state: "heating"
    type: time
    start: "{{ now().replace(day=1, hour=0, minute=0, second=0, microsecond=0 ) }}"
    end: "{{ now() }}"


template:
  - sensor:
      - name: Annex Heating Activity
        state: "{{ state_attr('climate.annex', 'hvac_action') }}"

If you have no specific recorder section in config yam; then it follows this
Recorder - Home Assistant (home-assistant.io)

For the long term, no experience myself but I would use the output of the sensor to feed a long_term sensor…not sure which so my proposal is to create 3 and see how this works

 - sensor:
      - name: "Counter 1"
        state_class: total_increasing
        state: "{{ states('whatever sensor you have for:.Annex - Heating on This Month') |float(0) }}"

 - sensor:
      - name: "Counter 2"
        state_class: total
        state: "{{ states('whatever sensor you have for:.Annex - Heating on This Month') |float(0) }}"

 - sensor:
      - name: "Counter 3"
        state_class: measurement
        state: "{{ states('whatever sensor you have for:.Annex - Heating on This Month') |float(0) }}"

btw… doing the same for myself now… I am measuring how long my son’s PC is on (he has a time-limit) but I also want to see this longer than 10d…so this sort-of does the same during the day…it increases and then starts anew the day after… again, I have no clue what will work :slight_smile:

I have been playing around a bit and, although unexpected, the histort_stats sensor I setup is (!) available in long term statistics. This seems to contradict the documentation and other posts stating you need to a.o. add a unit_of_measurement.
Using the statistics graph card I can now go back to the initial date that I set it up…which is 22/11 and my recorder purges after 10d (1/12)
image

Okay. So I just need to put this in my yaml?
I’m not sure what I am doing with the recorder bit though. Is that right if I wanted to keep the last two months for all my sensors?

recorder:
  include:
    domains:
      - sensor
  purge_keep_days: 65
template:
  - sensor:
      - name: "House Heating Activity Counter 1"
        state_class: total_increasing
        state: "{{ state_attr('climate.house', 'hvac_action') |float(0) }}"
  - sensor:
      - name: "House Heating Activity Counter 2"
        state_class: total
        state: "{{ state_attr('climate.house', 'hvac_action') |float(0) }}"
  - sensor:
      - name: "House Heating Activity Counter 3"
        state_class: measurement
        state: "{{ state_attr('climate.house', 'hvac_action') |float(0) }}"

So I found this. As everywhere I searched people kept saying use a database.

Hopefully it works.

recorder:
  db_url: !secret mariadb_url
  purge_keep_days: 65
  include:
    domains:
      - climate
    entities:
      - sensor.house_heating_activity
      - sensor.annex_heating_activity
template:
  - sensor:
      - name: "House Heating Activity Counter 1"
        state_class: total_increasing
        state: "{{ state_attr('climate.house', 'hvac_action') |float(0) }}"
  - sensor:
      - name: "House Heating Activity Counter 2"
        state_class: total
        state: "{{ state_attr('climate.house', 'hvac_action') |float(0) }}"
  - sensor:
      - name: "House Heating Activity Counter 3"
        state_class: measurement
        state: "{{ state_attr('climate.house', 'hvac_action') |float(0) }}"

As per my previous post… seems not needed as mine shows data via the statistics graph earlier than the purge date.

I would NOT put the recorder on 65 days as it will grow to quite big size, that is why/when the long-term statistics come in, they only register per hour where states per ‘few seconds’ hence these require to be purged.