Utility_meter cyles

@gieljnssns First of all, thank you for sharing you configuration. I’m studying it while trying to create a meter for the capaciteitstarief of the current month and of the current quarter.

I do not fully understand however why you already decide on the max value of the sensor.quarter_hourly_grid_consumption * 4 vs input_number.max_peak_2 rather than just return sensor.quarter_hourly_grid_consumption * 4 (see My-Hassio-config/energy.yaml at 56b473f09d59977c6f43c423e552cf6195614ef4 · gieljnssns/My-Hassio-config · GitHub) since you also check for the largest value in the following automation: My-Hassio-config/max_peak_2.yaml at 56b473f09d59977c6f43c423e552cf6195614ef4 · gieljnssns/My-Hassio-config · GitHub . Doesn’t that check for the max value twice?

(I’m pretty new to HA so forgive me if I’m just missing stuff…)

So far I created:

  • a sensor to sum up my daytime and nighttime grid usage (the HomeWizard P1 meter tracks this separately)
  • a utility_meter to track quarterly kWh based on the above sensor
  • an input_number to store the max value of the current month (peak_current_month)

Then I would guess it would be enough to just:

  • create a sensor (peak_current_quarter) to return the peak kW (=the utility_meter * 4) (without comparing to the current max value at that point?)
  • and create an automation to set peak_current_month to peak_current_quarter if that is larger

And then I can show peak_current_month and peak_current_quarter on the dashboard.

For HomeWizard Energy users: you can get the ‘official’ peak directly from the P1 meter, for now you can follow this issue and try to recreate it in configuration.yaml. But I am working hard to get this added to the HomeWizard Energy integration natively. → Capacity tariff Flanders (Belgium) - Extra data-objects, telegram change · Issue #150 · DCSBL/python-homewizard-energy · GitHub

1 Like

Oh that is awesome! I used the code from Capacity tariff Flanders (Belgium) - Extra data-objects, telegram change · Issue #150 · DCSBL/python-homewizard-energy · GitHub and that seems to work perfectly. Thanks a lot!

You could have right, I never saw that.

Sharing my implementation here:

  • A utility meter, called kwartierverbruik, tracking the energy consumed over the 15 min interval.
  • A template sensor, that tracks the maximum peak up to that moment of the current month, it resets every month (by using an attribute):
template:
  - sensor:
    - name: "Kwartierpiek"
      unique_id: "kwartierpiek"
      state: >
        {% set max_value = states.sensor.kwartierpiek.state|float(0) %}
        {% set current_month = now().strftime('%m') %}
        {% set last_reset_month = states.sensor.kwartierpiek.attributes.last_reset_month %}
        {% if last_reset_month is defined and current_month != last_reset_month %}
          {{ float(states.sensor.kwartierverbruik.state) * 4 }}
        {% elif max_value is defined and max_value < 4 * float(states.sensor.kwartierverbruik.state) %}
          {{ float(states.sensor.kwartierverbruik.state) * 4 }}
        {% else %}
          {{ max_value }}
        {% endif %}
      attributes:
        last_reset_month: >
          {{ now().strftime('%m') }}
      unit_of_measurement: "kW"
      state_class: measurement
      device_class: power
1 Like

@janmolemans Would you mind sharing your utility meter code as well? Thanks!

the utility meter is not in code, but via the GUI: Settings → devices and services → helpers → utility meter.
This tracks the energy consumed over the 15 min interval and resets every 15 minutes.

1 Like

hi @gieljnssns i implemented your code and everything calculates, but i have a p 1 meter thats says P1 meter Peak demand current month 5830W (5,83kW) but your readings are defferent (4,72) i must say i started your example a few days ago , the meter itselfs with the homewizard p1 integration is already counting from 26th februari, could that be the cause that those two numbers are not the same (because of a peak earlier then starting your implementation)?

i dont understand your macro part=

{% macro max(X, Y) -%} {{X|float if X|float > Y|float else Y|float }} {%- endmacro%}
{{ max(max_peak, peak) }}

are you willingly to explain it to me?
my ‘investigation(’ board added as image (and manualy put 5,83 in march peak :wink: )

The macro part is to define the max() function
max_peak = X
peak = Y
So the max() function returns max_peak|float if max_peak|float > peak|float else peak|float.
That function returns always the biggest from the 2 values.

I hope you get it now.

now i get it!
any idea why my readings are off? (4,72 vs 5,8à ?

Can you check when there was that peak(5,8)?

by my meter p1 no :s it must happen before the integration with ha (a few days later because the port wastn activated yet-