Utility_meter cyles

@gijbelsy
Have you been able to configure something successfully?

I was looking to see if I could do something in HA to calculate this new peak consumption every 15 minutes. Not really successful so far. :frowning:

If I understand correctly the Fluvius website, it is not the peak or maximum reading every 1/4 hour, but the average peak power every 1/4 hour:

The monthly peak corresponds to the highest quarter-hourly power - or average power on a quarter-hourly basis - that you have used in a month; not the highest instantaneous power.

First an overview of what we need (what I think we need, correct me if I did interpret not correctly the Fluvius website…):
In my case, I have a sensor giving me each second the power consumption in W(att), so I get 900 samples each 15 minutes.
Example:
We have 4 x 15 minutes in a hour and we are starting our first month
00:00:01 - 00:15:00 : calculate the average of the 900 samples, take the value and store it as max
00:15:01 - 00:30:00 : calculate the average of the 900 samples, take the value and see if > than previous value, if not do nothing, if yes, store it as max
00:30:01 - 00:45:00 : calculate the average of the 900 samples, take the value and see if > than previous value, if not do nothing, if yes, store it as max
00:45:01 - 01:00:00 : calculate the average of the 900 samples, take the value and see if > than previous value, if not do nothing, if yes, store it as max

At the end of the month, I take the max value of the first month.
If it is < 2.5 kW store 2.5 kW (minimum) else store the value.
Then the cycle begins again for the second month.
And so on.
After 12 months we calculate the average of the 12 months.
if it is < 2.5 kW take 2.5 kW else take the calculated value.
That will be the capacity peak to pay.

Now we must configure that into HA :thinking:
Someone an idea where to begin?
Is it even possible in HA with the existing platforms like Min/Max, Statistics, History-Stats, Utility_meter, …?

1 Like

I’m running some tests here with the suggested statistics sensor.
For now the configuration is the mean value of the power consumption. The data is reset every 15 hrs.
What I can’t figure out from the Fluvius website is the calculation of the 15 minute peak value:
Is this every quarter of the hour, or gliding 15 minutes?
I’ll report back on that.

Thinking about the idea of @fb22 to use the utility_meter to get the average power

kW x time = kWh
or
kW = kWh / time

for example :
1 kWh per quarter of an hour
a quarter of an hour = 0.25 hour
1 / 0.25 = 4 kW average peak power per quarter of an hour

The big problem, the standard utility_meter component does not have a cycle of a quarter of an hour.

I’ve made a custom_component based on the existing utility_meter and extended it with a QUARTERHOUR cycle option.
I will test this and if it works and gives me the needed information, I will create a pull request to the home assistant core to extend the default utility_meter component with the quarter-hour cycle.

to be continued.

Here is what I’m currently testing with:

# Kwartierpiek
- platform: statistics
  entity_id: sensor.energie_400V_totaal_actief_vermogen
  name: energie_kwartierpiek
  precision: 1
  sampling_size: 900
  max_age:
    minutes: 15

This gives me the statistics of my active power over 15 minutes.
Then with a template I visualize the mean value:

- platform: template
  sensors:
    # Energie: kwartiergemiddelde
    energie_kwartierpiek_gemiddelde:
      value_template: '{{ states.sensor.energie_kwartierpiek.attributes.mean  }}' 
      friendly_name: 'Energie kwartier piekgemiddelde' 
      unit_of_measurement: 'W'

This leaves me with 2 other statistics sensors, one for the monthly and one for the yearly peak values.

1 Like

@gijbelsy,
I have created your two sensors in my configuration with my total grid consumption sensor.
The two sensors are giving me the same values, what, I think, is correct.

From the Statistics page (Statistics - Home Assistant)

The statistics sensor platform consumes the state from other sensors. It exports the mean value as state and the following values as attributes: count , mean , median , stdev , variance , total , min_value , max_value , min_age , max_age , change , average_change and change_rate . If it’s a binary sensor then only state changes are counted.

The first sensor ‘energie_kwartierpiek’ will give you already the mean value as state.
The second sensor ‘energie_kwartierpiek_gemiddelde’ will give you the same value via his attribute ‘mean’.

This configuration is giving the average peakpower for the last 15 minutes.
But that is not what we must have if I understand it correctly from the Fluvius website, see one of my previous posts : Utility_meter cyles - #7 by evb

My tests with the custom utility_meter with quarter-hour cycle, did reveal that I did had a 3 kW peak in the last 2 days…
(not the 5 days, I had to correct my statistics sensor for the month because the sampling_size was not correct → one sample per second → 900 samples per quarter-hour, x 4 per hour, x 24 per day, x 31 per month = 2678400, did take now as sampling-size 2700000)
But the main question is still : is my assumption correct for calculating the average quarter-hour peakpower? Utility_meter cyles - #9 by evb

still to be continued

Meanwhile, @thomasdelaet did do a pull request for extending the utility_meter integration with a quarter-hourly option : Add quarter-hour period feature for utility_meter component by thomasdelaet · Pull Request #41999 · home-assistant/core · GitHub

In the utility_meter component, add support for 15 minute intervals (quarter-hours).

one (and my :slight_smile: use case for this is that in Belgium, a significant part of your electricity bill is going to be based on your peak usage per 15 minute interval. Measuring and managing this peak usage can help to reduce cost.

Documentation at home-assistant/home-assistant.io#15290

I hope to see his pull request accepted and done for the version 0.117.0 of HA.

I switched also to the influxdb v2 integration to store de raw data, because my HA database is limited to store only 5 days of data, otherwise it is explosing in size.

On the influxdb side I added two graphs on the dashboard, one based on the value calculated by the utility_meter integration based quarterhourly and on based on the raw value of my realtime smappee sensor giving the power consumption of the grid in W each second.

Calculated value utility_meter quarterhourly

maxAverageQuarterHourData = from(bucket: "homeassistant")
  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
  |> filter(fn: (r) => r["friendly_name"] == "Gemiddeld piekvermogen per kwartier")
  |> filter(fn: (r) => r["_field"] == "value")
  |> filter(fn: (r) => r["_measurement"] == "kW") 
  |> aggregateWindow(every: 15m, fn: max, createEmpty: false)
  |> yield(name: "maxAverageQuarterHour")

maxMonthData = maxAverageQuarterHourData
  |> aggregateWindow(every: 1mo, fn: max, createEmpty: false) 
  |> yield(name: "maxMonth")

maxMonthData
  |> aggregateWindow(every: 1y, fn: mean, createEmpty: false) 
  |> yield(name: "averageYear")

Raw value of smappee sensor grid consumption

averageQuarterHourData = from(bucket: "homeassistant")
  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
  |> filter(fn: (r) => r["friendly_name"] == "Net afname")
  |> filter(fn: (r) => r["_field"] == "value")
  |> filter(fn: (r) => r["_measurement"] == "W") 
  |> aggregateWindow(every: 15m, fn: mean, createEmpty: false)
  |> yield(name: "averageQuarterHour")

maxMonthData = averageQuarterHourData
  |> aggregateWindow(every: 1mo, fn: max, createEmpty: false) 
  |> yield(name: "maxMonth")

maxMonthData
  |> aggregateWindow(every: 1y, fn: mean, createEmpty: false) 
  |> yield(name: "averageYear")

Of course to get and see the 12 month values, we must have the data of 12 months…
You can experiment by setting for example 1 day instead of 1 month and 12 days instead of 1 year.
At that moment you can already test the graph layout.

Why two graphs?
You see that the two graphs are grosso modo identical, meaning that the assumption to use the calculated utility_meter quarterhourly is correct (see my previous post)

Hereunder an example of my output. The line you see between the two blocks is when the influxdb v2 integration did have a bug when going from HA 0.0115.6 to 0.116.0.
During several days no data was inserted into the influxdb till I discovered the problem and corrected it by adding the optional precision option. It was optional for influxdb v1.x, but required for influxdb v2.
A bug correction was done in HA for the next version 0.117.0? to make it also optional for influxdb v2.

The problem is that for the moment there is too little information about how the peak values are calculated by the grid supplier.
Therefore I paused this until things get more clear.
As we know, things can change a lot in Belgium, especially when it’s about energy.

1 Like

True, but this cannot be calculated from measured kWh values. By definition, the kWh figure is gained by determining how much power (kW) was used in the measured time (h). A 1 second load of 10kW is the same kWh value as a 10 second load of 1kW. If you only get an energy reading every 10s, simply dividing the kWh figure by 10 will not give you the max power during that 10s.

For each reading period, the measuring device needs to return the Max power seen (kW) - you can take those figures and find the max for the quarter hour and then the average for the month. You cannot reverse engineer the figure from measured energy (kWh).

I’m not suggesting that this is derived from kWh. Indeed peak power is measured in kW.
That’s why my sensor is based on reactive power (VAR), not consumed energy (kWh).
The only thing that’s currently unclear is the timeframe of the so called ‘peak value’.
I hope this information will be provided soon…

What sensor do you have to measure the max figure over the recording cycle?

just a little clarification: Energie(Energy): kWh; Vermogen(Power): kW

What is being measured is called in Dutch “het kwartiervermogen”.
It can be loosely translated as “quarter-hour power”.

Here is how it is determined and how you can get it from your utility meter data:

First things first: It is NOT a moving average.

It is the average demand in a quarter-hour, with 4 values computed for every hour of the day, representing the time periods

  • From x:00:00h to x:14:59h,
  • From x:15:00h to x:29:59h,
  • From x:30:00h to x:44:59h, and
  • From x:45:00h to x:59:59h.

It represents the load you have on the electricity grid.

In order to determine the quarter-hour power value, you calculate the energy consumed in the quarter-hour by taking the total consumption at the end of the quarter minus the consumtion at the beginning of the quarter-hour.
Ex: At x:15:00h your utility meater read 4998,00 kWh and at x:29:59h it said 5000,00 kWh. 5000,00 kWh - 4998,00 kWh = 2,00 kWh consumed in 15 minutes.

Then you multiply this value by 4, because there are 4 quarters in a hour.
Ex: 2kWh consumed in 15 minutes represents 2 x 4 = 8 kW of power demand.
(Because this consumption in 15 minutes really is equivalent of 1/4th of the average power demand in that quarter-hour.)

Of all the quarter-hour values determined, only the maximum of each calender month is retained.
(Important: If the monthly peak value is less than 2,5kW still 2,5kW is used.)
And with these max monthly values, the yearly average (The simple arithmetic mean) is calculated, which has (will have) an impact on your invoice. Users with higher loads on the grid will pay more (in the future).
(If the year is not complete, it is the arithmetic mean of the incomplete dataset.)

2 Likes

any idea how to calculate this within homeassistant?
I’m logging all these values in a mysql db

I’m currently attempting a couple of different methods (including logging values to influxDB and graphing in there) but so far the most correct method seem to be to use the utility meter, with the quarter-hourly cycle.
As input I use the tarif 1 and tarif 2 consumption sensors coming from the DSMR integration.
My next steps will be to get the monthly max peak and all the peak from the last year/12 months, but with the new statistics charts that shouldn’t be too hard (that info is also kept indefinitely as opposed to the state changes)

EDIT: This is my graph from yesterday:
The yellow bars are values coming from the DSMR integration, every 1 second, grouped per 15minutes by the apex-charts card. The blue one is the tarif1 utility meter, the red one is the tarif2 utility meter (red one has no values just yet, only activated this morning)

As you can see, grouping and taking the average from the actual Power values from DSMR seems to align pretty much with the utility meter integration. I’m going to keep both of them active for a while and compare results in the coming days. if the result stay the same I’ll be removing the direct DSMR graphs and changing the interval back to 30seconds (default), the 1 second interval causes a lot of data to come into home assistant which really isn’t needed.

You might get slightly different results in HA versus Mijn Fluvius, because DSMR is not sending data in a time-synced fashion.

What I am doing, is sum both tarifs in NodeRed using an inject node, which is cron under the hood.


Function node:

const globalHomeAssistant = global.get('homeassistant');
var output;
var afname_1 = parseFloat(globalHomeAssistant.homeAssistant.states["sensor.energy_consumption_tarif_1"].state);
var afname_2 = parseFloat(globalHomeAssistant.homeAssistant.states["sensor.energy_consumption_tarif_2"].state);


output = (+afname_1) + (+afname_2);
output = output.toFixed(3);
return [{payload: output}];

Capacity tarif is only applicable to downstream energy.

I actually don’t really care about 100% accurate results, just a rough estimate is good enough for me.
The main reason I don’t need 100% accurate results is that my meter actually does not send any data to Fluvius, so I don’t get any info from MijnFluvius at all :wink:

Newsflash.

New HA 2021.9 Utility Meter will support cron-based resets. So you can easily let UM reset every 15min of the hour, multiply by 4 et voila.

As mentioned above the utility meter with quarter-hourly cycle is the correct option to measure the correct “kwartierpiek” or “capaciteitstarief”…
Don’t forget to multiply this by 4 to get the correct value which is needed.

I’m struggling to get these values for a month/year… I want the values with the MAX value of the current and past months. Anyone found a solution for that yet? I cannot find something useful in HA. min/max sensor doesn’t help…

I have a bar graph that shows this for the last 24h with max values. (and can see that 2.08 is the highest value last 24h.)
2021-09-22 13_16_43-Window

I use this utility_meter sensor

quarter_hourly_grid_consumption:
  source: sensor.grid_consumption_kwh
  cycle: quarter-hourly

Then I use this input_numbers to store the maximum peak and the monthly maximum peaks

  max_peak_2:
    name: Maximum piek 2
    min: 0.1
    max: 12.0
    step: 0.001
    mode: box
    unit_of_measurement: "kWh"
  
  january_peak_2:
    name: Piek januari 2
    min: 2.5
    max: 12.0
    step: 0.001
    mode: box
    unit_of_measurement: "kWh"
  
  february_peak_2:
    name: Piek februari 2
    min: 2.5
    max: 12.0
    step: 0.001
    mode: box
    unit_of_measurement: "kWh"
  
  march_peak_2:
    name: Piek maart 2
    min: 2.5
    max: 12.0
    step: 0.001
    mode: box
    unit_of_measurement: "kWh"

  april_peak_2:
    name: Piek april 2
    min: 2.5
    max: 12.0
    step: 0.001
    mode: box
    unit_of_measurement: "kWh"

  may_peak_2:
    name: Piek mei 2
    min: 2.5
    max: 12.0
    step: 0.001
    mode: box
    unit_of_measurement: "kWh"

  june_peak_2:
    name: Piek juni 2
    min: 2.5
    max: 12.0
    step: 0.001
    mode: box
    unit_of_measurement: "kWh"

  july_peak_2:
    name: Piek juli 2
    min: 2.5
    max: 12.0
    step: 0.001
    mode: box
    unit_of_measurement: "kWh"

  august_peak_2:
    name: Piek augustus 2
    min: 2.5
    max: 12.0
    step: 0.001
    mode: box
    unit_of_measurement: "kWh"

  september_peak_2:
    name: Piek september 2
    min: 2.5
    max: 12.0
    step: 0.001
    mode: box
    unit_of_measurement: "kWh"

  october_peak_2:
    name: Piek oktober 2
    min: 2.5
    max: 12.0
    step: 0.001
    mode: box
    unit_of_measurement: "kWh"

  november_peak_2:
    name: Piek november 2
    min: 2.5
    max: 12.0
    step: 0.001
    mode: box
    unit_of_measurement: "kWh"

  december_peak_2:
    name: Piek december 2
    min: 2.5
    max: 12.0
    step: 0.001
    mode: box
    unit_of_measurement: "kWh"

This template_sensors for the maximum peak and the year peak

    max_peak_2:
      friendly_name: Maximum piek 2 
      unit_of_measurement: "kWh"
      device_class: energy
      value_template: >
        {% set peak = ((states.sensor.quarter_hourly_grid_consumption.state | float(default=0)) * 4) %}
        {% set max_peak = (states.input_number.max_peak_2.state | float(default=0)) %}
        {% macro max(X, Y) -%} {{X|float if X|float > Y|float else Y|float }} {%- endmacro %}
        {{ max(max_peak, peak) }}

    year_peak:
      friendly_name: Gemiddelde jaarpiek
      unit_of_measurement: "W"
      device_class: power
      value_template: >
        {{ (( states('input_number.january_peak') | float(default=0) +
              states('input_number.february_peak') | float(default=0) +
              states('input_number.march_peak') | float(default=0) +
              states('input_number.april_peak') | float(default=0) +
              states('input_number.may_peak') | float(default=0) +
              states('input_number.june_peak') | float(default=0) +
              states('input_number.july_peak') | float(default=0) +
              states('input_number.august_peak') | float(default=0) +
              states('input_number.september_peak') | float(default=0) +
              states('input_number.october_peak') | float(default=0) +
              states('input_number.november_peak') | float(default=0) +
              states('input_number.december_peak') | float(default=0) ) / 12) | round(2)
        }}

And finale I have 2 automations

alias: Maximum piek 2
id: 546462125er
description: ''
mode: parallel
trigger:
  - platform: state
    entity_id: sensor.max_peak_2
condition:
  - condition: template
    value_template: >
      {{  states("sensor.max_peak_2") | float(default=0)> states("input_number.max_peak_2") | float(default=0)}}
action:
  - service: input_number.set_value
    target:
      entity_id: input_number.max_peak_2
    data:
        value: >
          {{ states("sensor.max_peak_2") | float(default=0)}}
alias: Maximum maandpiek
id: fevefvdvfzsvf
description: ''
mode: single
trigger:
  - platform: template
    value_template: '{{ (as_timestamp(now()))|timestamp_custom(''%d'', true) | int == 1 }}'
condition: []
action:
  - choose:
      - conditions:
          - condition: template
            value_template: '{{ (as_timestamp(now()))|timestamp_custom(''%m'', true)|int == 2 }}'
        sequence:
          - condition: template
            value_template: >
              {{  states("sensor.max_peak_2") | float(default=0)> states("input_number.january_peak_2") | float(default=0)}}
          - service: input_number.set_value
            target:
              entity_id: input_number.january_peak_2
            data:
              value: >
                {{ states("sensor.max_peak_2") }}
          - delay:
              seconds: 5
          - service: input_number.set_value
            target:
              entity_id: input_number.max_peak_2
            data:
              value: 0.1
          - delay:
              minutes: 1
          - service: input_number.set_value
            target:
              entity_id: input_number.february_peak_2
            data:
              value: 2.5
      - conditions:
          - condition: template
            value_template: '{{ (as_timestamp(now()))|timestamp_custom(''%m'', true)|int == 3 }}'
        sequence:
          - condition: template
            value_template: >
              {{  states("sensor.max_peak_2") | float(default=0)> states("input_number.february_peak_2") | float(default=0)}}
          - service: input_number.set_value
            target:
              entity_id: input_number.february_peak_2
            data:
              value: >
                {{ states("sensor.max_peak_2") }}
          - delay:
              seconds: 5
          - service: input_number.set_value
            target:
              entity_id: input_number.max_peak_2
            data:
              value: 0.1
          - delay:
              minutes: 1
          - service: input_number.set_value
            target:
              entity_id: input_number.march_peak_2
            data:
              value: 2.5
      - conditions:
          - condition: template
            value_template: '{{ (as_timestamp(now()))|timestamp_custom(''%m'', true)|int == 4 }}'
        sequence:
          - condition: template
            value_template: >
              {{  states("sensor.max_peak_2") | float(default=0)> states("input_number.march_peak_2") | float(default=0)}}
          - service: input_number.set_value
            target:
              entity_id: input_number.march_peak_2
            data:
              value: >
                {{ states("sensor.max_peak_2") }}
          - delay:
              seconds: 5
          - service: input_number.set_value
            target:
              entity_id: input_number.max_peak_2
            data:
              value: 0.1
          - delay:
              minutes: 1
          - service: input_number.set_value
            target:
              entity_id: input_number.april_peak_2
            data:
              value: 2.5
      - conditions:
          - condition: template
            value_template: '{{ (as_timestamp(now()))|timestamp_custom(''%m'', true)|int == 5 }}'
        sequence:
          - condition: template
            value_template: >
              {{  states("sensor.max_peak_2") | float(default=0)> states("input_number.april_peak_2") | float(default=0)}}
          - service: input_number.set_value
            target:
              entity_id: input_number.april_peak_2
            data:
              value: >
                {{ states("sensor.max_peak_2") }}
          - delay:
              seconds: 5
          - service: input_number.set_value
            target:
              entity_id: input_number.max_peak_2
            data:
              value: 0.1
          - delay:
              minutes: 1
          - service: input_number.set_value
            target:
              entity_id: input_number.may_peak_2
            data:
              value: 2.5
      - conditions:
          - condition: template
            value_template: '{{ (as_timestamp(now()))|timestamp_custom(''%m'', true)|int == 6 }}'
        sequence:
          - condition: template
            value_template: >
              {{  states("sensor.max_peak_2") | float(default=0)> states("input_number.may_peak_2") | float(default=0)}}
          - service: input_number.set_value
            target:
              entity_id: input_number.may_peak_2
            data:
              value: >
                {{ states("sensor.max_peak_2") }}
          - delay:
              seconds: 5
          - service: input_number.set_value
            target:
              entity_id: input_number.max_peak_2
            data:
              value: 0.1
          - delay:
              minutes: 1
          - service: input_number.set_value
            target:
              entity_id: input_number.june_peak_2
            data:
              value: 2.5
      - conditions:
          - condition: template
            value_template: '{{ (as_timestamp(now()))|timestamp_custom(''%m'', true)|int == 7 }}'
        sequence:
          - condition: template
            value_template: >
              {{  states("sensor.max_peak_2") | float(default=0)> states("input_number.june_peak_2") | float(default=0)}}
          - service: input_number.set_value
            target:
              entity_id: input_number.june_peak_2
            data:
              value: >
                {{ states("sensor.max_peak_2") }}
          - delay:
              seconds: 5
          - service: input_number.set_value
            target:
              entity_id: input_number.max_peak_2
            data:
              value: 0.1
          - delay:
              minutes: 1
          - service: input_number.set_value
            target:
              entity_id: input_number.july_peak_2
            data:
              value: 2.5
      - conditions:
          - condition: template
            value_template: '{{ (as_timestamp(now()))|timestamp_custom(''%m'', true)|int == 8 }}'
        sequence:
          - condition: template
            value_template: >
              {{  states("sensor.max_peak_2") | float(default=0)> states("input_number.july_peak_2") | float(default=0)}}
          - service: input_number.set_value
            target:
              entity_id: input_number.july_peak_2
            data:
              value: >
                {{ states("sensor.max_peak_2") }}
          - delay:
              seconds: 5
          - service: input_number.set_value
            target:
              entity_id: input_number.max_peak_2
            data:
              value: 0.1
          - delay:
              minutes: 1
          - service: input_number.set_value
            target:
              entity_id: input_number.august_peak_2
            data:
              value: 2.5
      - conditions:
          - condition: template
            value_template: '{{ (as_timestamp(now()))|timestamp_custom(''%m'', true)|int == 9 }}'
        sequence:
          - condition: template
            value_template: >
              {{  states("sensor.max_peak_2") | float(default=0)> states("input_number.august_peak_2") | float(default=0)}}
          - service: input_number.set_value
            target:
              entity_id: input_number.august_peak_2
            data:
              value: >
                {{ states("sensor.max_peak_2") }}
          - delay:
              seconds: 5
          - service: input_number.set_value
            target:
              entity_id: input_number.max_peak_2
            data:
              value: 0.1
          - delay:
              minutes: 1
          - service: input_number.set_value
            target:
              entity_id: input_number.september_peak_2
            data:
              value: 2.5
      - conditions:
          - condition: template
            value_template: '{{ (as_timestamp(now()))|timestamp_custom(''%m'', true)|int == 10 }}'
        sequence:
          - condition: template
            value_template: >
              {{  states("sensor.max_peak_2") | float(default=0)> states("input_number.september_peak_2") | float(default=0)}}
          - service: input_number.set_value
            target:
              entity_id: input_number.september_peak_2
            data:
              value: >
                {{ states("sensor.max_peak_2") }}
          - delay:
              seconds: 5
          - service: input_number.set_value
            target:
              entity_id: input_number.max_peak_2
            data:
              value: 0.1
          - delay:
              minutes: 1
          - service: input_number.set_value
            target:
              entity_id: input_number.october_peak_2
            data:
              value: 2.5
      - conditions:
          - condition: template
            value_template: '{{ (as_timestamp(now()))|timestamp_custom(''%m'', true)|int == 11 }}'
        sequence:
          - condition: template
            value_template: >
              {{  states("sensor.max_peak_2") | float(default=0)> states("input_number.october_peak_2") | float(default=0)}}
          - service: input_number.set_value
            target:
              entity_id: input_number.october_peak_2
            data:
              value: >
                {{ states("sensor.max_peak_2") }}
          - delay:
              seconds: 5
          - service: input_number.set_value
            target:
              entity_id: input_number.max_peak_2
            data:
              value: 0.1
          - delay:
              minutes: 1
          - service: input_number.set_value
            target:
              entity_id: input_number.november_peak_2
            data:
              value: 2.5
      - conditions:
          - condition: template
            value_template: '{{ (as_timestamp(now()))|timestamp_custom(''%m'', true)|int == 12 }}'
        sequence:
          - condition: template
            value_template: >
              {{  states("sensor.max_peak_2") | float(default=0)> states("input_number.november_peak_2") | float(default=0)}}
          - service: input_number.set_value
            target:
              entity_id: input_number.november_peak_2
            data:
              value: >
                {{ states("sensor.max_peak_2") }}
          - delay:
              seconds: 5
          - service: input_number.set_value
            target:
              entity_id: input_number.max_peak_2
            data:
              value: 0.1
          - delay:
              minutes: 1
          - service: input_number.set_value
            target:
              entity_id: input_number.december_peak_2
            data:
              value: 2.5
    default:
      - condition: template
        value_template: >
          {{  states("sensor.max_peak_2") | float(default=0)> states("input_number.december_peak_2") | float(default=0)}}
      - service: input_number.set_value
        target:
          entity_id: input_number.december_peak_2
        data:
          value: >
            {{ states("sensor.max_peak_2") }}
      - delay:
          seconds: 5
      - service: input_number.set_value
        target:
          entity_id: input_number.max_peak_2
        data:
          value: 0.1
      - delay:
          minutes: 1
      - service: input_number.set_value
        target:
          entity_id: input_number.january_peak_2
        data:
          value: 2.5
4 Likes

Hi Giel,

Thank you for sharing your code!
This is a very useful implementation to have this information available in Home Assistant.

I just would like to remark 2 things to be aware of:

The input_numbers and template_sensors technically should be of the device_class “power”, not “energy” and their values are in “kW”, not “kWh”.

You can find more information in this video of VREG (Dutch): Capaciteitstarief: van kwartiervermogen tot gemiddelde maandpiek - YouTube

If there is a monthpeak of less than 2.5kW, then indeed 2.5kW will be used to calculate the average monthpeak.
However, if the year is incomplete (not all monthpeaks known) and therefore there are missing values for calculating the “average monthpeak”, the average is calculated with the known values only.
The missing values are simply omitted and you should not use a default minimum monthpeak of 2.5kW in that case.
So the first year of introducing the capacity tarif, your calculation will be off somewhat.

2 Likes