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

Hi, yes the whole thing seems a bit difficult to explain. If only because I’m trying to do it in English, which isn’t my main language.

Maybe I understand something completely wrong in the electricity price calculation.

I know that the electricity provider bills in kWh. And for me the question then arose, if kWh refers to an hour, then I can also calculate kWs from it in order to be able to get a price per second.

Difficult at this point is then again the number of watts. After all, kWs are still 1000 watts per second. But if the device then consumes 120 watts or more or less, a percentage of 1000 watts at kWs must be calculated here again.

But my idea here is probably complete nonsense. I am not an electrician and have been trying to find a solution for many days now.

I said above that I don’t want a monthly overview. That’s right. But that only referred to my main question. It should calculate the euros in seconds based on the number of plug power watts.

If the whole thing can then also be displayed for the month & day, it’s great! However, not my main concern.

I am currently testing with a plug using Powercalc. I also get a kWh specification, but I still have to check whether it is correct.

@Stiltjack said something about a utility meter for cost calculation. As a noob, I don’t understand that at all.

In the end, my actual plan was:

  1. I have a plug that shows me how many watts are being used
  2. I want a card that shows me:

A) Plug1: 0 Euro [ Current ]
B) Plug1: 0 Euro [ DAY ]
C) Plug1: 0 Euro [ MONTH ]

D) Plug1: 0 kWh [ Current ]
E) Plug1: 0 kWh [ DAY ]
F) Plug1: 0 kWh [ MONTH ]

A & D should only calculate from the moment when the device measures power consumption. So at 0 nothing happens.

The same then of course for Plug2 and Plug3 etc.

  1. A display that shows me a total of [ Current ] [ DAY ] [ MONTH ] from all the plugs.

I thought it would certainly be possible to actually be able to see, for example, if I turn on the heater on Plug1 with 1600 watts of consumption, which refers to 1 hour, that the value can then also be calculated in seconds. So if I pay 0.50 euros for an hour and the device runs for 20 minutes, the display Plug1: 0 euros [ Current ] would charge me a third.

20 minutes is of course simple here, but even if it only runs for 5 minutes, it is a consumption because the total is billed at the end of the month.

I think I’m going crazy with this topic!

Ok, just a really stupid calculation and the question of whether it all makes sense:

1kWh = 0.50 Euro

1Watt / 1000 = 0.001 kWh (per hour)
0.001 kWh / 3600 = 0.000000277777778 kWh (per second)

0.000000277777778 / 1 * 0.5 = 0.000000138888889 Euro?

Am I missing something here or is the calculation correct? :smiley:

That is correct. So 1 Watt continuously, for a year, will cost you 4.38 Euro.

1 Like

Ok thanks! That would mean

is it possible to do this?:

  1. Set a counter (1) that counts every second plus 1 (as soon as the watt power number changes from 0 to > 0)
  2. (0.000000138888889 * watt power number from the plug) * Counter
  3. Once the watt power count is back to 0, the counter reading is added to a 2nd counter for the day, a third for the month and a fourth for the year.
  4. Counter 1 is set to 0 and waits for the plug’s Watt power count to change again.

The result provides the euro price in real time based on the seconds the device is running.

Does that make sense, and more importantly, can something like this be implemented in Home Assistant in a card?

From what you describe, that is what the Rieman sum integration does (if you do not have a kwh entity in your power meter), when you combine it with a utility meter. And it really does sum up “real time” of sorts (depending on sensor update frequency), but the increase in cost per second is so low, you won’t see it change, unless you are maybe fast charging your car or something.

By your own calculation, at 0.000000138888889 euro per watt, how many watts are you pulling that you think you’ll see the price go up every second, or even minute? You will need to pull about 1000 watts for 10 seconds to see one cent added. That is a lot of calculation power you want home assistant to perform to see a snail move in real time.

For comparison: My whole house (household of four, lots of electronics and induction for cooking) uses about half a cent electricity per minute on average.

Yes, that really doesn’t make much sense!

With a combination of my own sensors, automations and scripts + value template for the cards, I now have the option of starting a counter from 0 and increasing it by 1 every second until the watt power number goes back to 0. Then the counter is reset to 0.

In addition, a daily, monthly, weekly and yearly counter counts with +1.

In the card, I then use a value template to calculate the current counter status in euros based on the number of watts of the plug.

The next step would then be to save the value when the device powered off into a variable or helper and add each new value, giving me the cost for the day, week, month and year.

Ultimately, it is interesting to see how, for example, the fan heater drives up this huge number 0.000000138888889 and very quickly arrives at the first cents. Of course I could still round here, but the effect that arises when you see how fast the number moves does something in your head. Get a feel for how fast you burn money.

And that’s what it was really about for me. Truly real-time to see a number that increases rapidly, although one or the other device could also remain switched off.

For those who might want to recreate the second measurement, here are the Yaml codes - its really Basic for seconds calculation:

AUTOMATION FOR START

alias: Counter - Energy Wlan Switch 3 START
description: ""
trigger:
  - type: power
    platform: device
    device_id: 59f42927cbf8b5b485e0fd1e9b060331
    entity_id: sensor.wlan_steckdose_heizlufter_strommesser_power
    domain: sensor
    above: 5
condition: []
action:
  - if:
      - condition: numeric_state
        entity_id: counter.energy_wohnzimmer_switch3_second_timer
        above: -1
        below: 1
    then:
      - service: script.counter_energy_wlan_switch_3_seconds_start
        data: {}
mode: single

AUTOMATION FOR RESET

alias: Counter - Energy Wlan Switch 3 RESET
description: ""
trigger:
  - type: power
    platform: device
    device_id: 59f42927cbf8b5b485e0fd1e9b060331
    entity_id: sensor.wlan_steckdose_heizlufter_strommesser_power
    domain: sensor
    below: 5
condition: []
action:
  - service: script.turn_off
    data: {}
    target:
      entity_id: script.counter_energy_wlan_switch_3_seconds_start
  - wait_for_trigger: []
    timeout:
      hours: 0
      minutes: 0
      seconds: 3
      milliseconds: 0
  - if:
      - condition: numeric_state
        entity_id: counter.energy_wohnzimmer_switch3_second_timer
        above: 0
    then:
      - service: counter.reset
        data: {}
        target:
          entity_id:
            - counter.energy_wohnzimmer_switch3_second_timer
mode: single

SCRIPT FOR START & COUNTING

alias: Counter - Energy Wlan Switch 3 - Seconds Start
sequence:
  - repeat:
      until:
        - type: is_power
          condition: device
          device_id: 59f42927cbf8b5b485e0fd1e9b060331
          entity_id: sensor.wlan_steckdose_heizlufter_strommesser_power
          domain: sensor
          above: -1
          below: 0.1
      sequence:
        - delay:
            hours: 0
            minutes: 0
            seconds: 1
            milliseconds: 0
        - service: counter.increment
          data: {}
          target:
            entity_id:
              - counter.energy_wohnzimmer_switch3_second_timer
              - counter.energy_wohnzimmer_switch3_week_timer
              - counter.energy_wohnzimmer_switch3_day_timer
              - counter.energy_wohnzimmer_switch3_month_timer
              - counter.energy_wohnzimmer_switch3_year_timer
mode: single

CONFIG > COUNTER

counter:
  energy_wohnzimmer_switch3_second_timer:
    name: Energy Wohnzimmer Switch 3 Sekunden Timer
    initial: 0
    step: 1
  energy_wohnzimmer_switch3_day_timer:
    name: Energy Wohnzimmer Switch 3 Tages Timer
    initial: 0
    step: 1
  energy_wohnzimmer_switch3_week_timer:
    name: Energy Wohnzimmer Switch 3 Wochen Timer
    initial: 0
    step: 1
  energy_wohnzimmer_switch3_month_timer:
    name: Energy Wohnzimmer Switch 3 Monat Timer
    initial: 0
    step: 1
  energy_wohnzimmer_switch3_year_timer:
    name: Energy Wohnzimmer Switch 3 Year Timer
    initial: 0
    step: 1

CARD YAML:

type: entities
entities:
  - type: custom:template-entity-row
    icon: mdi:download
    name: Consumption euros per second
    state: >-
      {{ (states('counter.energy_wohnzimmer_switch3_second_timer') |
      multiply(0.000000138888889) *
      states("sensor.wlan_steckdose_heizlufter_strommesser_power") | float)}}
      Euro  
  - entity: counter.energy_wohnzimmer_switch3_second_timer
    name: Device running (Seconds)
  - entity: counter.energy_wohnzimmer_switch3_day_timer
    name: Device running (Seconds / Day)
  - entity: counter.energy_wohnzimmer_switch3_week_timer
    name: Device running (Seconds / Week)
  - entity: counter.energy_wohnzimmer_switch3_month_timer
    name: Device running (Seconds / Month)
  - entity: counter.energy_wohnzimmer_switch3_year_timer
    name: Device running (Seconds / Year)

image
image

One thing is for sure, I tried! And I think that’s what Home Assistant is all about, trying to implement things. Nevertheless, it makes little sense when I consider what is still missing here for the individual daily, weekly, monthly, annual calculations and then the data also has to be saved.

AND the worst part is that it was all for a single plug. I now have 20-50 of them all over the house afterwards… Hallelujah :smile:

So I’ll stop my plan here after many hours of testing and tinkering.

Unfortunately, the procedure via Powercalc and/or Rieman sum integration always brings me to a point… It doesn’t work exactly.

I looked at the data in the app and the values differ so much from those in Home Assistant. Sometimes that is several kWh too much or too little. And by that I don’t mean this known problem of x10 or x100 if you don’t have “Left” selected.

An exact measurement is apparently not possible and therefore pointless if at the end of the year with daily deviations of several kWhs on 365 days later completely different sums come out.

One idea is certainly to build a Shelly 3EM in the electrical boxes at the end. Then you can at least keep an eye on the total consumption of the whole house. But it is still a pity that there is no simpler and more accurate way for individual devices / rooms.

I would also like to say a big thank you to everyone who helped here! A great active community that Home Assistant has built here! Thank you very much :heart:

Well, if it is counting how long something was on, there are easier ways. A History stats sensor the first that comes to mind:

I have been trying to solve this as week, I would like to remove my energy display from the electric company, it shows the current cost/hr which changes as the load changes, I assume this is showing the cost per hr assuming you leave it on for the hr, this gives the end user a better idea of the cost rarther than showing watts.

That would be a simple calculation. You could multiply the watts by the kWh price and divide by 1000: If a kWh costs for instance 0,40 EUR, then a Watt would cost 0,0004 EUR. So 100W would cost 4 cent per hour.