Integration (Riemann sum) - value only updating when source sensor updates 2

Before posting here, I read the following topic. But I think that the posted solution doesn’t work for me.

My goal is to record the energy our car consumes while charging at home. This would preferably be done using OCPP. However, this is not feasible, as it is already in use by the service provider of my employer who reimburses the energy costs for the car.

That’s why I created a template sensor that reads the current power provided by the Skoda Connect app when the car is at home. And an automation, that updates this sensor. Finally, I created a sensor based on the left Riemann sum integration to calculate the Energy consumed.

My problem is, that both the current power value and the location value do not change during charging. The car is not moving and the power stays always at 3500W. As a result, the Rieman integration is only calculated when the charging stops or HA is restarted. Charging this car full at a rate of 3.5kW takes more than 24 hours. As a result, my energy statistics are not reported correctly. I attempted to update the current power by using minutes: ‘/5’. However, this appears not to result in a new data entry in the database. As a result the value for energy is not updated regularly.

Please have a look at my configuration files. Maybe you can spot my mistake.

templates.yaml

  - name: "Enyaq current power at home"
    state_class: "measurement"
    unit_of_measurement: "W"
    device_class: "power" 
    state: >
      {% if is_state('device_tracker.***_position', 'home') %}
        {{ states('sensor.***_charging_power') | float }}
      {% else %}
        0
      {% endif %}

automations.yaml

- alias: "Update Enyaq Charging Power at Home"
  trigger:
    - platform: state
      entity_id: device_tracker.***_position
    - platform: state
      entity_id: sensor.***_charging_power
    - platform: time_pattern
      minutes: '/5'  # Triggers the automation every 5 minutes
  action:
    - service: homeassistant.update_entity
      target:
        entity_id: sensor.enyaq_current_power_at_home

sensors.yaml

- platform: "integration"
  source: "sensor.enyaq_current_power_at_home"
  name: "Enyaq Energy at home"
  method: "left"
  unit_prefix: "k"
  round: 2

Hi,

You can add a max_sub_interval setting (quite new feature) to your Riemann sum sensor to make it do regular updates, like this:

- platform: "integration"
  source: "sensor.enyaq_current_power_at_home"
  name: "Enyaq Energy at home"
  method: "left"
  unit_prefix: "k"
  round: 2
  max_sub_inteval:
    minutes: 1