How do I count/display how long Nest heating/cooling was on?

Hello everyone,

I enabled Nest integratrion in HA. It shows current/desired temperature, as well as real time status - if heating/cooling is on or idle.

What I want - to have on the same dashboard heating/cooling history. Nest’s web site has such option by clicking History icon

It would be ideal for me it I can import this data directly into HA, but I have not found this option.

Nest integration shows following states and attributes

I created helper template sensor using the following statement
{{ state_attr("climate.nest_thermostat_e", "hvac_action") }}

So when I add this helper sensor into dashboard it shows me the current state - heating/cooling/idle as well as how long the state was continuing before state change occured - see duration

So my question is - how do I display of the summary of heating/cooling in hours/minutes per 24h, previous day, last week, last month and since the begining of the year in the dashboard?

It should be a just entities type card like:
HVAC Action today:
Heating - x hours y minutes
Cooling - x hours y minutes

HVAC Action yesterday:
Heating - x hours y minutes
Cooling - x hours y minutes

HVAC Action last week:
Heating - x hours y minutes
Cooling - x hours y minutes

HVAC Action last month:
Heating - x hours y minutes
Cooling - x hours y minutes

HVAC Action since Jan 1:
Heating - x hours y minutes
Cooling - x hours y minutes

Thanks

I’m also using a Nest (only for heat though), but I have a daily cumulative chart.

(Take this with a grain of salt because I’m a coding half-wit (and I got help getting this one to work correctly back in the day), but this is what I use to track when my boiler is “on” in a 24 hour period. It’s been working flawlessly for years now.)

Should be as simple as changing your entity name, and then duplicating the sensor for the ‘cooling’ parameter.

I put it on my dashboard using a graph card in lovelace showing 1 week, so I can compare daily usage.

# History Stats for Furnace
  - platform: history_stats
    name: FurnaceOnToday
    entity_id: sensor.thermostat
    state: 'heating'
    type: time
    start: '{{ now().replace(hour=0).replace(minute=0).replace(second=0) }}'
    end: '{{ now() }}'

A History Stats sensor can help. Here are four I use:

  - platform: history_stats
    name: Heat Active Today
    entity_id: sensor.hvac_action
    state: "heating"
    type: time
    start: "{{ now().replace(hour=0, minute=0, second=0) }}"
    end: "{{ now() }}"
  - platform: history_stats
    name: Heat Active Yesterday
    entity_id: sensor.hvac_action
    state: "heating"
    type: time
    end: "{{ now().replace(hour=0, minute=0, second=0) }}"
    duration:
      hours: 24

  - platform: history_stats
    name: Cooling Active Today
    entity_id: sensor.hvac_action
    state: "cooling"
    type: time
    start: "{{ now().replace(hour=0, minute=0, second=0) }}"
    end: "{{ now() }}"
  - platform: history_stats
    name: Cooling Active Yesterday
    entity_id: sensor.hvac_action
    state: "cooling"
    type: time
    end: "{{ now().replace(hour=0, minute=0, second=0) }}"
    duration:
      hours: 24

For my setup, sensor.hvac_action is a template sensor that gets the current action from an attribute of the climate entity.

Thanks. Let me setup it and then see if results match with the data at Nest account

After defining helper sensors, utility meters, history stat sensors, installing, configuring Apexcharts, here is the intermediate result