Calculate monhtly energy cost based on hourly cost until now

Hi

I’m trying to make a template sensor for estimated total cost this month based on actual cost so far.

Example: Only 10 days into a month I would take the the total cost for each day and get the average of them in total (Avg per day) and multiply with amount of days in that month.

I have a sensor from my energy company with actual cost reading per hour, that resets every hour.

Should I make a Monthly utility meter to get a continious reading?

So it would be something like this: ( Utility value / Day of the month) * Amount of days in this month ?

utility_meter:
  actual_cost: 
    name: Faktisk kostnad denne mnd
    source: sensor.accumulated_cost_my_home
    cycle: monthly

  - platform: template
    sensors:
        days_in_this_month:
            friendly_name: "Antall dager denne mnd"
            unit_of_measurement: 'Dager'
            value_template: "{% if now().month in [1,3,5,7,8,10,12] %}31{% elif now().month in [4,6,9,11] %}30{% elif now().month == 2 and ((now().year-2000) % 4 > 0) %}28{% elif now().month == 2 and ((now().year-2000) % 4 == 0) %}29{% endif %}"
        estimert_kostnad_denne_mnd:
            friendly_name: "Estimert strømkostnad denne mnd"
            unit_of_measurement: 'NOK'
            value_template: "{{ (states('sensor.actual_cost')|float/(now().day))*(states('sensor.days_in_this_month'))|int }}"
 

This seems to work. Just have to wait until next month to get a more accurate reading. This is just going to give rough estimate.

1 Like

Will you share the sensor.accumulated_cost_my_home? thx.

It is an sensor from Tibber integration.

It looks like an utility meter daily.

If you make a utility meter hourly with consumption(kwh)* energy price as utility 1
you can use that as a source in utility meter daily and get same result.