Configuring Shelly EM Energy Meter

I am creating a utility meter at the moment. And I found out that there are supposed to be sensors “total” and “energy”.

Note that with the Shelly you have an option of getting total or energy data. total records energy in Wh, and is accumulated in device’s non-volatile memory. Whilst energy and returned_energy do not survive a power cycle or reboot (i.e. stored in volatile memory)

But I see only “energy” sensor in my entities while connected over WiFi via the built-in HA integration. And I tested it out and apparently all data is lost from the energy sensor when I disconnected power of the shelly device.

So the question is how to create a utility meter and preserve the data? Do I have to use MQTT and custom sensors in this case?

Where is that quote from?

Here Setting up Power and Energy Monitoring with a Shelly EM and Home Assistant | by Cyan Automation | Medium

They are using mqtt. Ignore that. And answer this:

So in the utility meter, should I use sensor energy? Or which one?

Yes, the total energy sensors.

1 Like

a bit side topic here, I also have some Shelly Plus PM’s, but in the energy configuration page I can select them to be monitored, but they immediately show this status:

I’m wondering if this a configuration issue, or a more general issue with the Shelly plus devices? Shelly gen1 devices work w/o issues.

1 Like

many thanks! wouldn’t have come to my mind that it could be related to an authentication problem as all other functionality works.

​Has anyone managed to solve the issue with negative consumption when the equipment is not working mentioned by @Shaad and @jrhbcn . I have the same problem, but with a dishwasher. I have regular negative values and sometimes spikes of power when the dishwasher is not working.

1 Like

I installed a Shelly EM with 2 clamps last week.
In the Shelly app the 2 “devices” are visual, but in Home Assistant, I only see 1 channel (first clamp).
Is there a way to add te second channel/clamp in HA (buildin Shelly HA integration)?

check what you see in the integration, you should have something similar

Yes, i see similar, but nothing which mentions channel 2, only the overall sensors and the sensors for channel 1 are available.

using debut moden I found these errors:

2022-01-18 18:06:02 DEBUG (MainThread) [homeassistant.components.utility_meter] Setup utility_meter.energia_oggi_casa

2022-01-18 18:06:02 DEBUG (MainThread) [homeassistant.components.utility_meter] Setup utility_meter.energia_mese_casa

2022-01-18 18:06:02 DEBUG (MainThread) [homeassistant.components.utility_meter] Setup utility_meter.energia_anno_casa

2022-01-18 18:06:02 DEBUG (MainThread) [homeassistant.components.utility_meter] Setup utility_meter.consumo_giornaliero

2022-01-18 18:06:14 DEBUG (MainThread) [homeassistant.components.utility_meter] Setup utility_meter.consumo_mensile

2022-01-18 18:06:35 DEBUG (MainThread) [homeassistant.components.utility_meter.sensor] CRON pattern: 0 0 * * *

2022-01-18 18:06:35 DEBUG (MainThread) [homeassistant.components.utility_meter.sensor] CRON pattern: 0 0 1 * *

2022-01-18 18:06:35 DEBUG (MainThread) [homeassistant.components.utility_meter.sensor] CRON pattern: 0 0 1 1/12 *

2022-01-18 18:06:35 DEBUG (MainThread) [homeassistant.components.utility_meter.sensor] CRON pattern: 0 0 * * *

2022-01-18 18:06:35 DEBUG (MainThread) [homeassistant.components.utility_meter.sensor] CRON pattern: 0 0 * * *

2022-01-18 18:06:35 DEBUG (MainThread) [homeassistant.components.utility_meter.sensor] CRON pattern: 0 0 1 * *

2022-01-18 18:06:35 DEBUG (MainThread) [homeassistant.components.utility_meter.sensor] CRON pattern: 0 0 1 * *

2022-01-18 18:06:36 ERROR (MainThread) [homeassistant.components.utility_meter.sensor] Could not restore state <unknown>. Resetting utility_meter.energia_mese_casa

2022-01-18 18:06:36 ERROR (MainThread) [homeassistant.components.utility_meter.sensor] Could not restore state <unknown>. Resetting utility_meter.energia_anno_casa

2022-01-18 18:07:10 DEBUG (MainThread) [homeassistant.components.utility_meter.sensor] <energia_oggi_casa> collecting None from sensor.w_kwh_casa

2022-01-18 18:07:10 DEBUG (MainThread) [homeassistant.components.utility_meter.sensor] <energia_mese_casa> collecting None from sensor.w_kwh_casa

2022-01-18 18:07:10 DEBUG (MainThread) [homeassistant.components.utility_meter.sensor] <energia_anno_casa> collecting None from sensor.w_kwh_casa

2022-01-18 18:07:10 DEBUG (MainThread) [homeassistant.components.utility_meter.sensor] <consumo_giornaliero f1> tracks utility meter utility_meter.consumo_giornaliero

2022-01-18 18:07:10 DEBUG (MainThread) [homeassistant.components.utility_meter.sensor] consumo_giornaliero f1 - collecting - source <sensor.shelly_shem_b9e6f0_1_total_consumption_attr>

2022-01-18 18:07:10 DEBUG (MainThread) [homeassistant.components.utility_meter.sensor] <consumo_giornaliero f2> tracks utility meter utility_meter.consumo_giornaliero

2022-01-18 18:07:10 DEBUG (MainThread) [homeassistant.components.utility_meter.sensor] consumo_giornaliero f2 - paused - source <sensor.shelly_shem_b9e6f0_1_total_consumption_attr>

2022-01-18 18:07:10 DEBUG (MainThread) [homeassistant.components.utility_meter.sensor] <consumo_mensile f1> tracks utility meter utility_meter.consumo_mensile

2022-01-18 18:07:10 DEBUG (MainThread) [homeassistant.components.utility_meter.sensor] consumo_mensile f1 - collecting - source <sensor.shelly_shem_b9e6f0_1_total_consumption_attr>

2022-01-18 18:07:10 DEBUG (MainThread) [homeassistant.components.utility_meter.sensor] <consumo_mensile f2> tracks utility meter utility_meter.consumo_mensile

2022-01-18 18:07:10 DEBUG (MainThread) [homeassistant.components.utility_meter.sensor] consumo_mensile f2 - paused - source <sensor.shelly_shem_b9e6f0_1_total_consumption_attr>

what means? what I have to do?

Hi Guys I’ve installed the Shelly Em and now have 3 main sensors reporting
sensor.energy_monitor_channel_1_energy
sensor.energy_monitor_channel_1_power
sensor.energy_monitor_channel_1_voltage
I’ve set up the utility meter integration and have the relevant 6 sensors

utility_meter:
  daily_energy:
    source: sensor.energy_monitor_channel_1_power
    cycle: daily
    tariffs:
      - peak
      - offpeak
  weekly_energy:
    source: sensor.energy_monitor_channel_1_power
    cycle: weekly
    tariffs:
      - peak
      - offpeak
  monthly_energy:
    source: sensor.energy_monitor_channel_1_power
    cycle: monthly
    tariffs:
      - peak
      - offpeak

i am now wanting a sensor/card to display the daily, weekly, & monthly costs so i found this a while back and have edited it to my electricity rates but i’m obviously wrong as the numbers are crazy.
My elec rates are
23.25p per kWh peak
12.78p per kWh offpeak
and i have a daily standing charge of 24.47p
How do i add that in the code below?
Thanls

- platform: template
    daily_energy:
      friendly_name: Daily Energy
      unit_of_measurement: kWh
      value_template: "{{ states('sensor.daily_energy')|float }}"
    weekly_energy:
      friendly_name: Weekly Energy
      unit_of_measurement: kWh
      value_template: "{{ states('sensor.weekly_energy')|float }}"
    monthly_energy:
      friendly_name: Monthly Energy
      unit_of_measurement: kWh
      value_template: "{{ states('sensor.montly_energy')|float }}"
    energy_cost_today:
      friendly_name: "Energy Cost Today"
      unit_of_measurement: '£'
      icon_template: mdi:currency-gbp
      value_template: "{{ (((states('sensor.daily_energy_peak') | float * 0.2325) + (states('sensor.daily_energy_offpeak') | float) * 0.1278 ) + 0.2447) | round(2) }}"
    energy_cost_this_week:
      friendly_name: "Energy Cost This Week"
      unit_of_measurement: '£'
      icon_template: mdi:currency-gbp
      value_template: "{{ ((states('sensor.weekly_energy_peak') | float * 0.2325) + (states('sensor.weekly_energy_offpeak') | float) * 0.1278 ) | round(2) }}" 
    energy_cost_this_month:
      friendly_name: "Energy Cost This Month"
      unit_of_measurement: '£'
      icon_template: mdi:currency-gbp
      value_template: "{{ ((states('sensor.monthly_energy_peak') | float * 0.2325) + (states('sensor.monthly_energy_offpeak') | float) * 0.1278 ) | round(2) }}"
1 Like

You are feeding the utility meters with power sensors. This is incorrect. You need to use the energy total sensor.

Thanks i’ve swapped it.
With the costs is this the correct way to calculate my tarrif charges
value_template: "{{ (((states('sensor.daily_energy_peak') | float * 0.2325) + (states('sensor.daily_energy_offpeak') | float) * 0.1278 ) + 0.2447) | round(2) }}"

1 Like

Hi. I monitor 3-phase home power grid with Shelly 3EM. But I see 3 sensors - one per phase. How to combine those three into one that I can use for the built-in HA energy monitoring and also my own custom dashboards?

There is something weird with the energy reading of my Shelly EM via MQTT.

For example, If I look at the power reading:

It is correct as I know more or less the power consumption of the machine I’m using.

However, the reading I get on the Home Assitant Energy Meter, for the same period of time, using /emeter/0/energy as source, is 14.900 which is supposed to be the reading in Watt-Minute.
If I translate it to kWh that would be 0,25 which doesn’t make sense considering that the power draw is on average 1.600 Watts over the hour as seen from the graph, which should be around 1,6 kWh.

Am I missing something?

Yes. That’s the wrong sensor. There’s one called “total”. It’s measured in kWh, not Wm.