Calculating Energy Costs

Noob here. Any suggestions how I can get energy costs calculations for my Sonoff POW?
I live in Spain and the tariffs have just changed to three different rates at different times

I guess what I need to do is first is put the tariff prices in then write an automation to tell HA what tariff is currently active, ie PEAK, MID or OFFPEAK then create the calculations.

This is what I have found on the forums so far but not sure how to get this all working together:

 utility_meter:
  daily_energy:
    source: switch.sonoff_1000fe2da2
    cycle: daily
    tariffs:
      - peak
      - mid
      - offpeak
  monthly_energy:
    source: switch.sonoff_1000fe2da2
    cycle: monthly
    tariffs:
      - peak
      - mid
      - offpeak
  
  cost_energy:
    friendly_name: "Energy Rates"
    unit_of_measurement: '€'
    icon_template: mdi:currency-eur
    value_template: "{{ ((states('sensor.peak') | float * 0,242837) + ((states('sensor.mid') | float * 0,146998) + (states('sensor.offpeak') | float) * 0,10404 ) | round(2) }}"

Any help would be much appreciated.

When I get this to work for the Sonoff POW I will get a Shelly to monitor the overall electricity usage.

You have the wrong source for your utility meters. They need to be energy sensors (kWh).

Then you need a few automations with time triggers to change the utility meter tariffs, using the service utility_meter.select_tariff See: https://www.home-assistant.io/integrations/utility_meter/#service-utility_meterselect_tariff

Done that. it now chooses the tariff based on the time.

Now, where do I put the tariff prices and the calculation?

Including fixing this?

You have switches where there should be energy sensors.

Like this?

utility_meter:
  daily_energy:
    source: sensor.energy
    cycle: daily
    tariffs:
      - peak
      - mid
      - offpeak
  monthly_energy:
    source: sensor.energy
    cycle: monthly
    tariffs:
      - peak
      - mid
      - offpeak

That depends, do you have a sensor called sensor.energy or did you just make that up?

I see what you mean.

I’ll try using the Integration - Riemann sum integral to create one

Nope. They are power sensors (W) not energy sensors (Wh or kWh).

Got somewhere after reading the docs and other forum topics asking the same thing.

Using the Riemann sum integral integration

   - platform: integration
     source: sensor.sonoff_1000fe2da2_power
     name: energy_pow
     unit_prefix: k
     round: 2

Then created the different tariffs using Utility Meter:

utility_meter:
  daily_energy:
    source: sensor.energy_pow
    cycle: daily
    tariffs:
      - peak
      - mid
      - offpeak
  monthly_energy:
    source: sensor.energy_pow
    cycle: monthly
    tariffs:
      - peak
      - mid
      - offpeak

Then created the sensors:

    
   - platform: template
     sensors: 
       daily_energy_cost_mid:
         unit_of_measurement: '€'
         friendly_name: 'Today Mid Tariff Cost'
         value_template: "{{ (states('sensor.daily_energy_mid') | float * 0.21269 ) | round(2) }}"
         
   - platform: template
     sensors:
       daily_energy_cost_peak:
         unit_of_measurement: '€'
         friendly_name: Today's Peak Tariff Cost
         value_template: "{{ (states('sensor.daily_energy_peak') | float * 0.242837 ) | round(2) }}"
         
        
   - platform: template
     sensors:
      daily_energy_cost_offpeak:
        unit_of_measurement: '€'
        value_template: "{{ (states('sensor.daily_energy_offpeak') | float * 0.10404 ) | round(2) }}"
        friendly_name: Today's Offpeak Tariff Cost
    
   - platform: template
     sensors:
       daily_energy_cost_all:
         value_template: "{{ (states('sensor.daily_energy_cost_mid') | float) + (states('sensor.daily_energy_cost_peak') | float) + (states('sensor.daily_energy_cost_offpeak') | float) }}"
         friendly_name: Today's Cost
        unit_of_measurement: '€'

Seems to be working :slight_smile:

1 Like

Good work! :clap:

I was expecting your next post to be about you not having energy sensors, and me having to explain the integral integration, but you searched and sorted it yourself. Well done.

One thing to be aware of is the method option in the Riemann integral.

From the docs:

So if your device switches on/off rather than gently varying in power you should set method: left for greatest accuracy.

My recommendation would be to make the utility rates per tarrif input number that you can control through the UI. This way if your rate changes you can just adjust it in the UI versus having to edit code.

Not that you have to do this. Just an option I take. I decided to not hard code any values into my automations, scripts, template sensors, … and do everything with input_number, input_select, and input_boolean and I have a dashboard in Home Assistant where I can maintain all of these values. I don’t make updates to the values often but it does help. Plus I have told my wife about this dashboard so she can adjust values herself. For example, she used to say “can we make the hallway lights less bright at night” and I would have to adjust the automation. Now she knows there is an input for this and she can just change it.

1 Like

Cool. Thank you. Just added it to the config.

The comments you made helped to prompt me to look for the solution rather than ask stupid questions that are posted in the docs and other topics so thanks @tom_l

Going to now get myself a Shelly EM to monitor the whole house as the Sonoff POW was a test and only monitoring the new refrigerator

1 Like

Very good recommendation thank you.

I like the Shelly EM. I use it myself and it has performed faultlessly for years - other than a wifi connection issue that was firmware fixed soon after. It gives me a good estimate of my quarterly bill (+/- 5%). Not sure where the inaccuracy is coming from. It should be better than that.

However just the other day I was alerted to this option you can use with ESPHome (if you are into DIY). It’s a great deal cheaper and seems to work well:

Just another option for you to consider.

Looks interesting. A lot cheaper than a Shelly.

I’ve not really messed around with ESPHome yet but it’s on my list.

Thanks

After the last update of HA, the price of energy has a lot of decimal places.
Is it possible to round the price of energy to two decimal places?

Hi all. I think I’m getting somewhere with this. Using platform: template to multiply my energy usage by tariff price.
image
Does anyone know how I change the icon from an eyeball?! And is there a way to get the unit of measurement to display before the value?
Thanks

1 Like