Calculate energy cost for a single device with changing tariffs

I would like to display a calculated energy cost (in €) for a specific device that’s connected to a Shelly EM and that is never reset (TCO = total cost of ownership).

I was able to create an utility sensor with 3 tariffs (see sensor.consumption_device_f1 below) that are switching correctly and this is my template sensor to calculate the energy cost.

template:
  - sensor:
      - unique_id: device_total_energy_cost
        name: 'Total device energy cost'
        icon: mdi:currency-eur
        unit_of_measurement: '€'
        state: >
          {{ (states('input_number.enegy_price_f1')|float(0) *
             states('sensor.consumption_device_f1')|float(0) +
             states('input_number.enegy_price_f23')|float(0) *
             (states('sensor.consumption_device_f2')|float(0) +
              states('sensor.consumption_device_f3')|float(0)))
             |float(0)|round(2) }}

It works well, but there’s a catch… what if the tariffs change? I mean if I edit the value of input_number.enegy_price_f1 (measured in €/kWh) the whole total would change immediately, while I want that only from the moment I change the input_numbers the total has to be updated “progressively”.

What do you suggest to do that?

did you get the solution to this?

Of course not! But I’m still open to suggestions :grinning: even though they don’t arrive, unfortunately. I’m just surprised that we’re the only two guys that need that!

You’re not alone, here’s a few same or similar threads:

1 Like