Calculating power cost using utility meter

Looking trough the forums I made these sensors to register power consumption from one of the powerplugs I use. The utility meter and the Power consumption meter are both working and populating correctly from what I can tell. But somehow the cost calculation stays at 0.0

utility_meter:
  ac_usage_month:
    source: sensor.ac_power_consumption
    cycle: monthly
    tariffs:
      - offpeak
      - peak


sensor:
  - platform: template
    sensors:
      ac_power_consumption:
        friendly_name: "AC Power Consumption"
        unit_of_measurement: 'W'
        icon_template: mdi:flash
        value_template: "{{ state_attr('switch.ac_woonkamer', 'load_power') }}"
      ac_cost_month:
        friendly_name: "AC cost this month"
        unit_of_measurement: '€'
        icon_template: mdi:currency-eur
        value_template: "{{ (states('sensor.ac_power_consumption_peak') | float * 0.23006 + states('sensor.ac_power_consumption_offpeak') | float * 0.21269) | round(2) }}"
1 Like

What is sensor.ac_power_consumption_peak and _offpeak? All you show is the template sensor for ac_power_consumption.

You might need to put entity_id in those template sensors in case it can’t figure out which entity it needs to track.

:zipper_mouth_face: that should offcourse be

utility_meter.ac_usage_month_peak &
utility_meter.ac_usage_month_offpeak

Thanks Jim :slight_smile:

1 Like

Unfortunately that didn’t resolve the issue. I now have this for the cost sensor:

      ac_cost_month:
        friendly_name: "AC cost this month"
        unit_of_measurement: '€'
        icon_template: mdi:currency-eur
        value_template: "{{ ((states('utility_meter.ac_usage_month_peak') | float * 0.23006) + (states('utility_meter.ac_usage_month_offpeak') | float) * 0.21269 ) | round(2) }}"

But it stays at 0.0€

image

The screenshot shows:
current usage - current tariff - peak usage - offpeak usage - total monthly cost

1 Like

Anyone got a clue?

do you have the recorder configured? perhaps there is no data in the database?
i would also put each of your senosrs into the template editor and see the values and then build out your template query and visualize the results. if you got nothing that shows there, then you have other issues to solve for.

Yes it is, in the screenshot I added you can see the peak and offpeak meters have values of 32046W and 19595W. Those are the values I’m trying to multiply and sum up.

Just checked mine, I don’t have any utility meter entities, only sensors, try this ?

  ac_cost_month:
    friendly_name: "AC cost this month"
    unit_of_measurement: '€'
    icon_template: mdi:currency-eur
    value_template: "{{ ((states('sensor.ac_usage_month_peak') | float * 0.23006) + (states('sensor.ac_usage_month_offpeak') | float) * 0.21269 ) | round(2) }}"

Also, my cost is in kWh, are you sure your cost is in Watts ?

From the docs:

Example configuration.yaml entry

utility_meter:
  energy:
    source: sensor.energy_in_kwh
    cycle: monthly
4 Likes

Ah great, that works. Thanks so much. Just need to adjust the cost to Kw :laughing:

image

1 Like

I mean kilowatt hour not just kilowatt.
My energy is costed using kWh

1 Like

yes, mine is in kWh as well although I don’t really understand what the per hour does in there.

Have a look on google to see the difference, you need to feed the utlility meter platfom with an energy input and not a power input. Have a look at the docs also.

1 Like

Just seen this:

Energy

An integration sensor is quite useful in energy billing scenarios since energy is generally billed in kWh and many sensors provide power in W (Watts).

If you have a sensor that provides you with power readings in Watts (uses W as unit_of_measurement ), then you can use the integration sensor to track how much energy is being spent. Take the next configuration as an example:

sensor:
  - platform: integration
    source: sensor.current_power
    name: energy_spent
    unit_prefix: k
    round: 2

This configuration will provide you with sensor.energy_spent who will have your energy in kWh.

1 Like

Ok so if I want a correct calculation I need the following sensors feeding data to eachother:

- sensor 1: powersocket wattage
- sensor 2: integration that transfers W to kWh
- sensor 3+4: utility meter with peak and offpeak readings
- sensor 5: cost calculation

No that’s not correct since the integration sums up. Then how would you make a difference between peak and offpeak tarrifs?

Integration sensor integrates, it does not sum up.

Integration sensor enables you to get the energy used (measured in kWh) from samples of power readings from your sensor.

@Holdestmade is pointing you in the right direction.

Use the entity created by the integration as the source for the utility meter

I hate Utility Meter, or rather the whole topic of trying to work out power consumption > cost. Been playing with it for over a week and still not go it!

To confirm what dgomes is saying, the flow should be?

powersocket wattage > integration
integration > Utility Meter
Utility Meter > Template Sensor (to get $ cost for total kwh)

I have this setup for one power plug that my pool pump is connected to. I’ve broken the Utility Meter into various cycles to get hourly, daily, and weekly readings, I’m a few days into running it and things seem to be working.

However, when adding a second socket (same socket type as above, zigbee real-time W usage) that this time is connected to a PC I hit a problem. I can see a reading from powersocket wattage, but not getting anything come out of integration. Silly question, you can run multiple devices through Utility Meter?

You can have multiple of any integration, just duplicate the platform

   - platform: x
     etc...
   - platform: x
     etc...

Thanks, if its not that then back to the drawing boards to work out what I’m doing wrong! :slight_smile:

update: I really don’t like the Utility Meter. I commented everything out and started adding one component at a time till it broke. After a dozen restarted everything was added back AND working, I didn’t change a thing! Grrrr…

Now I have data being logged across multiple devices and time periods time to get my calculator out to check the calculations are correct.

ok i’m new to this too
I got an electric boiler and have a plug that measures in Watt too
So i followed the advice here and have this:

this one should do the Watt → kwh
Then i got another

Which will sum it up , right? during day… (the boiler uses Watt every ± hour)

So i will get x kwh per day? right?

Will this be correct?
Then if i want to know how much kwh that is in a year, i can multiply it by 365
And if i want to know how much it spends… i have to multiply it accordingly my energy supplier?
Or do i let HA do this?