Shelly EM publishing its consumption over MQTT to a Mosquitto broker and on to Home Assistant

How to integrate the Shelly EM into Home Assistant over MQTT

Here's a question we get a lot from people building their own energy view: «I've got a Shelly EM measuring the house and I want to see it in Home Assistant over MQTT, but I don't know where to start… and I've read that enabling it loses me the Shelly app». Both things are true, and both have a solution. This guide takes you end to end: when MQTT is worth it, how to enable it on the EM, exactly what it publishes, and how to create the sensors in Home Assistant so your consumption shows up correctly in the Energy Dashboard.

First things first: MQTT or the native integration?

Comparison of integrating the Shelly EM into Home Assistant with the native CoIoT integration (automatic, keeps the cloud) or with MQTT (needs a broker, manual sensors, disables the cloud)

There are two ways to bring a Shelly EM into Home Assistant, and it pays to choose with a clear head. The native integration (over CoIoT on Gen1 devices) is picked up by Home Assistant almost on its own: there's no YAML to write and, importantly, it keeps the Shelly app and cloud. It's the quick route for most people.

The MQTT route makes sense when you already run a broker at home (for example the Mosquitto add-on in Home Assistant), you want your whole smart home speaking MQTT, or you need a specific topic structure to share the reading with another system. In exchange, you define the sensors by hand and —on the EM Gen1— you give up the Shelly cloud. Since this is the option that raises the most questions, it's the one we develop here.

Enable MQTT on the Shelly EM (and what you lose)

Steps to enable MQTT on the Shelly EM Gen1: Internet & Security, Advanced Developer Settings, point to the Mosquitto broker with IP, username and password; warning that it disables the Shelly cloud

The process, from the device's own web UI, is short: go to the Shelly EM's IP in the browser, open Internet & Security > Advanced — Developer Settings and enable executing actions over MQTT. Enter your Mosquitto broker IP, the username and password, leave the port at 1883 and save. From then on the EM starts publishing, with the default prefix shellies/shellyem-<id>.

The important warning, which is why we say it before you build it: on the Shelly EM Gen1, enabling MQTT disables the Shelly cloud. It won't do both at once. That means you lose remote control from the Shelly app when you're away from home, and the history stored in Shelly Cloud. On your local network and inside Home Assistant everything keeps working normally. If you rely on the app remotely, think it through before taking the step; if your goal is precisely to centralise everything in Home Assistant, you won't miss it.

What the Shelly EM publishes over MQTT

MQTT topic tree of the Shelly EM under shellies/shellyem-id: emeter/0/power, voltage, reactive_power, total, energy and relay/0; note to use total and not energy for the energy dashboard

The EM publishes each reading on its own topic, under the prefix shellies/shellyem-<id>/, where <id> is the hexadecimal part of the device identifier. For channel 0 (channel 1 is identical, swapping /0/ for /1/):

  • emeter/0/power — active power in watts (W).
  • emeter/0/voltage — voltage in volts (V).
  • emeter/0/reactive_power — reactive power (VAR).
  • emeter/0/total — cumulative energy in Wh, survives reboots.
  • emeter/0/energy — energy since the last boot in W·min, resets when the device restarts.
  • relay/0 and relay/0/command — relay state and the command to switch it.

The EM also publishes returned energy (returned_energy) —because it measures both ways and tells what you consume from what you export to the grid— and a connection-status topic. Remember each clamp is a channel: emeter/0 and emeter/1 are the two lines you're measuring.

The detail that matters most: for a consumption counter use total, not energy. total is in Wh and survives reboots; just divide it by 1000 to get kWh. energy goes back to zero every time the device boots, so it's no use for keeping count.

Create the sensors in Home Assistant

Examples of an MQTT sensor in Home Assistant for the Shelly EM: one for instant power in W and one for cumulative energy in kWh with device_class energy and state_class total_increasing for the energy dashboard

With the broker receiving data, in Home Assistant you define two classes of sensor. The first, instant power in watts, to see live consumption; point it at the topic …/emeter/0/power with device_class: power and unit W. The second, cumulative energy in kWh, which is what feeds the Energy Dashboard; point it at the topic …/emeter/0/total, divide it by 1000 with a value_template, set unit kWh, device_class: energy and —the key— state_class: total_increasing.

That combination (device_class: energy + state_class: total_increasing on total) is what makes Home Assistant sum consumption by hour, day and month in the Energy Dashboard. Power in W is no use for that panel: it's only for the live reading and for automations. Repeat the block with /1/ if you also use the second clamp.

Common mistakes

  • Using energy in the Energy Dashboard. When the counter resets, the panel sees a drop to zero and gets thrown off. Always use total.
  • Forgetting state_class: total_increasing. Without it, Home Assistant won't offer the sensor in the Energy Dashboard.
  • Expecting to keep using the app remotely. On Gen1, MQTT and the cloud are mutually exclusive. Accept it before enabling it.
  • Confusing the units. power is in W; total in Wh (÷1000 → kWh); energy in W·min. Don't mix conversions.

Frequently asked questions

Do I lose the Shelly app when I enable MQTT?

On the Shelly EM Gen1, yes: MQTT and the Shelly cloud don't coexist. You lose remote control from the app and the history in Shelly Cloud, but on your local network and in Home Assistant everything keeps working.

Which topic do I use for Home Assistant's Energy Dashboard?

The total one (in Wh), divided by 1000 to get kWh, with device_class: energy and state_class: total_increasing. Don't use energy, which resets with every boot.

Do I need an MQTT broker?

Yes. The EM publishes, but something has to receive: a broker like Mosquitto (the official Home Assistant add-on works perfectly). The EM points at its IP, username and password, and Home Assistant subscribes.

Wasn't the native integration easier?

For most people, yes: Shelly's native integration in Home Assistant (over CoIoT on Gen1) detects it with no YAML and keeps the app. MQTT is the option for those who already run a broker or want control over the topic structure.

Does the Shelly EM measure solar surplus?

Yes. It measures both ways, so it tells what you consume from what you export to the grid, and it publishes returned energy (returned_energy). It's one of the reasons it's so widely used in installations with panels.

Where do I find the for the topics?

It's the hexadecimal part of the Shelly's identifier, visible in its web UI. The default prefix is shellies/shellyem-<id>; if you prefer, you can set your own prefix when you enable MQTT.

What if I have an EM Gen3 or a Plus/Pro device?

Those devices (Gen2 and later) speak MQTT with a different, RPC-based structure, not shellies/…. For them, Home Assistant's native integration (over RPC WebSocket) is even more direct; MQTT is still optional.

Summary and products

  • Shelly EM — the two-channel Wi-Fi meter with a 50 A clamp, the star of this guide. It measures both ways.
  • Shelly EM Gen3 — the current generation, if you're starting fresh: it adds Bluetooth, scripting and DIN rail, and speaks MQTT in the RPC structure.

If you like, we'll help you get the sensors and the Energy Dashboard working for your exact case —one clamp or two, with or without solar panels. Technical support in Spanish and English, and shipping from Spain.


Dejar un comentario

Por favor tenga en cuenta que los comentarios deben ser aprobados antes de ser publicados

Este sitio está protegido por hCaptcha y se aplican la Política de privacidad de hCaptcha y los Términos del servicio.