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
Track the required temperature of a room, calculate a daily average
Track the outdoor temperature, calculate a daily average
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 %}
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.
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.
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?
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 !!!
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.
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
# 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 %}
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.
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)