Utility_meter cyles

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
  1. I’m going to change that.
  2. I think you can use a default value

All the specifics can be found in the technical regulations which you can find at https://www.vreg.be/sites/default/files/document/trde_2021.pdf

48°/1 Gemiddelde maandpiek afname: het rollend gemiddelde van de 12 laatste maandpieken
afname met inachtneming van de minimumwaarde van de maandpiek, zoals gedefinieerd in de
tariefmethodologie, vastgelegd door de VREG. Indien de maandpiek nog niet voor 12 maanden
beschikbaar is, is de gemiddelde maandpiek het gemiddelde sinds de eerste relevante maandpiek

48°/1 Gemiddelde maandpiek afname: het rollend gemiddelde van de 12 laatste maandpieken
afname met inachtneming van de minimumwaarde van de maandpiek, zoals gedefinieerd in de
tariefmethodologie, vastgelegd door de VREG. Indien de maandpiek nog niet voor 12 maanden
beschikbaar is, is de gemiddelde maandpiek het gemiddelde sinds de eerste relevante maandpiek

To avoid misunderstandings, let me summarise:
When you start taking measurements, for the first month the monthly peak and the average monthly peak are identical.

1st monthly peak: a kW ==> average monthly peak: a kW
2nd monthly peak: b kW ==> average monthly peak: (a+b)/2 kW
3rd monthly peak: c kW ==> average monthly peak: (a+b+c)/3 kW

12th monthly peak: l kW ==> average monthly peak: (a+b+c+d+e+f+g+h+i+j+k+l)/12 kW

13th monthly peak: m kW ==> average monthly peak: (b+c+d+e+f+g+h+i+j+k+l+m)/12 kW
14th monthly peak: n kW ==> average monthly peak: (c+d+e+f+g+h+i+j+k+l+m+n)/12 kW

==> “het rollend gemiddelde van de 12 laatste maanden” or “the rolling average of the last 12 months”

Correct?

Yes, your summary is correct. (Only the case <2.5kW is missing.)

More formaly: (With the correct terminology.)
The average monthpeak is the rolling average of the available monthpeaks, with a window size of 12. This window size is reduced to the amount of available monthpeaks if there are less than 12 monthpeaks available.

Pay attention to:
If an available monthpeak is less than 2.5kW, you must use a value of 2.5kW to represent that monthpeak in the calculations of the average monthpeak.
(Technically the monthpeak itself remains on its original value of less than 2.5kW.This might become relevant if the minimum value of 2.5kW in use today is changed (lowered) in the future. Today’s value was actualy determined by other net usage information and it can be reviewed and changed in the future if required.)

Also:
It doesn’t matter when “you” start taking measurements, but when the network operator starts. :slight_smile:

Today, monthpeaks are only relevant for consumption, not injection. However, if deemed necessary, this could change in the future so injection might then also be subject to a similar calculation (which might employ different numerical values).

It is unclear (not defined) what happens when you move to a different location within the geographical area where this capacitytarif is applicable, or when the legal owner of the electricitycontract is changed without moving. (Will the previous monthpeaks of the legal contractowner be used? Will the previous monthpeaks of the meter be used? Will you start again with no available monthpeaks?)

2 Likes

Hi @gieljnssns,

I’m trying to understand following in the automation ‘Maximum maandpiek’

If the first condition fails and failing means that the monthly peak is < 2.5 kW (2.5 kW is the minimum value of the input_number january in this example)

          - condition: template
            value_template: >
              {{  states("sensor.max_peak_2") | float(default=0)> states("input_number.january_peak_2") | float(default=0)}}

all the next steps are not done?
If so, the input_number.max_peak_2 is never reset and remains with his value.
February will then start with the value of the previous month in input_number.max_peak_2??

Am I missing some point?

Yes, you are right. :face_with_hand_over_mouth::face_with_hand_over_mouth:
I have to rethink this part…

I did some changes

        sequence:
          - service: input_number.set_value
            target:
              entity_id: input_number.january_peak_2
            data:
              value: >
                {% if states("sensor.max_peak_2") | float(default=0)> states("input_number.january_peak_2") | float(default=0) %}
                  {{ states("sensor.max_peak_2") }}
                {% else %}
                  2.5
                {% endif %}
          - 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
1 Like

I implemented your solution in HA next to mine (see above Utility_meter cyles - #12 by evb).
So I can compare the results :slight_smile:

The next step will be the implementation of the rolling average month peak “gemiddelde maandpiek afname” (Utility_meter cyles - #29 by JohanBraeken) :thinking:

I’m trying to set up something similar. The difference for me is that my monthly rate is calculated from the 5 highest hourly energy use figures each month. Any good ideas how I might achieve that? I’ve successfully set up @gieljnssns’s configuration so far, yet that obviously onnly gets me the single highest figure for the month.

What for hardware to measure do you have?

Could somebody help me in the right direction? I’m trying to use the utility_meter with cycle string: quarter-hourly but I’m not getting the right result. I’m fairly new at this so cut me some slack :wink:

cycle string (Optional)
How often to reset the counter. Valid values are quarter-hourly, hourly, daily, weekly, monthly, bimonthly, quarterly and yearly. Cycle value bimonthly will reset the counter once in two months.

This is my yaml-code

recorder:
sensor:
  - platform: statistics
    entity_id: sensor.energy

utility_meter:
  energy:
    source: sensor.p1_meter_active_power
    cycle: quarter-hourly
  daily_energy_offpeak:
    source: sensor.p1_meter_total_power_import_t2
    name: Daily Energy (Offpeak)
    cycle: daily
  daily_energy_peak:
    source: sensor.p1_meter_total_power_import_t1
    name: Daily Energy (Peak)
    cycle: daily
  monthly_energy_offpeak:
    source: sensor.p1_meter_total_power_import_t2
    name: Monthly Energy (Offpeak)
    cycle: monthly
  monthly_energy_peak:
    source: sensor.p1_meter_total_power_import_t1
    name: Monthly Energy (Peak)
    cycle: monthly

I’ve added the following to allow me to be able to measure the “kwartuurpiek”.

However, the sensor seems to add up consumed power instead of just measuring. Thereafter I changed the kind of measurement in ‘entity customization’ into ‘measurement’ instead of ‘total increasing’ because the entity doesn’t have a unique ID (because it was added in YAML.). But this doesn’t change its behaviour.

This entity (‘sensor.energy’) does not have a unique ID, therefore its settings cannot be managed from the UI. See the documentation for more detail.
You can overwrite some attributes in the [entity customisations] section.

Because I needed the ‘mean’ value I added statistics sensor. Normally this should already give the mean value

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, quantiles, standard_deviation, variance, total, min_value, max_value, min_age, max_age, change, average_change and change_rate. If the source is a binary sensor then only state changes are counted.

Am I approaching this all wrong? What do I need to change in order for this to work? Also am I missing something? Do I need to multiply the value?

In Grafana it looks just fine, but I’m not able to pinpoint the issue occurring on the sensor from the utility meter :frowning:

This is a screenshot from the utility meter. The values seem to just always rise. I can’t seem to figure this one out on my own.

@Giovanni85, I’m trying to understand your post, but have difficulty to follow you.

I imagine that this sensor, in his raw value, is giving you the actual power consumption (W or kW) of your installation? This value is the real-time power consumption from the grid, correct?
Be careful if you have solar panels! You must only have the grid consumption!

This value must be converted to kWh (kilo-watt-hour), the number of kW per hour.
For this you can use the Riemann sum integration from HA.

- platform: integration
  source: sensor.p1_meter_active_power
  name: smappeemqtt_grid_afname_kwh
  unit_prefix: k
  round: 3

Now you can use the utility_meter integration

### creat quarterhour utility_meter from the riemann sum sensor.smappeemqtt_grid_afname_kwh
smappeemqtt_quarterhour_gridenergy:
  source: sensor.smappeemqtt_grid_afname_kwh
  cycle: quarter-hourly

Now you can follow 2 ways for the calculation of the average peak power per quarter.

  1. via a template sensor
- platform: template
  sensors:
    ### create from the utility_meter sensor the average peakpower per quarterhour  ###
    smappeemqtt_quarterhour_grid_averagepeakpower:
      value_template: "{{ states('sensor.smappeemqtt_quarterhour_gridenergy')|float * 4 }}"
      unit_of_measurement: "kW"
      icon_template: mdi:calculator
      friendly_name: "Gemiddeld piekvermogen per kwartier"

or

  1. Utility_meter cyles - #26 by gieljnssns : see above
    You take the sensor smappeemqtt_quarterhour_gridenergy as starting point to implement the Helpers and input_numbers.
    Be sure to implement the correction applied by @gieljnssns : Utility_meter cyles - #32 by evb

I’m using these 2 implementations in parallel, to be able to verify the values…

This is indeed the real-time power consumption:

sensor.p1_meter_active_power
state_class: measurement
unit_of_measurement: W
friendly_name: P1 meter Active Power
device_class: power

Should I not use this one? I’ve used this one in Grafana without any problem? The device is connected to the P1 port from the grid operator’s DSMR 5.0 digital meter

I have solar panels and to answer your question: sensor.p1_meter_active_power gives the grid consumption (positive number) and grid injection (negative number). This in fact works very well in Grafana.

Thank you for your help, I’ll take a look at it tomorrow when I’m back clearheaded, which isn’t the case at the moment :wink:

Hi @Giovanni85,

Yes, you should use the sensor p1_meter_active_power as starting point.

If this sensor can be positive (grid consumption) and negative (solar production), then you must convert it to get only the positive part and 0 if it is negative.
This new sensor is then the starting point for the Riemann sum integration.

I have two sensors, giving me the production of solar power and the current consumption of the house. Via a template sensor, I get a new sensor.smappeemqtt_grid_consumption.
This sensor is then used in the Riemann sum integration.

    smappeemqtt_grid_consumption:
      friendly_name: Grid afname
      unit_of_measurement: "W"
      value_template: >-
        {%- if states("sensor.smappeemqtt_huidige_opbrengst") | float < states("sensor.smappeemqtt_huidig_verbruik") | float %}
          {{ states("sensor.smappeemqtt_huidig_verbruik") | float - states("sensor.smappeemqtt_huidige_opbrengst") | float }}
        {%- elif states("sensor.smappeemqtt_huidige_opbrengst") | float > states("sensor.smappeemqtt_huidig_verbruik") | float %}
          {{ 0 | float }}
        {% endif %}

Hi, I started this similar thread on Reddit before I spotted this discussion. Would my approach be a good one too?

My approach is teh following using a 3.15 kWh limit as said here Het capaciteitstarief: wat er verandert | Energie-Vergelijker.be using the below in my configuration file:

template2

and followed by this automation



And this dashboard

3.15kWh? See article

Indeed. That’s per 15 minutes, so if you fire up your car charger or electrical furnace …

Dear can you please provide the full/complete config yaml for the first option/ way to calculate the piek consumption. Whatever I adjusted in the coding it keeps giving errors or HA refuses to restart ….

Tx, Wim