History stats sensor issue

Ok, so maybe I’m blind, or misunderstanding something, but I’m having an issue with a history_stats sensor. Maybe someone can help.

Background:
I’m trying to break out the hvac_action attribute of the hive system, so I can then create an automation to track if the heating has been on in the last 12 hours. This is to aid me in the mornings, when I’m a zombie, to know if I should use the electric shower, or if there’s sufficient hot water. (Note, when heating is active, the system also heats my water.) The automation will cause my bathroom light to change colour or flash, when there’s hot water, so I don’t need to think, or check my phone. Remember, I’m a zombie in the morning!

Sensors:
The attributes I need are part of climate.upstairs, and climate.downstairs, and I’ve managed to break these out into their own sensors.

#
### Break out Hvac_action from hive climate sensor
#
      downstairs_hvac:
        friendly_name: Downstairs Hvac
        value_template: '{{ state_attr("climate.downstairs", "hvac_action") }}'
#
      upstairs_hvac:
        friendly_name: Upstairs Hvac
        value_template: '{{ state_attr("climate.upstairs", "hvac_action") }}'

All good so far.

The next step was to use the history_stats function to track those two sensors for 12 hours.

sensor:

# Keep track of how long the heating has been on.
  - platform: history_stats
    name: downstairs heating
    entity_id: sensor.downstairs_hvac
    state: "heating"
    type: time
    end: "{{ now() }}"
    duration:
      hours: 12

  - platform: history_stats
    name: upstairs heating
    entity_id: sensor.upstairs_hvac
    state: "heating"
    type: time
    end: "{{ now() }}"
    duration:
      hours: 12

I thought I was tracking the sensors successfully, but it’s become obvious that sensor.upstairs_heating is not working, while sensor.downstairs_heating is working as intended.

Can anyone help? What have I missed?

What does this mean?

What specifically is happening?

The child sensor has to have updated and entries have to exist in the recorder database for history stats to function.

What is the state of sensor.upstairs_hvac, and has it changed?

Haven’t used the stats much, so won’t be helpful there.

I think a template binary sensor with a delay_on for 12 hours would do the trick.

Basically, you want to say. If hvac has been idle for 12 hours then be true.

What if it was heating, but only for 1 minute during that 12 hours?

The history stats sensor is a better option.

Sorry, I should have been more clear. The downstairs sensor is working as intended and showing the duration of when (downstairs) hvac_action is heating. The upstairs sensor is not.

upstairs hvac issue 2
Downstairs hvac_action sensor

upstairs hvac issue 4
Output from sensor.downstairs_heating as expected.

upstairs hvac issue 1
Upstairs Hvac_action sensor

upstairs hvac issue 3
Output from sensor.upstairs_heating not as expected.

Basically, sensor.upstairs_heating did not record the state change of sensor.upstairs_hvac and I can’t see why.

I was originally looking at a binary sensor, but it’s always possible that the heating might be on for 5 minutes or less, which not heat enough water for a shower. So instead I wanted to output how long it was active for and then create an automation that would do something if the heating was on for more than a half hour. (flash a bulb, change colour, or something like that.)

Hover your mouse here:

ad0fd9a65ee03c76c0cb4044da2b110c035abb93

What is the state?

state is either idle or heating. The area you’ve pointed to is heating.
Both upstairs and downstairs are identical except for the sensor names.

Are you using !includes for sensors or is all this in your configuration.yaml file?

All in configuration.yaml.
It’s got me baffled, as I don’t see why one works and the other doesn’t. The code is identical for both, with the exception of the specific sensors, and they’re pulling from the one system (hive).

How many times does sensor: appear in your configuration.yaml file?

Just the once.

I might just have had a light bulb moment.
I think I need a restart. I made a change to the upstairs sensor after the sensor was created. (I had “heat” instead of “heating” as the state.) but I don’t remember if I restarted HA after I made the final change …

That would do it.

God damn it, it’s always the little things that get you. Fingers crossed that that’s all it is…

That was it. 1 restart later and everything is working as expected. I can’t believe that’s all it was.
Thanks for the help. :slight_smile:

1 Like