Utility Meter calculation wrong - solved: actually wrong implementation

I want to use the Utility Meter addon for both of my smart plugs I own. They are Xiaomi Mi Smart Plug (Zigbee), and are connected to deCONZ and then integrated with the deCONZ addon. They work fine, show current power use and life time.

I integrated it as shows below, the problem is that the numbers a very wrong. For one plug the consumption is to low, and for the other to high.

I reset all data at 8PM, and let it run for 59 minutes. The server uses ~65W, so it should be an hourly power of ~65Wh (?) and for the *desk * mean is ~120W, so it should be ~120Wh hourly use (or do I misunderstand power calculation completly).
The server power use showed 3W for the past 30 minutes, where the desk plug only increase.

Earlier today, the “desk” used ~30W, but the hourly (daily etc) was way higher then the server power use, eventough it uses ~60W. Sadly I can’t show it now as I reseted it, though I can reproduce it tomorrow evening.

I don’t get how the power calculation is so off, for the server plug, it is way to low, and for the desk it is to high, the config are the same…

Is there something I’m missing?
I tried to use add “unit_of_measurement: W” but that only gives an error messages when checking the config file.

sensor.server_use / sensor.desk_use is the power usages live.

utility_meter:

  hourly_energy_server:
    source: sensor.server_use
    cycle: hourly
  daily_energy_server:
    source: sensor.server_use
    cycle: daily
  weekly_energy_server:
    source: sensor.server_use
    cycle: weekly
  monthly_energy_server:
    source: sensor.server_use
    cycle: monthly
  bimonthly_energy_server:
    source: sensor.server_use
    cycle: bimonthly
  quarterly_energy_server:
    source: sensor.server_use
    cycle: quarterly
  yearly_energy_server:
    source: sensor.server_use
    cycle: yearly

  hourly_energy_desk:
    source: sensor.desk_use
    cycle: hourly
  daily_energy_desk:
    source: sensor.desk_use
    cycle: daily
  weekly_energy_desk:
    source: sensor.desk_use
    cycle: weekly
  monthly_energy_desk:
    source: sensor.desk_use
    cycle: monthly
  bimonthly_energy_desk:
    source: sensor.desk_use
    cycle: bimonthly
  quarterly_energy_desk:
    source: sensor.desk_use
    cycle: quarterly
  yearly_energy_desk:
    source: sensor.desk_use
    cycle: yearly

System information:

version: core-2021.3.4
installation_type: Home Assistant Supervised
dev: false
hassio: true
docker: true
virtualenv: false
python_version: 3.8.7
os_name: Linux
os_version: 4.19.0-14-amd64
arch: x86_64
timezone: UTC

SOLVED
I used the wrong sensor.
If someone have the same problem, that the energy nr do not make sense, you are using the wrong sensor. It should be the sensor that calculats in kWh and is the total energy, not the live view.

1 Like

The utility meter needs an energy sensor, not power.

  1. I control the polling on my power sensor. (I use tasmota and control how often MQTT sends an update. (Not entirely necessary)

2.Calculate the ‘instantaneous kwh’ (I.e as you said above at 120W this should be 120Wh if it was to run for an hour). This is more like kWh/s (I.e if you think about the units-> kWh/s = ((W/1000)*3600)/1 = W * (3600/1000) = W * 3.6). )

  1. Integrate with unit time ‘a’ to give the actual kWh

  2. Now create utility meters.

  3. Calibrate. There are different methods to polling/integrating/etc which will ensure you get the correct value.

Hopefully this can get you started!
To anyone wondering, I am using a wholesale electricity company so my cost of electricity changes quickly. I use this method so I can calculate the ‘live’ power cost.


utility_meter:
  ##Fridge
  fridge_power_kwh_daily:
    source: sensor.fridge_power_kwh_integral
    cycle: daily
    net_consumption: true

sensor:
  # Fridge Power
  - platform: template
    sensors:
      fridge_power_kwh:
        friendly_name: Fridge Power 1s kWh
        value_template: "{{ ( states.sensor.fridge_power.state | float ) / (1000 * 3600) }}"
        unit_of_measurement: 'kWh' 
      fridge_power_cost:
        friendly_name: Fridge Power 1s $
        value_template: "{{ (( states.sensor.amber_general_usage_price.state | float ) / 100 ) * ( states.sensor.fridge_power.state | float ) / (1000 * 3600) }}"
        unit_of_measurement: '$' 
  - platform: integration
    source: sensor.fridge_power_kwh
    name: fridge_power_kwh_integral
    method: left
    unit: 'kWh'
    unit_time: 's'
    round: 3
  - platform: integration
    source: sensor.fridge_power_cost
    name: fridge_power_cost_integral
    method: left
    unit: '$'
    unit_time: 's'
    round: 3

Okay, so it is not possible with an outlet that only gives live data and total?

Okay,
I tried to modify your code so I can use it, but I get an error

bad indentation of a mapping entry at line 40, column 16:
            sensors:
                   ^

The code:

utility_meter:

  ##server
  server_power_kwh_daily:
    source: sensor.server_use
    cycle: daily
    net_consumption: false
  ##Fridge
  desk_power_kwh_daily:
    source: sensor.desk_use
    cycle: daily
    net_consumption: false
    
###### Sensors
sensor:


  # Power Calculation
  # Server
    - platform: template
        sensors: #<- thisone
          fridge_power_kwh:
            friendly_name: Server Power 1s kWh
            value_template: "{{ ( states.sensor.server_use | float ) / (1000 * 3600) }}"
            unit_of_measurement: 'kWh' 

    - platform: integration
        source: sensor.server_use
        name: server_power_kwh_integral
        method: left
        unit: 'kWh'
        unit_time: 's'
        round: 3
  # Desk
    - platform: template
        sensors:
          fridge_power_kwh:
            friendly_name: Desk Power 1s kWh
            value_template: "{{ ( states.sensor.desk_use | float ) / (1000 * 3600) }}"
            unit_of_measurement: 'kWh' 

    - platform: integration
        source: sensor.desk_use
        name: desk_power_kwh_integral
        method: left
        unit: 'kWh'
        unit_time: 's'
        round: 3

If your total kWh resets every day then you can only use it for a maximum cycle length that long (or less) in the utility meter.

The way around it is to use the integral sensor to integrate your power, giving energy. This can then be used in the utility meter. Make sure to read the bit about method (left method is usually the best).

The value of the total kWh does not reset. I do not know if I even can do that. After a short problem with deCONZ both plugs were reconnected to HA, but the total consumption was not reset.

So I should use the total kWh sensor? I’ll change it, I tried it for just a few minutes a couple of days ago, but the values where very high, because the sensors value of the total use are now 28kWh and 21kWh.

I’ll also look at the integration you linked and change the header of this thread.

Yes that is the sensor to use with your utility meters.