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.
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.)
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
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.
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.
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?)
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.
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
I implemented your solution in HA next to mine (see above Utility_meter cyles - #12 by evb).
So I can compare the results
The next step will be the implementation of the rolling average month peak “gemiddelde maandpiek afname” (Utility_meter cyles - #29 by JohanBraeken)
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
cycle string (Optional)
How often to reset the counter. Valid values arequarter-hourly
,hourly
,daily
,weekly
,monthly
,bimonthly
,quarterly
andyearly
. Cycle valuebimonthly
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 themean
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
andchange_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
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.
- 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
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
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:
and followed by this automation
And this dashboard