Template Sensor for "Kwartiervermogen" (15-Minute Average Power)

Hi everyone,

I’m trying to create a template sensor in Home Assistant that continuously calculates the average power consumption within fixed 15-minute intervals. The sensor should reset when a new quarter starts and only include values from the current quarter.

What I Want to Achieve:

  • The quarter starts at fixed timestamps (e.g., 18:00, 18:15, 18:30, etc.).
  • If I check at 18:05, it should calculate the mean power from 18:00 to 18:05.
  • If I check at 18:44, it should calculate the mean power from 18:30 to 18:44.
  • When a new quarter starts, the sensor should reset and only consider the new period.

The calculation should be based on sensor.p1_meter_power (real-time power measurement).

The reason I need it, is because the electricity bill here (in Belgium) is partially based on a “capacity tarrif”, which is based on the average power consumption on each of these 15 minute intervals. So if 10 minutes of the 15 minutes have passed, I would like to have a warning from HA to reduce my consumption for the remained of the time.

Does anyone know how to approach this?

Use this custom integration:

It can do 15 minute clock intervals (rather than last 15 minutes) using the start and end templates.

start: '{{ now().replace(minute = now().minute - now().minute % 15).replace(second=0) }}'
end: '{{ now() }}'

I’m pretty sure the start template is correct but it is untested. Check it in the developer tools template editor.

1 Like

Wow, amazing. This was like the perfect answer!

Thanks a lot!

1 Like