Tracking Heating Usage with Home Assistant

Hi everyone! I recently got a new heating system and I’m trying to track how long it’s been on each month. I came across the Utility Meter integration in Home Assistant and thought it might be the solution I’m looking for.

Here’s what I’m thinking: I have a Sonoff Basic acting as a relay to control my boiler. This is managed by two virtual thermostats in Home Assistant, which are scheduled using Schedy. I want to create a sensor that tracks how long the heating has been on over the month. Ideally, I’d also like to compare this to the previous month’s usage.

I found some YAML code that uses the history_stats and utility_meter integrations. It looks like this:

yaml
sensor:

  • platform: history_stats
    name: Heating ON today
    entity_id: switch.heating
    state: ‘on’
    type: time
    end: ‘{{ now().replace(hour=0, minute=0, second=0) }}’
    duration: hours: 24

utility_meter:
heating_usage:
source: sensor.heating_on_today
cycle: monthly

I’m a bit unsure about how the Utility Meter works, though. Specifically, I’m wondering if the utility meter sensor will reset if the history_stats sensor is reset, like during a Home Assistant restart. I also set the history_stats sensor to only record for 24 hours, hoping that when it starts counting the next day, the utility sensor will just add the number to the total from the previous days.

Has anyone else tried something like this? Or is there a better way to track heating usage over time? Any suggestions would be greatly appreciated!

Cheers,
Matt