Time heating on

Hi all

I would like to have shown how much time the heater was on on a daily basis, and possibly get also a graph where I can choose to show weekly or monthly.

My thermostat is Netatmo

Now I have created this sensor

  - platform: history_stats
    name: history_stats_caldaia
    entity_id: climate.termostato
    state: 'on'
    type: time
    end: '{{ now() }}'
    duration:
      hours: 24

Is it ok like this?

What should I add/modify to get what I want?

Thanks

I think that will report for a period representing the last 24 hours. In other words, the starting time is the time you look at the sensor minus 24 hours.

If you want it to report for a period representing the current day you need to use start and set it to the beginning of the current day (using a calculation). The documentation provides an example:

  - platform: history_stats
    name: Lamp ON today
    entity_id: light.my_lamp
    state: 'on'
    type: time
    start: '{{ now().replace(hour=0).replace(minute=0).replace(second=0) }}'
    end: '{{ now() }}'

Here is how I use it in my system:

  - platform: history_stats
    name: Heating Hours Today
    entity_id: climate.thermostat
    state: 'heat'
    type: time
    start: '{{ now().replace(hour=0).replace(minute=0).replace(second=0) }}'
    end: '{{ now() }}'
1 Like

Thanks @123

I will try this way!!!

What about unit of measurement?

Iā€™ve tried this

  - platform: history_stats
    name: history_stats_caldaia
    entity_id: climate.termostato
    state: 'heat'
    type: time
    start: '{{ now().replace(hour=0).replace(minute=0).replace(second=0) }}'
    end: '{{ now() }}'
    
  - platform: template
    sensors:
      caldaia:
        friendly_name: Utilizzo caldaia
        icon_template: mdi:radiator
        value_template: '{{ states.sensor.history_stats_caldaia.attributes.value }}'
        unit_of_measurement: 'min'

because in the entity I see that the value is shown as minutes (I used 4 minutes), but in the attributes is show as hours.

03

Try this:

  - platform: template
    sensors:
      caldaia:
        friendly_name: Utilizzo caldaia
        icon_template: mdi:radiator
        value_template: "{{ states('sensor.history_stats_caldaia') | float * 60 }}"
        unit_of_measurement: 'min'

All state values are stored as text (string). This sensor stores the elapsed time (in hours) as numeric text. The template uses float to convert the numeric text into a floating point number. It multiplies the number by 60 to convert from hours to minutes.

1 Like

Perfect, thanks!!

Hi

using this template there is the possibility to get also floating ā€œminutesā€.

I tried to replace float with int, but probably is not the right way.

Is there a way to get an rounded integer number?

    value_template: "{{ states('sensor.history_stats_caldaia') | float * 60 }}"

Eventually, how can I show sensor.history_stats_caldaia.attributes.value using a template?

Iā€™ve tried this way but it dowsnā€™t work, I get ā€˜unknownā€™.

  - platform: template
    sensors:
      caldaia_hr:
        friendly_name: Utilizzo caldaia hr
        icon_template: mdi:radiator
        value_template: "{{ sensor.history_stats_caldaia.attributes.value }}"
        unit_of_measurement: 'ore'

42

Thanks

Just round it Sorry, miss read post. use the following

  - platform: template
    sensors:
      caldaia:
        friendly_name: Utilizzo caldaia
        icon_template: mdi:radiator
        value_template: "{{ state_attr('sensor.history_stats_caldaia', 'value') }}"
1 Like

And the reason sensor.history_stats_caldaia.attributes.value didnā€™t work is because you left out the states..

   |
   V
states.sensor.history_stats_caldaia.attributes.value

Thanks again!!!

Hi

The history stats I have is not working anymore.

  - platform: history_stats
    name: history_stats_caldaia
    entity_id: climate.termostato
    state: 'heat'
    type: time
    start: '{{ now().replace(hour=0).replace(minute=0).replace(second=0) }}'
    end: '{{ now() }}'

I read about the time and time_pattern, but I canā€™t apply time_pattern here (I get error during check).

Simply the sensor does not get updated.

31

Any suggestion?

Thanks

Check if you have excluded this entity in history component as it uses that.

This is my configā€¦

history:
  exclude:
    domains:
      - automation
      - weblink
      - updater
      - media_player
  include:
    domains:
      - sensor
      - binary_sensor
      - light
      - switch

looks good, are you able to see the stats on this entity ā€œclimate.termostatoā€ on the history tab?

Are you using recorder in conjunction with history?

@petro yes, i have configured both.
@Prathik_Gopal
it seems that the issue was related to MariaDB.
I decided to switch some days ago, since the hom-eassistant_v2.db was growing up really fast, even if I have

  purge_keep_days: 7
  purge_interval: 1

So, now I removed the db_url line of code and seems to work againā€¦

Thanks all

I have to understand better where was the issueā€¦

Recorder is what history pulls from if you use both recorder and history. I.E. You need to track it in recorder for it to show up in history. So if you arenā€™t recording that sensor in recorder, the history_stats wont work at all and the sensor wont appear in history even if you configure it to.

Without recorder, history is what controls what goes into history.

1 Like