2021.8 - new energy feature in HA: Conversion from W to kWh

My Gosund smart plug (using ESPHome) provides a wattage entity:
image

I would like to calculate the energy (kWh) based on this sensor and use / display it in the new energy dashboard provided by HA 2021.8.

I have read about utility_meter and that I might need a template sensor to get it converted into kWh. But somehow I don’t have a clue how to realize it. Maybe anyone who can help with a short instruction?

Thanks, red

1 Like

Use this-

You should also use the “left” method for a more accurate result.

After integrating it using Reimann Sum, you can then use the sensor for Utility Meter to track your consumption (daily, weekly, monthly).

5 Likes

Thanks @ardysusilo !
At first glance, it sounds easy. I used the following in my sensors.yaml

- platform: integration
  source: sensor.energy_06_wattage
  name: energy_06_spent
  unit_prefix: k
  round: 2
  method: left

It seems to work properly (still have to validate the results).

But now when I want to use the Utility Meter, how it implement this? Would this be correct if I put this into configuration.yaml?

# Utility Meter
utility_meter:
  daily_energy_06:
    source: sensor.energy_06_spent
    cycle: daily
  monthly_energy_06:
    source: sensor.energy_06_spent
    cycle: monthly

PS: Is it possible to reset the values for sensors based on Integration - Riemann sum integral?

2 Likes

You can try the configuration for Utility Meter integration. Make sure to Check Configuration to rule out the possibility of invalid syntax.

For Integration of Riemann Sum Integral, the default unit time is h (hour). Available options are s , min , h and d .

Finally it worked as written in my last post.
Thanks @ardysusilo!

Hello,

Did you find any solution to reset your values ?

Thanks

Perfect solution, thanks!

Hi,

why not simply use this:

- platform: integration
  source: sensor.energy_06_wattage
  name: energy_06_spent_day (I would prefer energy_06_kWd)
  unit_prefix: k
  round: 2
  unit_time: d

Where the unit time “d” is for DAY?!

Ok, I got it - because the “platform: integration” doesn’t support the state_class: measurement, total or total_increasing - Therefore it doesn’t show up in the energy setup. :frowning:

Will this be fixed?

The work around I have for this is to setup a template that sets that parameter with the state just being the state of the integration:

- name: "Export Energy (template)"
  unit_of_measurement: "kWh"
  unique_id: export_energy_template
  state_class: measurement
  device_class: energy
  state: >
    {{ states('sensor.export_energy_calc') }}
3 Likes

For anybody coming to this thread by googling, like I did. In the meantime the Riemann integration is directly integrated into HA helpers. Works like a charme!
Hope this helps anybody that is searching…
Best, Frank

2 Likes

hi all

after several hours spent, i need some guidance please.
I have a huawei solar inverter and 2 strings.

I would like to a daily/monthly/yearly statistics for each string.

I created below a sensor for String 2:

  - sensor:
    - name: "Solar Fotovoltaice String 1 Sud"
      unit_of_measurement: "W"
      unique_id: "solar_foto_string1_sud"
      state_class: measurement
      device_class: power
      state: >
          {{((states('sensor.inverter_pv_1_voltage')|float) * (states('sensor.inverter_pv_1_current')|float))|int(0)}}

This sensor multiplies String 2 Voltage with String 2 Current resulting power in Watts.
How to convert it in kWh?

I’ve tried using utility meter but it is in Watt expressed.

I was thinking in creating below sensor already in kWh and use it in utility meter for statistics:

#Productie string 2 in kWh
  - sensor:
    - name: "Productie Fotovoltaice String #2"
      unique_id: productie_solar_string2_test2
      unit_of_measurement: 'kWh'
#      icon: mdi:transmission-tower
      state: >
        {{(((states('sensor.inverter_pv_2_voltage')|float) * (states('sensor.inverter_pv_2_current')|float))|int(0))/1000}}             
      device_class: energy
      state_class: total_increasing

How would you do it to store the statistics in kWh ?

1 Like

Hi, I am late to this party but trying to see if I understand what is said here.

I have a Power Station that I want to keep track of in terms of discharged energy (kWh). I only have the power sensor (attached pic). So I use this power senor as the input to this Riemann Sum Integral integration ?

@ardysusilo