Track your degree days using HA and benchmark your gas consumption

I wanted to benchmark the tuning to my heating system. To do so, Degree Days (DD) is a good way of measuring energy consumption. I had some hassle to get this to work, so I wanted to share it here. I calculate the degree days using the wanted temperature, and not the actual temperature. So you can also track optimizations on your heat management algorithm.

How does it work

  1. Track the required temperature of a room, calculate a daily average
  2. Track the outdoor temperature, calculate a daily average
  3. Track the daily energy consumption
  4. Calculate the DD daily.

Requirements

configuration.yaml
Now the interesting part. Getting it to work. I put everything in one example and explain it with comments.

sensor:
  # Calculate the average outdoor temperature, restart on midnight. You could also use a weather integration
  - platform: average
    name: average_daily_outdoor_temp
    start: '{{ now().replace(hour=0).replace(minute=0).replace(second=0) }}'
    end: '{{ now() }}'
    entities: sensor.my_outdoor_temp_sensor
  # Calculate the average required temperature, restart on midnight.
  - platform: average
    name: average_daily_target_temp
    start: '{{ now().replace(hour=0).replace(minute=0).replace(second=0) }}'
    end: '{{ now() }}'
    entities:sensor.my_indoor_target_temp_sensor_or_input
  # Calculate the Degree Days, this
  - platform: template
    sensors:
      degree_day_daily:
        friendly_name: "Degree day daily"
        unit_of_measurement: 'DD'
        value_template: >
          {{ [0, states('sensor.average_daily_target_temp')|float - states('sensor.average_daily_outdoor_temp')|float] | max | round(2) }}

# Track daily gas consumption into a sensor
utility_meter:
  daily_gas_m3:
    source: sensor.gas_consumption
    cycle: daily

# Now create a template which triggers at the end of each day
template:
  trigger:
    - platform: time_pattern
      # This will update every night
      hours: 23
      minutes: 59
      seconds: 58
  sensors:
    m3_per_degree_day_daily:
      friendly_name: "m³ gas per degree day daily"
      unit_of_measurement: "m³/DD"
      value_template: >
        {% if (states('sensor.degree_day_daily')|float <= 1) %}
        0
        {% else %}
        {{ [0, states('sensor.gas_consumption')|float / states('sensor.degree_day_daily')|float] | max | round(2) }}
        {% endif %}

Screenshots

6 Likes

Nice ! Next to “mindergas.nl” use something like this. But your sensor, shouldn’t it be “M3 per degree day daily” instead of kWh ?

I’ve got no gas at home, but I do have at the office. I picked some parts from both of them, I missed this one. I will change it :).

Hello Martin, firstly Thanks for the contribution! I am migrating away from Domoticz and was figuring out a way of implementing Graaddagen in Home Assistant. I have copied and edited the file above to reflect my sensor names but unfortunately i receive a config error: Invalid config for [sensor.template]: [degree_day_daily] is an invalid option for [sensor.template]. Check: sensor.template->degree_day_daily. (See ?, line ?).

When i look at your code in the area: “# Calculate the Degree Days, this” the sentence seems unfinished. Did a typo appear in the code or did i do something wrong.

Again thanks for the work!

Hi Jeroen, sorry, I missed your reply. But I found what was missing. As I have multiple sensors below “-platform: template”, I missed a key in the yaml. I’ve edited in the example.

The “sensors:” line after “- platform: template” missed. This should fix things. If not, let me know.

Hi, I’m getting a way too high gas per DD value: last night above 400. Whereas i would expect something around 0.4. The gas usage was 6.5 m3 and the degreedays were 16.5 at that time.
Any idea what could cause this?

I’m new to HA so getting used to YAML syntax. Any recommendation where to find info to understand this shorthand notation?
{{ [0, states('sensor.gas_consumption')|float / states('sensor.degree_day_daily')|float] | max | round(2) }}

If you add state_class: measurement to your template sensor, it will be included in the statistics database for long term data.

@kannen
The template does the following, it creates a list (array). The array is between the square brackets [ and ].
It has 2 values, 0 and the current state of the gas consumption sensor states('sensor.gas_consumption') divided by the state of the degree day sensor states('sensor.degree_day_daily'). As states are always strings in Home Assistant, you need to convert it to a number using the float filter, since you can’t calculate with a string.
So that covers the [0, states('sensor.gas_consumption')|float / states('sensor.degree_day_daily')|float] part.
The | max filter then takes the highest value out of these two. This makes sure the minimum result is 0 so you won’t have negative values.
The | round(2) filter rounds the float value to 2 decimal points.
All is between double curly brackets {{ and }} to indicate it is a Jinja template.

1 Like

Hi Martin,

Thanks for the tutorial! With the current gas prices it’s good to have some more insight.

I hope you can help me with my question. I filled in the template with my outdoor temp sensor and the living room sensor as indoor sensor.

The graph I get shows high values in 20 & 21 December (40-ish) and low values on 22 & 23 December (around 33). But 22 & 23 have been really cold days. Shouldn’t the degree day value be higher on colder days because the delta outside-inside is bigger? What am I missing here?

Schermafbeelding 2021-12-23 105804

Thanks in advance!

Hi Raarr,

I don’t think these values are correct. I would expect the m3 gas/graaddag would be somewhere between 0 and 5.

Could you look into the values of the Degree Day, which is indeed larger on colder days. And also check your daily gas consumption.

I rechecked my code, but I think everything is well there.

Hi Martin!

Thanks for the reply. Let me show you what me settings are:

sensor.yaml

configuration.yaml

I think I simply made a mistake in the output graph :slight_smile: displaying m3/DD in stead of DD. Now the values vary between 7 - 12.

Thanks for sharing this ! One question … the code for the part to create a template which triggers at the end of each day, where does that go ? Is that an automation ??? Does it go into configuration.yaml ? Could you please explain ? Many thanks !!!

1 Like

I have it all setup now and these are my numbers. Is this ok?

image

All goes in the configration.yml. Maybe you have already sections of some kinds, then you can combine those. The average-sensors are calculated automatically by that integration, it has it’s own magic inside. :slight_smile:

Those numbers seem to be reasonable. You also have added the weight by month? That’s an interesting addon.

Personally, I also like to compare with a daily target temperature of 18 degrees Celcius, so the numbers are easily compared with somebody else. But for tuning your own settings, using your own values is of course better.

In Mindergas.nl i have 1.281 weighted degree day’s, so that’s correct. I don’t understand why i have 5.971 gas consumption per weighted degree day. It should be 0.268 like in Mindergas.nl.

hi, nice and simple idea, thanks!
I want to use this for monitoring a heatpump, so I replace gas_consumption with the heatpump’s energy consumption in kWh and made the utility sensor with that.
I don’t want to use the target temperature average sensor, so replaced that by 18.
Now I’m wondering, don’t you want to use that daily consumption sensor to be divided by the daily degree days? In your code I now see the general sensor.gas_consumption. And the daily value seems to remain unused.
Maybe that’s why some people here got high wrong values?
Not that I know much about coding. I share it here anyway, since there are also a few syntax changes without which I couldn’t get it to be valid. I will be able to tell if it makes more sense after midnight :smiley:

 # Calculate the average outdoor temperature, restart on midnight. You could also use a weather integration
sensor:
  - platform: average
    name: average_daily_outdoor_temp
    start: '{{ now().replace(hour=0).replace(minute=0).replace(second=0) }}'
    end: '{{ now() }}'
    entities: sensor.boiler_outside_temperature
  # Calculate the Degree Days, this
  - platform: template
    sensors:
      degree_day_daily:
        friendly_name: "Degree day daily"
        unit_of_measurement: 'DD'
        value_template: >
            {{ (18 - states('sensor.average_daily_outdoor_temp')|float) | round(2) }}
           
# Track daily gas consumption into a sensor
utility_meter:
  daily_energy_consumed_heating:
    name: daily energy consumed heating
    source: sensor.boiler_energy_consumption_compressor_heating
    cycle: daily  
# Now create a template which triggers at the end of each day
template:
 - trigger:
    - platform: time_pattern
      # This will update every night
      hours: 23
      minutes: 59
      seconds: 58
   sensor:
    - name: energy heating per degree day daily
      unit_of_measurement: "kWh/DD"
      state: >
        {% if (states('sensor.degree_day_daily')|float <= 1) %}
        0
        {% else %}
        {{ (0, states('sensor.daily_energy_consumed_heating')|float / states('sensor.degree_day_daily')|float) | max | round(2) }}
        {% endif %}   
1 Like

I like this idea. I don’t have a way to measure gas use, so I’m thinking I’ll just track heater run time vs degree days. This will still let me track the relative efficiency of my home insulation.

Hi Maarten, would you mind sharing your YAML for the yearly total and the weighted degree days?

Thanks!

Nice work here!
I was wondering, since HA already has the ability to calculate gas usage per day, is the utility meter still required or can we use the HA core mechanism for this?

Did you ever do this?, I don’t have a way to track gas meter readings but I track the time the furnace runs (I could convert it to gas volume but knowing the capacity of the furnace)