Question: Riemann Sum Integral refresh

I’m using the Integration - Riemann sum integral to calculate the gas consumption of the boiler.

As the boiler provides its current power in percent, I first calculate the power in Watts from this (DHW mode has 29 kW, heating 24 kW for 100%):

  - platform: template
    sensors:
      boiler_power_in_watts:
        friendly_name: "Kazán teljesítmény Wattban"
        value_template: >
          {% if is_state('binary_sensor.boiler_ww_charging', 'on') %}
            {{ ((states('sensor.boiler_burner_current_power')|float(0)) * 29000 / 100) | round(0) }}
          {% else %}
            {{ ((states('sensor.boiler_burner_current_power')|float(0)) * 24000 / 100) | round(0) }}
          {% endif %}

then I convert this to Wh with this integral:

  - platform: integration
    source: sensor.boiler_power_in_watts
    name: boiler_energy2
    round: 0
    method: left

and finally convert this to m³, which can be used in the Energy panel:

template:
  sensor:
    - name: "Kazán saccolt összfogyasztása"
      unit_of_measurement: "m³"
      state: >
        {{ ((states('sensor.boiler_energy2')|float(0)) / 9444) | round(3) }}
      state_class: total_increasing
      device_class: gas

This more or less works fine with a small problem: these values gets recalculated only when the power of the boiler has changed… which often remains constant for long, sometimes for hours.

Of course the daily consumption is OK, but the Energy panel has hourly resolution, which in this case results an hour with zero gas use, and then the next hour with double value, like here at 06-07 hours:
gaz

because the boiler power was at constant 14% for that period:

Is there a way to force the recalculation of the integral sensor somehow?

From https://community.home-assistant.io/t/add-force-update-support-to-template-sensor, I think you can “force” a boiler update with

  - platform: template
    sensors:
      boiler_power_in_watts:
        friendly_name: "Kazán teljesítmény Wattban"
        value_template: >
          {% if is_state('binary_sensor.boiler_ww_charging', 'on') %}
            {{ ((states('sensor.boiler_burner_current_power')|float(0)) * 29000 / 100) | round(0) }}
          {% else %}
            {{ ((states('sensor.boiler_burner_current_power')|float(0)) * 24000 / 100) | round(0) }}
          {% endif %}
        attribute_templates:
          hour_last_updated:  "{{ now().hour }}"          

Every hour, the attribute value will change, so a new state will be recorded, that should trigger the whole chain.

1 Like

Thanks!
From that topic, I finally used {{ (now().minute / 5) | round(0, 'floor') }} to have a 5 minutes resolution and to make sure a fairly fresh data is displayed in the Energy panel for the last hour (don’t know if template evaluation by the changed attribute preceeds the Energy panel re-display, but this way it won’t matter)