Any experience with Utility Meter functions?

Hi there!
I have a Shelly EM. It properly works in home assistant but I have some problem for the utility meter functions.

This is my configuration. Could you help me to find the error?
Thank you so much.

#############
# SHELLY EM #
#############
switch:
  - platform: mqtt
    name: "Output"
    state_topic: "shellies/shellyem-XXXXXX/relay/0"
    command_topic: "shellies/shellyem-XXXXXX/relay/0/command"
    qos: 1
    payload_on: "on"
    payload_off: "off"
    retain: false
 
sensor:
  - platform: mqtt
    name: "Power 1"
    state_topic: "shellies/shellyem-XXXXXX/emeter/0/power"
    unit_of_measurement: "W"
  - platform: mqtt
    name: "Reactive power 1"
    state_topic: "shellies/shellyem-XXXXXX/emeter/0/reactive_power"
    unit_of_measurement: "PR"
  - platform: mqtt
    name: "Voltage 1"
    state_topic: "shellies/shellyem-XXXXXX/emeter/0/voltage"
    unit_of_measurement: "V"
 
  - platform: mqtt
    name: "Power 2"
    state_topic: "shellies/shellyem-XXXXXX/emeter/1/power"
    unit_of_measurement: "W"
  - platform: mqtt
    name: "Reactive power 2"
    state_topic: "shellies/shellyem-XXXXXX/emeter/1/reactive_power"
    unit_of_measurement: "PR"
  - platform: mqtt
    name: "Voltage 2"
    state_topic: "shellies/shellyem-XXXXXX/emeter/1/voltage"
    unit_of_measurement: "V"

##############################
## Shelly and power sensors ##
##############################

  - platform: rest
    name: Shelly EM Wifi
    resource: http://192.168.1.47/status
    value_template: '{{ value_json.wifi_sta.rssi }}'
    scan_interval: 180
    unit_of_measurement: dB

  - platform: rest
    name: Shelly Casa
    resource: http://xxx.xxx.xxx.xx/status #Shelly's IP
    value_template: '{{ (value_json.emeters.0.total | float /1000)|round(3) }}' # Wh to kWh
    scan_interval: 300 # no point updating faster than this. The Shelly only updates every 5 minutes
    unit_of_measurement: kWh

  - platform: rest
    name: Shelly PdC
    resource: http://xxx.xxx.xxx.xx/status #Shelly's IP
    value_template: '{{ (value_json.emeters.1.total | float /1000)|round(3) }}'
    scan_interval: 300
    unit_of_measurement: kWh

  - platform: mqtt
    name: "Energia Casa"
    state_topic: "shellies/shellyem-XXXXXX/emeter/0/power"
    value_template: '{{ value|round(1) }}'
    qos: 1
    unit_of_measurement: "W"
    icon: mdi:gauge

  - platform: mqtt
    name: "Energia PdC"
    state_topic: "shellies/shellyem-XXXXXX/emeter/1/power"
    value_template: '{{ value|round(1) }}'
    qos: 1
    unit_of_measurement: "W"
    icon: mdi:gauge

  - platform: template
    sensors:
      total_power:
        friendly_name: 'Total Power'
        entity_id:
          - sensor.energia_casa
          - sensor.energia_pdc
        value_template: "{{ (states('sensor.energia_casa')|float + states('sensor.energia_pdc')|float)|round(1) }}"
        unit_of_measurement: "W"

  - platform: statistics
    name: 'Power Stats'
    entity_id: sensor.total_power
    sampling_size: 50000
    max_age:
      hours: 24
    precision: 1

#################
# UTILITY METER # 
#################
utility_meter:
  energy:
    source: sensor.energia_casa
    cycle: monthly
  energy:
    source: sensor.energia_pdc
    cycle: monthly
  daily_energy:
    source: sensor.energia_casa
    cycle: daily
  monthly_energy:
    source: sensor.energia_casa
    cycle: monthly
  daily_energy:
    source: sensor.energia_pdc
    cycle: daily
  monthly_energy:
    source: sensor.energia_pdc
    cycle: monthly

Naming a power as sensor an energy sensor does not make it an energy sensor.

  - platform: mqtt
    name: "Energia Casa"
    state_topic: "shellies/shellyem-XXXXXX/emeter/0/power"
                                                      ^---- see, power, not energy.

You need to use actual energy sensors in your utility meters. This one for example:

  - platform: rest
    name: Shelly Casa
    resource: http://xxx.xxx.xxx.xx/status #Shelly's IP
    value_template: '{{ (value_json.emeters.0.total | float /1000)|round(3) }}' # Wh to kWh
    scan_interval: 300 # no point updating faster than this. The Shelly only updates every 5 minutes
    unit_of_measurement: kWh

I’m really sorry, I’m a noob.
I did take a copy from yours configuration:

- platform: rest
  name: Shelly EM Wifi
  resource: http://10.1.1.24/status
  username: !secret shelly_usr
  password: !secret shelly_pwd
  authentication: basic
  value_template: '{{ value_json.wifi_sta.rssi }}'
  scan_interval: 180
  unit_of_measurement: dB

- platform: rest
  name: Shelly T31 Total Energy # lights and power
  resource: http://10.1.1.24/status
  username: !secret shelly_usr
  password: !secret shelly_pwd
  authentication: basic
  value_template: '{{ (value_json.emeters.0.total | float /1000)|round(3) }}' # Wh to kWh
  scan_interval: 300 # no point updating faster than this. The Shelly only updates every 5 minutes
  unit_of_measurement: kWh

- platform: rest
  name: Shelly T41 Total Energy # heating and hot water
  resource: http://10.1.1.24/status
  username: !secret shelly_usr
  password: !secret shelly_pwd
  authentication: basic
  value_template: '{{ (value_json.emeters.1.total | float /1000)|round(3) }}'
  scan_interval: 300
  unit_of_measurement: kWh

- platform: mqtt
  name: "Tariff 31 Power"
  state_topic: "shellies/shellyem-B9E940/emeter/0/power"
  value_template: '{{ value|round(1) }}'
  qos: 1
  unit_of_measurement: "W"
  icon: mdi:gauge

- platform: mqtt
  name: "Tariff 41 Power"
  state_topic: "shellies/shellyem-B9E940/emeter/1/power"
  value_template: '{{ value|round(1) }}'
  qos: 1
  unit_of_measurement: "W"
  icon: mdi:gauge

On the entities I can find only the shelly’s sensor of power, voltage and reactive power but not energy

The following are your energy sensors:

sensor.shelly_casa
sensor.shelly_pdc

Hi there - I’m brand new to HA. What are you using to produce those graphs and stats in those two views you’ve attached there? Looks awesome.

The graphs can now be made with sensor cards, and ask it to do a line.
There is also a custom bar-card available.
Get the HACS installed, that will help you wth the custom cards.

Thank’s a lot @tom_l

your explanations are very detailed and I understood a lot with your examples.
Could you gave more information about the cards you’ve used for Energy use and the graphs with colors & night / day?

Regards

https://community.home-assistant.io/t/daily-energy-monitoring/143436/17?u=tom_l

and

https://community.home-assistant.io/t/daily-energy-monitoring/143436?u=tom_l

1 Like

Thanks @tom_l

BTW I’ve just received my Shelly EM so I can compare from the values on the official meter :slight_smile:

@fribse sorry for jumping into this old conversation. I’m trying to setup something like you were doing here, work out the kWh of multiple sensors that report real-time power consumption. My end goal is to track cost of the individual items.

I’ve got to the same point as you are here and I’m also getting W not kWh.

I’m tracking hourly, daily, weekly and monthly usage through utility meter for the individual sensors. What’s strange is the hourly, daily and monthly totals are showing W but weekly is correctly showing kWh.

Did you find out what was causing you to also get W reported?

I’ve actually put it aside for now, I have to redo it when I get the time (yeah one should think there were a lot of time at the moment, but noooo), but I get the daily summations from ESPHome. I would also like to push all the info to influxdb and grafana, but that’s next step after that.

I did the integration sensors like this (integration over time):

  - platform: integration
    source: sensor.pool_power
    name: pool_energy
    unit_time: h

That gives the Wh or kWh.

1 Like

Guess this is an Old topic but here is an update nonetheless.

I setup 3 x PZEM 004T for a 3 phase supply last week.
While the device reports instant power and accumulated usage, the latter is prone to issues as the value resets after even short power outages (which unfortunately i get plenty of)

The solution (s) i am currently testing uses:
A)

  • Use the Instant power (Watts) to populate sensors in HA
  • Use the Riemann sum integration sensor in HA to calculate the power (kWH) usage for 3 X kWH sensors
  • Use the utility meter component in HA to compute daily and monthly usage

B)
Once this was done, I setup influx and grafana for the graphing

C) I also setup a local openenergymonitor (OEM) server to test it as an alternate to B)
HA has a component called open emoncms_history that allows you to send sensor feeds to it
OEM also allows you to transform power (W) readings into accumulated kWH

I think I wil do away with B) entirely as C) seems better suited for the typical logging use cases for HA (power/ temperature etc)

Hi
Would love to have more info about you C setup. I presently have my data being stored in Infuxdb but haven figured out how to use Grafana at all. Am using the utility meter component to convert W into kWh. Seems to be working. Calculatons match bill.

Look forward to trying emoncrm. Where did you download the local server.

Thanks

the local server details are on github

My setup details :

what are the sensor cards in your lovelace screenshot?

https://github.com/superczar/home-assistant/blob/15d773d82b9dfd53c8e38d4ce0637ea70cd191f8/images/sensor1.jpg

Temperature sensors drawn with grafana.
Having said that, shifting away from grafana towards emoncms…
Less pretty graphs but far more easy to use!

Is it possible to bulk load old data to utility meter?
I fear it´s a “from now on, start with zero” thing, but who knows… :wink:

Background:
Integrated utility meter months after starting with HA and due to some plug trouble (Shelly erasing their memory on firmware updates - how stupid is that…) I lost all my total consumption values since the beginning.

No. There is no way to do that.

That´s what I expected.

What do you guys do with single measurements?
Do you sum single measurements up to rooms or the whole house?

Currently I use it for single power plugs only. No aggregation at the moment. Curious to see what´s possible with all that numbers provided by this great utility meter. Wish I had integrated it right from the beginning (start with HA).

I’ve set up an aggregation sensor (thanks to @tom_l I got it working :slight_smile: )

total_daily_power:
      friendly_name: Samlet forbrug for i dag
      unit_of_measurement: kWh
      value_template: >
        {{ expand('group.daily_power_usage')
        | rejectattr('entity_id', 'eq', 'sensor.power')
        | map(attribute='state')
        | map('float') | sum | round(3) }}
      device_class: power

That sums up the daily power. Just before midnight I store it in an input variable, so I can show ‘yesterdays’ powerusage.

3 Likes