Template + Utility meter not working properly?

Hi

I’ve got a energy usage sensor in W that is transformed into kWh using integration as follows:


- platform: integration
  source: sensor.grid_consumed_power
  name: grid_consumed_power_integration
  unit_time: h
  unit_prefix: k
  method: left
  round: 2

On the other hand, the result is used in a template so to have its hourly cost (pvpc is an official integration with hourly energy prices):

- platform: template
  sensors:
      coste_energia_porhour:
        friendly_name: "Gasto en energía por hora"
        unit_of_measurement: '€'
        value_template: "{%if states.sensor.pvpc.state %}{{ ((states.sensor.grid_consumed_power_integration.state | float) * (states.sensor.pvpc.state | float)) | round(5) }}{% else %}unknown{% endif %}"
        entity_id:
          - sensor.grid_consumed_power_integration
          - sensor.pvpc

Template seems to work fine but on some rate changes (in the one at 13h in the picture), template shows a jump that does not make sense:

Is there something I’m missing in the template definition ?

Thanks

I think it seems to be working fine …

Before 13:00 the cost is approximately 22.5 kWh x 0.07 E/kWh = E1.58

After 13:00 the cost is approximately 22.5 kWh x 0.14 E/kWh = E3.15

The jump in price appears to be caused by the PVPC sensor jumping which sounds like it comes from an external source. At least that’s the way I see it.

Thanks @Jonah1970 ,

Price at 13:00 is for energy consumed from 13:00 til 14:00, not for the already consumed. Consumption at that hour is < 1kWh!