I’m using a utility meter to track my energy consumption daily/monthly/yearly (monthly_cost), also have a sensor number input to be able to define the current energy cost manually (input_number.energy_cost_kwh).
Created the following template sensor to get the monthly energy cost:
Not using the input_number.energy_cost_kwh directly I’m creating a template sensor called energy_cost as shown above.
The issue with this implementation is that every time I change the energy cost in the middle of the month the monthly_cost changes according to the new value.
I would like it to consider the price along the time. For instance, if I have paid X kwh at 0.1€ and then change the price to 0.2€ would expect to pay the next Y kwh at this price.
Currently, the calculations are applying 0.2€ to Y and X kwh.
Can someone give me some help on this topic, please?
The way you could implement this is with a daily energy utility meter and a triggered template sensor.
Trigger the template sensor just before midnight, calculate your daily cost by multiplying the daily energy by the current price. Then add this to the running total of the template sensor,
I tried to explain it in the picture above. So if I change the price of the kwh in the middle of the month the template sensor gives me a total of 20€ instead of 15€.