Real-time energy costs based on watt data from a plug

Hi, I’ve been looking for a week now and just can’t find any info. The question is actually quite simple.

Can I display the electricity costs in Home Assistant via a plug / or several that provides me with the current number of watts in real time? So not daily or during the week or only in an hour. Really in complete real time as I get the number of watts that are consumed in real time from the plug.

Most forum posts are just total chaos. someone asks a similar question and thousands of people answer something else or halfway or in the middle of it 3 new ones appear who ask something again :rofl: Unfortunately that doesn’t get you any further :exploding_head:

Does anyone know if this is technically possible? I’m slowly despairing! 😵‍💫

I just want to be able to see how much electricity I’m using at that moment and what it’s costing me. Without peak values or current electricity prices or other things. Simply with a fixed kWh price.

I’m curious about the pros here someone has a good solution for sure! Thanks so much!

Man, that is a tough nut to crack under current energy conditions. By that I mean that Utility/Energy Companies are getting variable pricing regulations passed.

Currently electric rates for the Winter were very stable, but now due to NG (Natural Gas) inflation pricing the cost per KWH carries 3 charges all based on your consumption of Electricity.

NG charges for heating (Furnace/Hot Water Heater) now also have variable surcharges and rates also based upon your consumption.

I have not on touched the Summer (but there is a High Demand Surcharge rate involved here now to).

It would be nice if we could have a template type spreadsheet to help with the formulas used to get a more truer cost in HA in the energy area. Oh and there is a Winter/Summer rate on Water rate here to.

So I’m waiting on the more expert coders/programmers out there to assist in more detailed conditional setups in the Energy section of Home Assistant.

1 Like

Holy! That’s quite a lot of different values that you would have to consider!

In my case, none of that exists. I have contractually agreed a fixed electricity price per 1 kWh for several years. Lucky :smile:

That’s why my question is so simple. At least that’s what I think. Since the price is always the same, I don’t have to take anything into account here.

I just can’t find any information on how I can do a real-time conversion into euros based on my real-time watt consumption. For example, when I turn on the washing machine, Home Assistant can also display: Consumption Previously: 10 euros and in the next minute 10,004 euros or whatever is then calculated :raised_hands:

Then I believe your in luck. Do you have the Energy shown in the sideboard or you can navigate to it.
Settings>Dahboards>Energy
Then you have some choices on cost and which entity to use. So look there

Yes, I have already tested the Energy Dashboard. However, the watt of the plug must be converted into kWh. I was able to do that halfway. That can probably be done via integration - Riemann sum integral. However, the sensor created with it gives me wrong data compared to the Tuya app. I then set the method to left. Apparently this is also important and more accurate.

BUT now comes the problem.

I have now let the fan heater run full for 1 hour with 1620 watts. And the Energy Dashboard doesn’t show any of that. It’s going to be hours before anything comes up.

And that’s exactly what I want to do differently. Results not only after hours but to the minute or better second exact!

If I had just looked at the Energy Dashboard, it should show that the fan heater is running and that I am currently spending x euros.

I hope I explain this sufficiently so that you understand what I mean.

You should be able to build/install a card for the main dashboard that give near instantaneous readings on those plugs, em devices.

Whole House Power:
image

Plugs:

Uh, these cards with the colored circles look awesome!

I have already included the data in a card. That works great too. However, I would like to know how much money I am paying at this moment instead of just specifying the watts and volts.

Do you have an idea how to calculate this within a card?

image

That would be taking the default card and modifying it. Look/search for other energy cards that others have done.

Power companies charge by the kWh. You can easily show how much energy you have used in the past hour, or day, or week, along with the cost, but it doesn’t make sense to ask how much you are paying at this moment.

Hi, that’s exactly the problem! :smile: I don’t want only to know what I’ve used after a day or at the end of the month. For example, when I turn on the TV, I want a money counter thats go up in real time. That I can see what I am causing in terms of costs per second or per minute.

1 Like

Do you mean something like this:

You can watch all these figures update second by second in real time, but it has to be an hourly/daily/monthly total.

2 Likes

That’s exactly what I’m looking for!!! :raised_hands: how can i build this?

It’s 3 am here - can I get back to you in the morning…? :sleeping:

1 Like

hey of course, no problem! It’s already 4:30 in the morning here in Germany :smile: Good night :smiley:

1 Like

Good morning.

Sad, isn’t it? All these men (it’s usually men) sitting up into the small hours… Still, enough of that. :roll_eyes:

I use a HACS integration called Powercalc to monitor all my energy usage. You probably know it already - I’m sure you could get the same results with “official” methods, but Powercalc is much more compact and easy to maintain, and you can use estimated figures if you don’t have enough smart plugs. The docs are pretty thorough.

An annotated example. Say I want to monitor what I’m spending on the smart home… These devices all use power at a steady rate. Part of my configuration.yaml looks like this:

  - platform: powercalc
    create_group: smarthome                   # Groups devices together to give total energy usage
    entities:

    - entity_id: input_boolean.echo_dot       # The entity to monitor.These devices are on all the time, so an input_boolean (always on) does the job.
      fixed:
        power: 1.7                            # I don't want to spend a fortune on smart power monitoring plugs. This is the estimated wattage of the device from the manufacturer's docs.
      multiply_factor: 5                      # I have five echo dots.

    - entity_id: input_boolean.hue_hub
      fixed:
        power: 1.5

    - entity_id: input_boolean.lightwave_hub
      fixed:
        power: 1.5

    - entity_id: input_boolean.home_assistant
      fixed:
        power: 4

    - entity_id: input_boolean.broadlink
      fixed:
        power: 5
      multiply_factor: 3

For my computers, I do have smart plugs, since their power consumption is irregular and they may be switched off:

  - platform: powercalc
    create_group: computers
    entities:
        
# Dell
    - entity_id: switch.tasmota_10
      power_sensor_id: sensor.tasmota_10_energy_power
      
# Acer
    - entity_id: switch.tasmota_15
      power_sensor_id: sensor.tasmota_15_energy_power
      
# Laptop
    - entity_id: switch.tasmota_17
      power_sensor_id: sensor.tasmota_17_energy_power

Powercalc creates virtual power sensors (Watts) and virtual energy sensors (kWh) for each group, in this case:

   sensor.smarthome_power (Watts)
   sensor.smarthome_energy (kWh)

   sensor.computers_power (Watts)
   sensor.computers_energy (kWh)

It also has a utility meter function, which gives you more sensors to record energy usage on a daily, weekly or monthly cycle, in this case:

   sensor.smarthome_energy_monthly
   sensor.computers_energy_monthly

These give you the figures that you can see ticking up in a dashboard entities card. (I should warn you, though, that for most devices it’s like watching paint dry…).

To get costs, I have a set of templates:

  - sensor:
      - name: "smarthome monthly"
        state: '{{ (states("sensor.smarthome_energy_monthly")| float(0) * states("input_number.electricity_rate")| float(0) / 100) | round (2) }}'
        device_class: monetary
        state_class: total_increasing
        unit_of_measurement: "£"
        icon: mdi:home

input_number.electricity_rate comes from my electricity bill (currently 32.6460 pence per kWh).

Hope this makes sense. I haven’t done much work on the dashboard itself. You can get a feel for comparative energy usage in the home with HACS cards like Lovelace power usage graph card with regular expressions.

This updates in real time, but it doesn’t store any data. Clicking on a segment gives you the total usage since the card was installed. Again, the data come from Powercalc.

1 Like

Another approach is this: Home Integration - Riemann sum integral for energy calculation, it is a standard Home Assistant helper function.
I am using that with some devices, that gives you a semi-real-time kWs reading, which you can convert to semi-real-time kWh readings. (if you choose the “seconds” integration time). The accuracy is dependent of the accuracy of your sensor readings, sensor update time and chosen integration time.
You can define this by choosing a “helper” in the UI and selecting the “Riemann sum intgral” function or put this part (example) in your “configuration.yaml”:

sensor:
  - platform: integration
    source: sensor.energy_socket_5c2faf025214_active_power
    name: Quooker kWs meter
    unit_prefix: k
    round: 3
    unit_time: s
    method: trapezoidal
    unique_id: zz_testintegration3

  - platform: integration
    source: sensor.aubess_smart_socket_em_8_power
    name: UPS kWs meter
    unit_prefix: k
    round: 3
    unit_time: s
    method: trapezoidal
    unique_id: zz_testintegration4

template:
  - sensor:
      - name: Quooker kWh meter
        icon: mdi:flash
        state: "{{ (states('sensor.quooker_kws_meter') | float / 3600.0) | round(3, default=0)}}"
        unit_of_measurement: kWh
        unique_id: zz_testintegration5

  - sensor:
      - name: UPS kWh meter
        icon: mdi:flash
        state: "{{ (states('sensor.ups_kws_meter') | float / 3600.0) | round(3, default=0)}}"
        unit_of_measurement: kWh
        unique_id: zz_testintegration6

The “Quooker sensor” here is a HomeWizard Wi-Fi smart plug the “UPS sensor” is an Aubess (Tuya) Wi-Fi smart plug. The HomeWizard plug is more accurate (and also has its own kWh meter) because it is pushing data every few seconds, while the second plug has to be polled, which is normally every 30 seconds or longer, if the data does not change.

I like your use case. I recommend creating a helper to house your current electricity rate ($/kwh). Then create a template sensor in your configuration.yaml to multiply your watts sensor (div by 1000 to get to kw) by your electricity rate. This will give you a view of your cost if that usage were to persist for 1hr.

I have taken similar approaches to define status or “thresholds” to drive automations based on current power usage.

WOW!

Thanks for the detailed explanation! I hesitated briefly because I knew that Powercalc creates virtual sensors and therefore the data is not really “real”. But then I read on and you wrote about your “real” energy plugs that you can also use!

Awesome I’ll test that tonight.

Thank you very much! :raised_hands:

Thank you very much for the info!
I’ll take a look at that too! Maybe this can actually be done without Powercalc :smiley:

You have quite a few partial answers but none will give you what you want, simply because what you ask is contradictory. You ask real time cost from Watts. But Watts don’t translate to cost by themselves without a time for which those watts are used. Prices are in kWh: the W are the watts, but the h stands for hours, which is missing from your question. A watt consumed for a second is 60 times as cheap as the same watt used for a minute. So cost per what period do you mean?

You say you do do not want it per day or per hour, but real time. When you see the cost for a month you say that is what you want. But that cannot be calculated from watts in real time, as the cost slowly increases. Your watts can be 0 when a device is off, but the cost for that month will not be 0 if you used the device before during that month.

If you want to know monthly cost, you need a Wh or kWh value. The Riemann sum suggested above will help you derive kWh from W if your meter only shows W. But it is likely it also provides kWh, so you won’t need Riemann. But you do need to explain better what cost you are after.

If you expect the cost to be 0 when the device is off, then monthly cost is not what you are after. Then Watts can be used to calculate a fictive value for what the cost will be if you leave the device on for a certain time. But still you need to know what time you think the watts will be used for to have some idea of cost. And the cost won’t happen if you don’t keep the device on that long. But it will be much more real time. Using a Riemann sum over a very short period for this use case is way more complex than needed.

Powercalc can simulate a power meter, but as I understand it you have a power meter so powercalc will not help you further.