Setting up Power and Energy Monitoring with a Shelly EM and Home Assistant
In this guide I’ll demonstrate how to use the very useful Shelly EM as a power and energy monitoring input into your Smart Home. The Shelly EM is one of Allterco’s solutions for power monitoring, and allows the monitoring of two channels/circuits via Current Transformer (CT) clamps. We’ll cover the installation, configuration and the set up of sensors in Home Assistant.
Getting Started
First set up your Shelly EM to monitor the circuit that you’re keen on measuring; I’m going to use my main incoming supply line. Don’t hesitate to check Allterco’s Wiring Diagrams for the Shelly EM, located here. There are multiple ways in how you could place your Shelly EM, here is how I’ve set-up mine:

Note that the Shelly EM requires its own 230V reference supply to operate. If you’re not confident in wiring up a system, choose a simpler and safer method; or get help from a professional
Next, we have to define an MQTT sensor to get the power of the primary channel in Watts. The key part is to articulate the state_topic
correctly, and remember that the first circuit’s ID is 0
(and the second circuit’s ID is 1
). Here you can also set the QOS— which is recommended to be 2 in this situation — as well as defining the unit_of_measurement
, which is Watts for the Shelly EM. Here is what it looks like in YAML:
Making It Work
We already have created a Power sensor in Home Assistant, which is a positive step forward. Next, we’re going to level up and pull in Energy (watt-hours
) into a Utility Meter, so we can track today’s energy versus yesterday’s.
Utility Meters are powerful ways to accumulate readings (like Wh/kWh) over a period — either hourly, daily, weekly, monthly, quarterly and yearly. For our case, we’re going to be using daily
. Utility Meters have an added benefit built-in, where they keep track of the total value from the last period
, which in this situation would be the prior day.

Note that with the Shelly you have an option of getting
total
orenergy
data.total
records energy in Wh, and is accumulated in device’s non-volatile memory. Whilstenergy
andreturned_energy
do not survive a power cycle or reboot (i.e. stored in volatile memory)
To make this work, first define the Energy sensor in YAML, then create the Utility Meter in your configuration.yaml file. Finally, we can create a Template sensor to track yesterday’s energy, by extracting it’s value from the Utility Meter’s last period
value. Here is how it looks in YAML: