Spike in energy cost calculation when hour change (utility meter)

Hi,

Hi I have some sensors and integrations used to calculate energy bill of a water-heater. Recently I found a spike on the energy cost calculation when changin the hour. You can see it in next image:

This spike its making my daily and monthly cost calculation going wrong. I don’t know what happened to occur, because it’s the first time it happens, but maybe its because energy price changed some milliseconds early than energy meter resets. I would like it to avoid to happen again. Could you help me??

This are my integrations:

  • Tasmota energy plug that reports me energy consuption (kWh)
  • Integration that reports energy price each hour (pvpc_hourly_pricing).
  • Utility meter for energy (kWh) that resets hourly
  • Utility meter for energy (kWh) that resets monthly
  • Utility meter for cost (€) that resets monthly
  • Energy bill per hour (template sensor that multiply utitily_meter_energy_hourly * energy_price)
sensor:
  - platform: template
    sensors:
      energy_bill_hourly:
        friendly_name: Gasto Energía Hora
        value_template: '{{ states("sensor.energy_hourly") | float * states("sensor.pvpc") | float }}'
        unit_of_measurement: '€'
        icon_template: hass:currency-eur

# electricity tariff
pvpc_hourly_pricing:
  - name: PVPC
    tariff: normal

# electricity bill
utility_meter:
  energy_monthly:
    source: sensor.termo_energy_today
    cycle: monthly
    offset:
      days: 14
  energy_hourly:
    source: sensor.termo_energy_today
    cycle: hourly
  energy_bill_daily:
    source: sensor.energy_bill_hourly
    cycle: daily
  energy_bill_monthly:
    source: sensor.energy_bill_hourly
    cycle: monthly
    offset:
      days: 14

I fixed it. I don’t know if is the best option but it works.
Just added a delay of 59 minutes and 59 seconds to my hourly metter, so in this way it will reset just 1 second before hourly price change.