Runtime sensor

I’ve had a runtime sensor for my heatpump that has worked fine.
Recently there was an update and the names in MQTT changed.

I’ve updated my code with the new name but it just returns 0.

Any suggestion on what I’m missing?

Sensor.yaml:


- platform: history_stats
  name: Compressor Runtime
  entity_id: binary_sensor.hp_compressor
  state: "on"
  type: time
  start: "{{ now().replace(hour=0, minute=0, second=0) }}"
  end: "{{ now() }}"

I also have the binary_sensor.hp_compressor as history card which looks fine:

image

  1. Edit your post, the code is unformatted. Not crucial in this particular case since “history_stats” syntax does not have indents, but this is a matter of “help people to help you”.
  2. The “history_stats” platform needs an entity_id of a monitored entity. Is the “binary_sensor.hp_compressor” a proper id of this entity?
  1. It bugged for me, is it ok now?
  2. Yes, full code:
- platform: history_stats
  name: Compressor Runtime
  entity_id: binary_sensor.hp_compressor
  state: "on"
  type: time
  start: "{{ now().replace(hour=0, minute=0, second=0) }}"
  end: "{{ now() }}"
  
- platform: history_stats
  name: Compressor Starts
  entity_id: binary_sensor.hp_compressor
  state: "on"
  type: time
  start: "{{ as_timestamp( now().replace(hour=0, minute=0, second=0, microsecond=0) ) - now().weekday() * 86400 }}"
  end: "{{ now() }}"

The compressor starts counter works, it’s also that entity in the chart in my first post.

Suddenly after updating Home Assistant I get a value from today, I’ll check again tomorrow if it seems correct.

Code for “Compressor Runtime” seems OK.

Ok, so after the update of HA the sensor is working again, I can see this:

image

My ApexChart is wonky though, but it was before also.
I don’t understand why it shows 4.6 hours when the actual value is 7.5 hours.

type: custom:apexcharts-card
graph_span: 7d
header:
  show: true
  title: IVT HT+ C7
  show_states: true
  colorize_states: true
series:
  - entity: binary_sensor.hp_compressor
    transform: 'return x === "on" ? 1 : 0;'
    type: column
    name: Compressor Starts/Day
    group_by:
      func: sum
      duration: 1d
  - entity: sensor.compressor_runtime
    type: line
    name: Compressor Runtime
    group_by:
      func: avg
      duration: 1d

A bit the same here, the starts seems to become correct, but the runtime is off, I think it’s at least partially because the compressor starts before midnight and keeps running until the morning.

The history-graph shows you same 7.5 which you consider as actual.
If you have any issues with apexcharts - better to ask in the huge apexcharts thread.

1 Like