History_stats tracking heater usage, not working

I try to track heater usage on last 30 days. Some times it works but generally it gives values which are a way of from reality

I have following config

  - platform: history_stats
    name: ULkohuone lämmitys ON (viim. 30pv) h
    entity_id: switch.ulkohuone
    state: "on"
    type: time
    end: "{{ now().replace(hour=0, minute=0, second=0) }}"
      days: 30

If i check it from Influxdb, there I see these spikes. What could be the cause?

I suggest you consider doing this:

Create a History Stats sensor that reports the current day’s total heating time.

  - platform: history_stats
    name: ULkohuone
    entity_id: switch.ulkohuone
    state: "on"
    type: time
    start: "{{ today_at() }}"
    end: "{{ now() }}"

Create Utility Meter sensors that report daily, monthly, and yearly total heating time.

    source: sensor.ulkohuone
    cycle: daily
    source: sensor.ulkohuone
    cycle: monthly
    source: sensor.ulkohuone
    cycle: yearly

The data for Utility Meter sensors is stored in Home Assistant’s statistics table which is not purged and held indefinitely.

That’s the method I use to track heating and cooling time (and I now have over a year’s worth of data).

@123 Thanks, I will test this.

Any progress to report?

Yes, now it works. Thanks.

1 Like

You’re welcome!

Please consider marking my post above with the Solution tag. It will automatically place a check-mark next to the topic’s title which signals to other users that this topic is resolved. This helps other users find answers to similar questions.

For more information about the Solution tag, refer to guideline 21 in the FAQ.