Can't setup energy probably due to wrong unit of measurement

Hello,

I have two 4 smart plugs that I would like to use to monitor energy usage.
I did the setup of the 2 first one a while ago and it works fine. I bought 2 new one (exact same model), I did the exact same setup but this time it does not show as an energy souce.

I probably did someting wrong in the config but I can’t figure out what.

The smart plug entity is: switch.antela_smart_plug_3

This is the smart plug:

The config:

sensor:
  - platform: template
    sensors:
      antela_smart_plug_3_power_meter:
        value_template: "{{ states.switch.antela_smart_plug_3.attributes.current_consumption }}"
        friendly_name: Antela Smart Plug 3 Power Meter
        unit_of_measurement: 'W'
  - platform: integration
    source: sensor.antela_smart_plug_3_power_meter
    name: Antela Smart Plug 3 Energy Meter
    unit_prefix: k
    method: left

As Home Assistant requires to have kWh unit, I created that utility meter. I’m not really sure that it is the way to go but it is was worked for the previous 2 smart plugs. If you have suggestion to make it better, don’t hesitate ^^

 utility_meter:
  antela_smart_plug_3_utility_meter:
    source: sensor.antela_smart_plug_3_energy_meter
    name: Antela Smart Plug 3 Utility Meter
    cycle: daily

When I go to history and compare the one that work with the new one, I can see that they are in different graph and the new one is not showing the unit. So I think the problem come from the unit of measurement.

So I think I should specify the unit of measurement somewhere but the config become invalid if I add a unit_of_measurement property to the utility meter. In the below screenshot, we can see that the working one has a unit_of_measurement and not the new one.

Do you have an idea of what I’m doing wrong ?

Looks to me like you are measuring watts. I think HA wants Wh or kWh.

The utility meter is normally converting W to kWh from what I understood. Am I wrong ?

Watt is not really a measure of usage(for this purpose). Wh is a measure of usage. You need a time component. That is the h.

It can convert Wh to kWh.

I’m not the worlds best teacher so.

:thinking:

state_class: total_increasing

Thank you for pointing that out.

I checked a bit more few articles on that topic and I think what I try to do make sense. Let me explain the idea. If it seems wrong to you, tell me please :stuck_out_tongue:

I have a smart plug which is giving me an attribute “current_consumption”. This attribute is the power (W) that is passing through the plug now (no need to have a time indication, the power is what is used now, it’s an instant consumption).

From that attribute, I created one sensor:

sensor:
  - platform: template
    sensors:
      antela_smart_plug_3_power_meter:
        value_template: "{{ states.switch.antela_smart_plug_3.attributes.current_consumption }}"
        friendly_name: Antela Smart Plug 3 Power Meter
        unit_of_measurement: 'W'

So I have now a entity with the current consumption (just to make it easier)

How I would like to compute the consumption:
if that attribute stays at 300W during 2 hours, the total consumption is 600Wh. That is what I tried to achieve with the Riemann sum integral.

sensor:
  - platform: integration
    source: sensor.antela_smart_plug_3_power_meter
    name: Antela Smart Plug 3 Energy Meter
    unit_prefix: k
    method: left

What do you think about that method ? Does it seems correct to you ? Any idea why it works for previous plug but not the new one (with exact same config) ?

The Riemann Sum is exactly what you need.

1 Like

Thank you for the confirmation :slight_smile: Do you have any idea why it does not show up in the energy source ? Do you see something wrong in my way of doing it ?

You may need to give your power sensor a device class:

sensor:
  - platform: template
    sensors:
      antela_smart_plug_3_power_meter:
        value_template: "{{ states.switch.antela_smart_plug_3.attributes.current_consumption }}"
        friendly_name: Antela Smart Plug 3 Power Meter
        unit_of_measurement: 'W'
        device_class: power
1 Like

Thank you I will give a try now

That is not where I told you to put it. Put the device class in the source sensor config, as I showed you.

1 Like

Ah this makes a difference ! Now the entity “Antela Smart Plug 3 Energy Meter” is visible as an energy source but not the Utility Meter.

Your help is really appreciated :slight_smile: Thank you.

Do you think I should configure the energy dashboard based on the sensor.antela_smart_plug_3_energy_meter or based on the sensor.antela_smart_plug_3_utility_meter ?
The Riemann Sum is the utility meter. Do I still need it ?
If I base everything on the energy meter, do you think it will be correct as with the Riemann sum ?

Hello @tom_l,

In your previous answer you said that

The Riemann Sum is exactly what you need.

If I understand well, the Remann Sum is the utility meter entity (not visible as an energy source).
So I’m wondering, is it making a difference to use the power meter or the riemann sum ? I have 4 smart plugs and I would like to have them aligned (showing same result no matter which plug I use). But as the 2 old ones are using the utility meter and the 2 new ones are using the power meter, I’m not sure what is the right way to go.
For the 2 new one, the utility meter is not selectable from the energy source.
Do you have any idea what I’m doing wrong ? I see that you have way more knowledge than me on what is the correct setup to have something that make sense so I would like to have your opinion.
Thanks a lot :slight_smile:

Xavier

No the Riemann Sum and Utility meter are separate things.

Riemann Sum - approximates an integral with respect to time. e.g. convert power to energy.

Utility Meter - keeps track of increasing values for a specified cycle. e.g. tracks total energy for a day / week / month / etc…

1 Like

Thanks @tom_l, I think I understand.

It would means that I don’t need the utility meter as I can query the energy dashboard to give me the consumption (or the cost) of one sensor for a day/week/month.

Is the conversion from power (W) to consumption (kWh) still needed (as home assistant accepts power as an energy source with the device_class: power you suggested above) ? I suppose it’s already automatically done by home assistant if the input is a power, is it correct ? If it still needed, any idea how to do it to allow the integration in the energy dashboard ?

Nope. There are no entities generated by the energy dashboard. Only pretty pictures. This has annoyed a lot of people.

Yes it is an energy dashboard. Not a power dashboard.

1 Like

@tom_l Got It. Thanks !

So to summarize:

  • The conversion from power (W) to consumption (kWh) is not needed and HA is taking care of it for us.
  • It’s not needed to create a utility meter to include the consumption in the energy dashboard.

Good news :slight_smile:

No that is the opposite of what I said. You can not use power sensors in the energy dashboard.

Correct.

1 Like

@tom_l Ok I see where my confusion comes from. I had 2 entities in kWh (one sensor and one utility meter).

2 entities:

  • sensor.antela_smart_plug_3_power_meter: current power (W)
  • sensor.antela_smart_plug_3_energy_meter: total consumption (kWh)

sensor.antela_smart_plug_3_energy_meter is used for the energy dashboard.

Config:

sensor:
  - platform: template
    sensors:
      antela_smart_plug_3_power_meter:
        value_template: "{{ states.switch.antela_smart_plug_3.attributes.current_consumption }}"
        friendly_name: Antela Smart Plug 3 Power Meter
        unit_of_measurement: 'W'
        device_class: power
  - platform: integration
    source: sensor.antela_smart_plug_3_power_meter
    name: Antela Smart Plug 3 Energy Meter
    unit_prefix: k
    method: left

I think it’s finally good now :smiley:
Many thanks again for your help (and for taking the time to explain). Much appreciated :slight_smile:

1 Like