Create sensor to show electricity cost per sensor

I’m using Shelly Plug S to monitor my energy use on single devices and that gives me a lot of attributes to work with


I also have the Tibber integration that gives me the current spot electricity price:
image

I want to create a new sensor that shows the cost for the individual plugs per now/day/week/month but not sure how to do it since the plug only reports W and kWh.
I know there are feature suggestions being voted on to show the price in the energy dashboard but until that gets added I want another way of showing the family how much is being spent.

I’m using templates for that

  blablabla:
        friendly_name: "Miesieczny koszt sypialnia"
        unit_of_measurement: 'zł'
        value_template: "{{ (states('sensor.monthly_energy') | float * 0.80) | round(2) }}"

But you are just multiplying it with a fixed cost of 0.80 right. My Electricity price varies each hour so I can’t really do the same.
I tried taking my sensor * price sensor but since the price is in kWh and the other sensor is W I don’t think it works.

Would it maybe work doing something like this:

{{(states.sensor.electricity_price_billa_katrinelund_1.state | float | round(5)) * ((states.sensor.shelly_shplg_s_6f384f_current_consumption.state | float | round(5))/1000)}}

Where I take the electricity price and multiply it with the current consumption divided by 1000 to get it to kW instead of W. Then a rieman sum helper to save it?

Formally, you should multiply the power (W) by the price and intrgrate it (i.e. Riemann) with a time of hours. But not all the devices report the power very accurately (it fluctuates a lot usually but the updates to HA are only sent with some cadence). The energy consumption from the device is usually much more accurate.

So you could create a statistics sensor that calculates the change in the energy sensor over the last hour and then create a trigger-based template-sensor to multiply the change in energy by the current price once per hour and add it to its previous value. This will then by a cumulative cost and from it you can do a utility_meter with whatever cadence you need.

Hi, everyone.

I have tried to create a sensor which calculates the cost of, for example, one wash cycle. Unfortunately it already fails with the template.

What do I need specifically:
A counter that I can set to 0 by pressing a button, then when, for example, the washing machine starts the program, the counter starts to count the KWH consumed and then calculates for me with the set price, for example 0.30 cents/Kwh.

Can someone help me how the template must look exactly for this?

Thanks in advance.