---
title: "Shelly 3EM MQTT"
description: "Potenza, tensione, corrente, fattore di potenza ed energia bidirezionale per fase più controllo contattore via MQTT. Template TapHome per Shelly 3EM Gen1."
url: "https://taphome.com/it/compatibility/shelly-3em-gen1-mqtt/"
language: it
lastmod: 2026-10-08
generator: hugo
ai:
  topics: ["mqtt","electric-meter","3-phase","wifi","energy-metering","bidirectional-metering","mdns"]
  questions: ["Come integrare Shelly 3EM con TapHome via MQTT?","Cosa misura il template Shelly 3EM MQTT TapHome per ogni fase?","Come trovare il Device ID di Shelly 3EM per il template MQTT?","Perché il prefisso del topic MQTT di Shelly 3EM è shellyem3- invece di shelly3em-?","Il template Shelly 3EM MQTT supporta la misura bidirezionale per il fotovoltaico?","Come azzerare i contatori di energia per fase su Shelly 3EM da TapHome?"]
---

# Shelly 3EM MQTT

Comunicazione: Packet Parser → MQTT

- [Pagina prodotto Shelly 3EM](https://www.shelly.com/en/products/shop/shelly-3em)

> Indirizzo di rete
> 
> Con il broker MQTT integrato in TapHome, inserisci `127.0.0.1` come indirizzo del broker in TapHome. Nel dispositivo inserisci l’indirizzo IP del TapHome Core e assegna al Core una prenotazione IP nel router.
> 
> [Preparazione della rete](https://taphome.com/it/docs/setup/network-preparation/)

## Guida all'integrazione

Lo Shelly 3EM è un contatore di energia trifase Wi-Fi della prima generazione di dispositivi Shelly (Gen1). Misura potenza attiva, tensione, corrente, fattore di potenza ed energia totale in modo indipendente per ciascuna delle tre fasi tramite tre TA apribili da 120 A inclusi e dispone di un relè integrato da 10 A, tipicamente usato per pilotare la bobina di un contattore di potenza esterno. TapHome comunica con il dispositivo via MQTT — il dispositivo invia le misure per fase a un broker, il modulo TapHome PacketParser si iscrive al ramo dei topic `shellies/#` e instrada i valori a quattro dispositivi figli (3 contatori elettrici + 1 interruttore contattore).

Questa è la **variante MQTT** del template Shelly 3EM. È disponibile anche una variante HTTP — scegli MQTT se hai già un broker MQTT locale, vuoi aggiornamenti push invece del polling, oppure devi condividere il contatore con più consumatori (TapHome più un altro sistema). Abilitare MQTT sul firmware Gen1 **disabilita Shelly Cloud** — i due servizi non possono funzionare contemporaneamente.

## Configurazione

### Abilitare MQTT nello Shelly 3EM

Apri l'interfaccia web dello Shelly 3EM (`http://{device-ip}` o `http://shelly3em-{MAC}.local`) e configura il client MQTT:

1. Vai su **Internet & Security** → **Advanced - Developer Settings**
2. Seleziona **Enable action execution via MQTT**
3. Compila **Server** con `{indirizzo IP del broker MQTT}:{port}` — tipicamente `192.168.1.10:1883`
4. (Opzionale) Imposta **Username** e **Password** se il broker richiede autenticazione
5. Clicca **SAVE** — il dispositivo si riavvia e si connette al broker

> [!WARNING]
> I dispositivi Shelly Gen1 **non supportano** MQTT su TLS. La comunicazione tra dispositivo e broker è in plain TCP non cifrato sulla porta 1883. Username e password vengono inviati in chiaro. Usa il broker MQTT solo su una rete locale fidata.

> [!NOTE]
> Abilitare MQTT **disabilita automaticamente Shelly Cloud** sul firmware Gen1. Per ripristinare, deseleziona MQTT e riabilita Cloud in Internet & Security.

### Trovare il Device ID

Il template TapHome si iscrive a `shellies/shellyem3-{dID}/#`, dove `{dID}` è il suffisso MAC del dispositivo usato come prefisso del topic MQTT.

Per trovarlo nell'interfaccia web di Shelly 3EM:

1. Apri l'interfaccia web del dispositivo nel browser
2. Vai su **Settings** → **Device Info**
3. Copia la **prima stringa Device ID** (NON il valore tra parentesi) — corrisponde all'indirizzo MAC dell'interfaccia WiFi (es. `DC4F227649A1`)

In alternativa, chiama `GET http://{device-ip}/settings` e leggi il campo `mqtt.id`.

### Configurazione del template

Dopo aver importato il template in TapHome, imposta i tre parametri di import:

| Parametro | Descrizione | Esempio |
|-----------|-------------|---------|
| **IpAddress** | Indirizzo IP del broker MQTT | `192.168.1.10` |
| **Port** | Porta del broker MQTT | `1883` |
| **dID** | Device ID (suffisso MAC) dello Shelly 3EM | `DC4F227649A1` |

Il modulo si iscrive quindi a `shellies/#` (QoS 0) e gli script listener instradano i messaggi emeter e relay per fase ai corrispondenti dispositivi figli. Il periodo di aggiornamento MQTT predefinito del dispositivo è 30 secondi — può essere ridotto tramite `GET http://{device-ip}/settings?mqtt_update_period=N` (valore `0` per pubblicare solo al cambio di stato).

> [!NOTE]
> Il prefisso del topic MQTT in linea è `shellyem3-{MAC}`, mentre il nome host mDNS del dispositivo è `shelly3em-{MAC}.local` — Shelly usa due forme diverse per lo stesso dispositivo. Il template segue l'effettivo prefisso del topic MQTT (`shellyem3-`). Se i messaggi MQTT non arrivano, iscriviti a `shellies/#` con un client MQTT per verificare quale prefisso il firmware sta effettivamente usando.

## Funzionalità del dispositivo

### Potenza attiva ed energia totale per fase

Il template crea tre dispositivi contatore elettrico — uno per ogni fase (TA 1 → fase A, TA 2 → fase B, TA 3 → fase C). Ogni contatore legge due valori:

- **Potenza attiva** — potenza istantanea da `shellies/shellyem3-{dID}/emeter/{i}/power` (W), divisa per 1000 e memorizzata come kW
- **Energia totale consumata** — energia cumulativa per l'intero ciclo di vita da `.../emeter/{i}/total` (Wh), divisa per 1000 e memorizzata come kWh

Ogni TA è dimensionato per **120 A** ed è non invasivo (clip-on, senza tagliare il cavo). I 3 TA inclusi sono singolarmente marcati e calibrati — NON sono intercambiabili tra i canali.

### Parametri elettrici per fase

Ogni contatore espone quattro service attribute per il monitoraggio avanzato:

- **Tensione** (V) — tensione RMS fase-neutro sulla fase corrispondente (`.../emeter/{i}/voltage`)
- **Corrente** (A) — corrente RMS misurata dal TA corrispondente (`.../emeter/{i}/current`)
- **Fattore di potenza** — rapporto tra potenza attiva e apparente, intervallo da −1.00 a 1.00 (`.../emeter/{i}/pf`)
- **Energia restituita** (Wh) — energia totale restituita **alla** rete sulla fase corrispondente (`.../emeter/{i}/total_returned`), utile per misure PV / bidirezionali

La combinazione di `total` (consumata) e `total_returned` (esportata) per fase rende il template adatto a installazioni solari / con immissione in rete.

### Reset dei contatori di energia

Ogni fase dispone di un service action **Reset Total** che pubblica `reset_totals` su `shellies/shellyem3-{dID}/emeter/{i}/command`. Questo azzera i contatori `total` e `total_returned` per la fase specifica — utile quando si riassegna l'uso del contatore o si avvia un nuovo periodo di misura.

### Relè contattore

Il relè da 10 A integrato è esposto come dispositivo interruttore. Lo stato è letto da `shellies/shellyem3-{dID}/relay/0` (`on` → 1, qualsiasi altro valore → 0) e si controlla pubblicando `on` o `off` su `.../relay/0/command`. Il relè è dimensionato per 10 A / 240 V AC e tipicamente viene cablato tramite i morsetti `I` (ingresso fase) e `O` (uscita relè) per pilotare la bobina di un contattore di potenza esterno per la commutazione di carichi più elevati.

> [!TIP]
> Il template MQTT non pubblica una somma trifase della potenza (`total_power` è disponibile solo via HTTP su Gen1). Crea un dispositivo virtuale TapHome che sommi i tre valori di potenza per fase se ti serve un singolo valore di potenza domestica.

## Risoluzione dei problemi

### Nessun messaggio MQTT ricevuto

1. Conferma che MQTT è abilitato nell'interfaccia web di Shelly (**Internet & Security** → **Advanced - Developer Settings** → **Enable action execution via MQTT**) e che il dispositivo si è riavviato dopo il salvataggio
2. Verifica che IP e porta del broker nel dispositivo corrispondano ai parametri di import `IpAddress`/`Port` in TapHome
3. Iscriviti a `shellies/#` con un client MQTT (es. MQTT Explorer, `mosquitto_sub`) e controlla se il dispositivo pubblica qualcosa — verifica che il prefisso del topic effettivo (`shellyem3-{dID}`) corrisponda al `dID` inserito in TapHome
4. Assicurati che il broker MQTT sia in esecuzione e raggiungibile sia dallo Shelly 3EM sia dal TapHome Core
5. Se l'IP del dispositivo è cambiato di recente, prova a connetterti tramite il nome host mDNS `shelly3em-{MAC}.local` per verificare la raggiungibilità in rete

### I valori di energia sono zero o non plausibili

1. Conferma che ogni TA è collegato all'ingresso **corretto** — il TA marcato `IA` deve essere cablato ai morsetti `IA-/IA+`, `IB` a `IB-/IB+`, `IC` a `IC-/IC+`. I TA sono calibrati per canale e non sono intercambiabili.
2. Verifica che la **freccia sul corpo del TA** indichi il verso del flusso di corrente (dalla sorgente al carico). Un TA invertito produce un fattore di potenza negativo e inverte la classificazione consumo / restituzione.
3. Controlla che gli ingressi di tensione `VA`, `VB`, `VC` siano collegati alle stesse fasi misurate dai TA — un abbinamento errato tensione / corrente produce valori di potenza e fattore di potenza scorretti.
4. Se una sola fase legge zero mentre le altre sono corrette, scambia quel TA con uno noto funzionante per isolare il problema tra TA e circuito.

### Impossibile abilitare MQTT — Cloud è in uso

Sul firmware Gen1, MQTT e Shelly Cloud sono mutuamente esclusivi. Se la casella **Enable action execution via MQTT** appare disabilitata, disattiva prima Shelly Cloud in **Internet & Security** → **Cloud**, poi riapri le impostazioni MQTT.

### Lo storico Shelly Cloud è scomparso dopo aver abilitato MQTT

È un comportamento atteso — abilitare MQTT disabilita Cloud, inclusa la sua conservazione storica di 365 giorni. Se hai bisogno sia del controllo MQTT in tempo reale in TapHome sia dello storico a lungo termine, instrada i messaggi MQTT attraverso il tuo broker e mantieni i dati storici in TapHome (o in un sistema di logging separato).

> [!WARNING]
> Ogni TA deve essere sempre collegato ai morsetti dello Shelly 3EM **prima** di essere agganciato attorno a un conduttore in tensione. La tensione indotta su un avvolgimento secondario aperto del TA può raggiungere livelli pericolosi e danneggiare il TA.

## Come installare in TapHome

### Prerequisiti

- Dispositivo Shelly connesso al Wi-Fi (2,4 GHz), ad es. tramite l'app Shelly o l'access point del dispositivo stesso
- Broker MQTT attivo sulla rete locale (es. Mosquitto, Home Assistant o il broker integrato di TapHome)
- TapHome CCU sulla stessa rete del broker

> [!WARNING]
> Sui dispositivi **Gen1**, l'attivazione di MQTT **disabilita Shelly Cloud**. Entrambi non possono funzionare contemporaneamente. Sui dispositivi Gen2/Plus questa limitazione non si applica.

### Passaggio 1 — Abilitare MQTT sul dispositivo Shelly

#### Dispositivi Gen1 (Shelly 1, 1PM, 2.5, EM, 3EM, Plug S, RGBW2, Dimmer, TRV…)

1. Apri l'interfaccia web Shelly: `http://<device-ip>/`
2. Vai su **Internet & Security** → **Advanced — MQTT**
3. Abilita **MQTT**
4. Imposta **MQTT Server**: `<broker-ip>:<port>` (es. `192.168.1.10:1883`)
5. Opzionalmente imposta **MQTT User** e **MQTT Password** se il broker richiede l'autenticazione
6. Clicca su **Save** — il dispositivo si riavvierà e si connetterà al broker

#### Dispositivi Gen2 / Plus (Shelly Plus 1, Plus 1PM, Plus 2PM, Plus Plug S, Plus H&T, Pro 3EM…)

1. Apri l'interfaccia web Shelly: `http://<device-ip>/`
2. Vai su **Settings** → **MQTT**
3. Abilita **MQTT**
4. Imposta **Server**: `<broker-ip>:<port>` (es. `192.168.1.10:1883`)
5. Il **Client ID** è precompilato con l'ID del dispositivo (es. `shellyplus1pm-AABBCCDDEE`) — lascialo così a meno che tu non abbia un motivo specifico per cambiarlo
6. Clicca su **Save** e riavvia il dispositivo

Con il broker integrato di TapHome, `<broker-ip>` è l'indirizzo IP del TapHome Core. Assegna al Core una prenotazione IP nel router, altrimenti il dispositivo perde il broker quando il router cambia l'indirizzo → [Preparazione della rete](https://taphome.com/it/docs/setup/network-preparation/).

> [!TIP]
> Per verificare che MQTT funzioni, usa un client MQTT (es. MQTT Explorer) e sottoscrivi `shellies/#` (Gen1) o `<device-id>/#` (Gen2). Dovresti vedere i messaggi di stato dal dispositivo.

### Passaggio 2 — Trovare il Device ID / MQTT Client ID

Alcuni template richiedono un parametro **Device ID** o **MQTT Client ID**. Questo è l'identificatore univoco utilizzato nei topic MQTT.

- **Gen1:** si trova sull'etichetta come indirizzo MAC (es. `AABBCCDDEE`). Device ID = `shelly<model>-<mac>`, es. `shelly1pm-AABBCCDDEE`
- **Gen2/Plus:** si trova nell'interfaccia web Shelly sotto **Settings** → **Device Info** → **Device ID**, oppure sull'etichetta del dispositivo

### Passaggio 3 — Configurazione in TapHome

1. In TapHome, aggiungi un nuovo modulo **Packet Parser (MQTT)**
2. **IP Address:** `127.0.0.1` per il broker integrato di TapHome (l'unità di controllo si connette a sé stessa, l'indirizzo non cambia mai); per un broker esterno il suo indirizzo IP (es. `192.168.1.10`)
3. **Port:** `1883` (predefinito; usa `8883` per TLS)
4. **Device ID / MQTT Client ID:** inserisci il valore dal passaggio 2 (se richiesto dal template)
5. Importa il template — TapHome si sottoscriverà automaticamente ai topic del dispositivo

## Dispositivi disponibili 4

Questi dispositivi compaiono in TapHome dopo l'importazione.

Shelly 3EM MQTT Modulo

Variabili personalizzate

`dID` (string) Suffisso MAC dello Shelly 3EM che forma il prefisso del topic MQTT shellies/shellyem3-{dID}/... — si trova nell'interfaccia web di Shelly → Settings → Device Info (prima stringa, NON il valore tra parentesi)

Open Shelly 3EM web UI → Settings → Device Info → copy the first Device ID string (NOT the value in brackets); equals the WiFi MAC address (e.g. DC4F227649A1)

Contatore elettrico (Fase 1) Contatore elettrico Solo lettura

Potenza attiva (kW) ed energia totale (kWh) sulla fase A — letta dal TA 1, con conversione W→kW e Wh→kWh

numeric Unità: kW / kWh

Attributi di servizio

|                    |                                                                                                       |
|--------------------|-------------------------------------------------------------------------------------------------------|
| Energia restituita | Energia totale restituita alla rete sulla fase A (Wh) — utile per PV / misure bidirezionali           |
| Tensione           | Tensione RMS fase-neutro sulla fase A (V)                                                             |
| Corrente           | Corrente RMS misurata dal TA 1 (A)                                                                    |
| Fattore di potenza | Fattore di potenza sulla fase A — rapporto tra potenza attiva e apparente, intervallo da −1.00 a 1.00 |

Azioni di servizio

|               |                                                                                |
|---------------|--------------------------------------------------------------------------------|
| Azzera totali | Azzera entrambi i contatori total e total\_returned dell'energia per la fase A |

Lettura consumo totale

```taphome
# Simple HTTP Request:
# VAR response := SENDHTTPREQUEST("/example/getValue");
# IF response.IsSuccess
#  VAR content := response.Content;
#  VAR responseHeaders := response.Headers;
#  RETURN(PARSEXML(content, "//element1/value1"));
# ELSE
#  ADDERROR(response.StatusCode + " (" + response.ReasonPhrase + ")");
#  RETURN(NaN);
# END
#
# Set Http request method, body and headers
# VAR response := SENDHTTPREQUEST("/example/getValue", "GET", "some data", "header1:value1", "header2:value2", ...);
# OR
# VAR request := HTTPREQUEST("/example/getValue", "POST", "some data");
# request.headers := { "header1:value1", "header2:value2", ...};
# request.method := "GET";
# request.data := null;
# VAR response := SENDHTTPREQUEST(request);
#
#
# Send TCP, UDP data:
# VAR data1 := BYTECOLLECTION("0a bb ea df 01");
# SENDDATA(data1);
# VAR data2 := "{\"name\":\"John\", \"age\":32}";
# SENDDATA(data2);
# VAR data3 := TOBYTES("{\"name\":\"John\", \"age\":32}", "iso-8859-1");
# SENDDATA(data3);
# Process received TCP or UDP data and set device values in the Listener script
#
#
# Download data from FTP:
# FTPDOWNLOAD("filePath");
```

Lettura domanda

```taphome
# Simple HTTP Request:
# VAR response := SENDHTTPREQUEST("/example/getValue");
# IF response.IsSuccess
#  VAR content := response.Content;
#  VAR responseHeaders := response.Headers;
#  RETURN(PARSEXML(content, "//element1/value1"));
# ELSE
#  ADDERROR(response.StatusCode + " (" + response.ReasonPhrase + ")");
#  RETURN(NaN);
# END
#
# Set Http request method, body and headers
# VAR response := SENDHTTPREQUEST("/example/getValue", "GET", "some data", "header1:value1", "header2:value2", ...);
# OR
# VAR request := HTTPREQUEST("/example/getValue", "POST", "some data");
# request.headers := { "header1:value1", "header2:value2", ...};
# request.method := "GET";
# request.data := null;
# VAR response := SENDHTTPREQUEST(request);
#
#
# Send TCP, UDP data:
# VAR data1 := BYTECOLLECTION("0a bb ea df 01");
# SENDDATA(data1);
# VAR data2 := "{\"name\":\"John\", \"age\":32}";
# SENDDATA(data2);
# VAR data3 := TOBYTES("{\"name\":\"John\", \"age\":32}", "iso-8859-1");
# SENDDATA(data3);
# Process received TCP or UDP data and set device values in the Listener script
#
#
# Download data from FTP:
# FTPDOWNLOAD("filePath");
```

Listener

```taphome
IF(RECEIVEDMSG.TOPIC = "shellies/shellyem3-"+dID+"/emeter/0/power")
 Ed := todouble(TOSTRING(RECEIVEDMSG.PAYLOAD))/1000;
elseif(RECEIVEDMSG.TOPIC = "shellies/shellyem3-"+dID+"/emeter/0/total")
 To := todouble(TOSTRING(RECEIVEDMSG.PAYLOAD))/1000;
END
```

Attributi di servizio

returned energy \[Wh]

```taphome
IF(parsejson(x, "Topic") = "shellies/shellyem3-"+dID+"/emeter/0/total_returned")
 return(parsejson(x, "Payload"));
END
```

voltage \[V]

```taphome
IF(parsejson(x, "Topic") = "shellies/shellyem3-"+dID+"/emeter/0/voltage")
 return(todouble(parsejson(x, "Payload")));
END
```

current \[A]

```taphome
IF(parsejson(x, "Topic") = "shellies/shellyem3-"+dID+"/emeter/0/current")
 return(todouble(parsejson(x, "Payload")));
END
```

power factor

```taphome
IF(parsejson(x, "Topic") = "shellies/shellyem3-"+dID+"/emeter/0/pf")
 return(todouble(parsejson(x, "Payload")));
END
```

Azioni di servizio

Reset total

```taphome
mqttpublish("shellies/shellyem3-"+dID+"/emeter/0/command", "reset_totals");
```

Contatore elettrico (Fase 2) Contatore elettrico Solo lettura

Potenza attiva (kW) ed energia totale (kWh) sulla fase B — letta dal TA 2, con conversione W→kW e Wh→kWh

numeric Unità: kW / kWh

Attributi di servizio

|                    |                                                                                                       |
|--------------------|-------------------------------------------------------------------------------------------------------|
| Energia restituita | Energia totale restituita alla rete sulla fase B (Wh) — utile per PV / misure bidirezionali           |
| Tensione           | Tensione RMS fase-neutro sulla fase B (V)                                                             |
| Corrente           | Corrente RMS misurata dal TA 2 (A)                                                                    |
| Fattore di potenza | Fattore di potenza sulla fase B — rapporto tra potenza attiva e apparente, intervallo da −1.00 a 1.00 |

Azioni di servizio

|               |                                                                                |
|---------------|--------------------------------------------------------------------------------|
| Azzera totali | Azzera entrambi i contatori total e total\_returned dell'energia per la fase B |

Lettura consumo totale

```taphome
# Simple HTTP Request:
# VAR response := SENDHTTPREQUEST("/example/getValue");
# IF response.IsSuccess
#  VAR content := response.Content;
#  VAR responseHeaders := response.Headers;
#  RETURN(PARSEXML(content, "//element1/value1"));
# ELSE
#  ADDERROR(response.StatusCode + " (" + response.ReasonPhrase + ")");
#  RETURN(NaN);
# END
#
# Set Http request method, body and headers
# VAR response := SENDHTTPREQUEST("/example/getValue", "GET", "some data", "header1:value1", "header2:value2", ...);
# OR
# VAR request := HTTPREQUEST("/example/getValue", "POST", "some data");
# request.headers := { "header1:value1", "header2:value2", ...};
# request.method := "GET";
# request.data := null;
# VAR response := SENDHTTPREQUEST(request);
#
#
# Send TCP, UDP data:
# VAR data1 := BYTECOLLECTION("0a bb ea df 01");
# SENDDATA(data1);
# VAR data2 := "{\"name\":\"John\", \"age\":32}";
# SENDDATA(data2);
# VAR data3 := TOBYTES("{\"name\":\"John\", \"age\":32}", "iso-8859-1");
# SENDDATA(data3);
# Process received TCP or UDP data and set device values in the Listener script
#
#
# Download data from FTP:
# FTPDOWNLOAD("filePath");
```

Lettura domanda

```taphome
# Simple HTTP Request:
# VAR response := SENDHTTPREQUEST("/example/getValue");
# IF response.IsSuccess
#  VAR content := response.Content;
#  VAR responseHeaders := response.Headers;
#  RETURN(PARSEXML(content, "//element1/value1"));
# ELSE
#  ADDERROR(response.StatusCode + " (" + response.ReasonPhrase + ")");
#  RETURN(NaN);
# END
#
# Set Http request method, body and headers
# VAR response := SENDHTTPREQUEST("/example/getValue", "GET", "some data", "header1:value1", "header2:value2", ...);
# OR
# VAR request := HTTPREQUEST("/example/getValue", "POST", "some data");
# request.headers := { "header1:value1", "header2:value2", ...};
# request.method := "GET";
# request.data := null;
# VAR response := SENDHTTPREQUEST(request);
#
#
# Send TCP, UDP data:
# VAR data1 := BYTECOLLECTION("0a bb ea df 01");
# SENDDATA(data1);
# VAR data2 := "{\"name\":\"John\", \"age\":32}";
# SENDDATA(data2);
# VAR data3 := TOBYTES("{\"name\":\"John\", \"age\":32}", "iso-8859-1");
# SENDDATA(data3);
# Process received TCP or UDP data and set device values in the Listener script
#
#
# Download data from FTP:
# FTPDOWNLOAD("filePath");
```

Listener

```taphome
IF(RECEIVEDMSG.TOPIC = "shellies/shellyem3-"+dID+"/emeter/1/power")
 Ed := todouble(TOSTRING(RECEIVEDMSG.PAYLOAD))/1000;
 elseif(RECEIVEDMSG.TOPIC = "shellies/shellyem3-"+dID+"/emeter/1/total")
 To := todouble(TOSTRING(RECEIVEDMSG.PAYLOAD))/1000;
END
```

Attributi di servizio

total returned \[Wh]

```taphome
IF(parsejson(x, "Topic") = "shellies/shellyem3-"+dID+"/emeter/1/total_returned")
 return(todouble(parsejson(x, "Payload")));
END
```

voltage \[V]

```taphome
IF(parsejson(x, "Topic") = "shellies/shellyem3-"+dID+"/emeter/1/voltage")
 return(todouble(parsejson(x, "Payload")));
END
```

current \[A]

```taphome
IF(parsejson(x, "Topic") = "shellies/shellyem3-"+dID+"/emeter/1/current")
 return(todouble(parsejson(x, "Payload")));
END
```

power factor

```taphome
IF(parsejson(x, "Topic") = "shellies/shellyem3-"+dID+"/emeter/1/pf")
 return(todouble(parsejson(x, "Payload")));
END
```

Azioni di servizio

Reset total

```taphome
mqttpublish("shellies/shellyem3-"+dID+"/emeter/1/command", "reset_totals");
```

Contatore elettrico (Fase 3) Contatore elettrico Solo lettura

Potenza attiva (kW) ed energia totale (kWh) sulla fase C — letta dal TA 3, con conversione W→kW e Wh→kWh

numeric Unità: kW / kWh

Attributi di servizio

|                    |                                                                                                       |
|--------------------|-------------------------------------------------------------------------------------------------------|
| Energia restituita | Energia totale restituita alla rete sulla fase C (Wh) — utile per PV / misure bidirezionali           |
| Tensione           | Tensione RMS fase-neutro sulla fase C (V)                                                             |
| Corrente           | Corrente RMS misurata dal TA 3 (A)                                                                    |
| Fattore di potenza | Fattore di potenza sulla fase C — rapporto tra potenza attiva e apparente, intervallo da −1.00 a 1.00 |

Azioni di servizio

|               |                                                                                |
|---------------|--------------------------------------------------------------------------------|
| Azzera totali | Azzera entrambi i contatori total e total\_returned dell'energia per la fase C |

Lettura consumo totale

```taphome
# Simple HTTP Request:
# VAR response := SENDHTTPREQUEST("/example/getValue");
# IF response.IsSuccess
#  VAR content := response.Content;
#  VAR responseHeaders := response.Headers;
#  RETURN(PARSEXML(content, "//element1/value1"));
# ELSE
#  ADDERROR(response.StatusCode + " (" + response.ReasonPhrase + ")");
#  RETURN(NaN);
# END
#
# Set Http request method, body and headers
# VAR response := SENDHTTPREQUEST("/example/getValue", "GET", "some data", "header1:value1", "header2:value2", ...);
# OR
# VAR request := HTTPREQUEST("/example/getValue", "POST", "some data");
# request.headers := { "header1:value1", "header2:value2", ...};
# request.method := "GET";
# request.data := null;
# VAR response := SENDHTTPREQUEST(request);
#
#
# Send TCP, UDP data:
# VAR data1 := BYTECOLLECTION("0a bb ea df 01");
# SENDDATA(data1);
# VAR data2 := "{\"name\":\"John\", \"age\":32}";
# SENDDATA(data2);
# VAR data3 := TOBYTES("{\"name\":\"John\", \"age\":32}", "iso-8859-1");
# SENDDATA(data3);
# Process received TCP or UDP data and set device values in the Listener script
#
#
# Download data from FTP:
# FTPDOWNLOAD("filePath");
```

Lettura domanda

```taphome
# Simple HTTP Request:
# VAR response := SENDHTTPREQUEST("/example/getValue");
# IF response.IsSuccess
#  VAR content := response.Content;
#  VAR responseHeaders := response.Headers;
#  RETURN(PARSEXML(content, "//element1/value1"));
# ELSE
#  ADDERROR(response.StatusCode + " (" + response.ReasonPhrase + ")");
#  RETURN(NaN);
# END
#
# Set Http request method, body and headers
# VAR response := SENDHTTPREQUEST("/example/getValue", "GET", "some data", "header1:value1", "header2:value2", ...);
# OR
# VAR request := HTTPREQUEST("/example/getValue", "POST", "some data");
# request.headers := { "header1:value1", "header2:value2", ...};
# request.method := "GET";
# request.data := null;
# VAR response := SENDHTTPREQUEST(request);
#
#
# Send TCP, UDP data:
# VAR data1 := BYTECOLLECTION("0a bb ea df 01");
# SENDDATA(data1);
# VAR data2 := "{\"name\":\"John\", \"age\":32}";
# SENDDATA(data2);
# VAR data3 := TOBYTES("{\"name\":\"John\", \"age\":32}", "iso-8859-1");
# SENDDATA(data3);
# Process received TCP or UDP data and set device values in the Listener script
#
#
# Download data from FTP:
# FTPDOWNLOAD("filePath");
```

Listener

```taphome
IF(RECEIVEDMSG.TOPIC = "shellies/shellyem3-"+dID+"/emeter/2/power")
 Ed := todouble(TOSTRING(RECEIVEDMSG.PAYLOAD))/1000;
 elseif(RECEIVEDMSG.TOPIC = "shellies/shellyem3-"+dID+"/emeter/2/total")
 To := todouble(TOSTRING(RECEIVEDMSG.PAYLOAD))/1000;
END
```

Attributi di servizio

total returned \[Wh]

```taphome
IF(parsejson(x, "Topic") = "shellies/shellyem3-"+dID+"/emeter/2/total_returned")
 return(todouble(parsejson(x, "Payload")));
END
```

voltage \[V]

```taphome
IF(parsejson(x, "Topic") = "shellies/shellyem3-"+dID+"/emeter/2/voltage")
 return(todouble(parsejson(x, "Payload")));
END
```

current \[A]

```taphome
IF(parsejson(x, "Topic") = "shellies/shellyem3-"+dID+"/emeter/2/current")
 return(todouble(parsejson(x, "Payload")));
END
```

Power Factor

```taphome
IF(parsejson(x, "Topic") = "shellies/shellyem3-"+dID+"/emeter/2/pf")
 return(todouble(parsejson(x, "Payload")));
END
```

Azioni di servizio

reset total

```taphome
mqttpublish("shellies/shellyem3-"+dID+"/emeter/2/command", "reset_totals");
```

Relè contattore Interruttore Lettura e scrittura

Relè 10 A integrato — tipicamente cablato per pilotare la bobina di un contattore di potenza esterno tramite i morsetti I/O

boolean

Valori / Stati: ON · OFF

Lettura stato interruttore

```taphome
# Simple HTTP Request:
# VAR response := SENDHTTPREQUEST("/example/getValue");
# IF response.IsSuccess
#  VAR content := response.Content;
#  VAR responseHeaders := response.Headers;
#  RETURN(PARSEXML(content, "//element1/value1"));
# ELSE
#  ADDERROR(response.StatusCode + " (" + response.ReasonPhrase + ")");
#  RETURN(NaN);
# END
#
# Set Http request method, body and headers
# VAR response := SENDHTTPREQUEST("/example/getValue", "GET", "some data", "header1:value1", "header2:value2", ...);
# OR
# VAR request := HTTPREQUEST("/example/getValue", "POST", "some data");
# request.headers := { "header1:value1", "header2:value2", ...};
# request.method := "GET";
# request.data := null;
# VAR response := SENDHTTPREQUEST(request);
#
#
# Send TCP, UDP data:
# VAR data1 := BYTECOLLECTION("0a bb ea df 01");
# SENDDATA(data1);
# VAR data2 := "{\"name\":\"John\", \"age\":32}";
# SENDDATA(data2);
# VAR data3 := TOBYTES("{\"name\":\"John\", \"age\":32}", "iso-8859-1");
# SENDDATA(data3);
# Process received TCP or UDP data and set device values in the Listener script
#
#
# Download data from FTP:
# FTPDOWNLOAD("filePath");
```

Scrittura stato interruttore

```taphome
# Simple HTTP Request:
MQTTPUBLISH("shellies/shellyem3-"+dID+"/relay/0/command", switch(St,1,"on","off"));
# VAR response := SENDHTTPREQUEST("/example/set/value=" + St);
# IF response.IsSuccess = false
#  ADDERROR(response.StatusCode);
# END
#
# Set Http request method, body and headers
# VAR response := SENDHTTPREQUEST("/example/setValue", "GET", "value=" + St, "header1:value1", "header2:value2", ...);\r
# Or VAR request := HTTPREQUEST("/example/setValue");
# request.Method := "PUT";
# VAR response := SENDHTTPREQUEST(request);
#r
#
# Send TCP, UDP data:
# VAR data1 := "{\"name\":\"John\", \"age\":" + St + "}";
# SENDDATA(data1);
# VAR data2 := TOBYTES("{\"name\":\"John\", \"age\":" + St + "}", "iso-8859-1");
# SENDDATA(data2);
# You can process received TCP or UDP data in the Listener script
#
#
# Upload data to FTP:
# FTPUPLOAD("filePath", "somedata=" + St, "write"); # use "append" mode to append data to existing file
```

Listener

```taphome
# Parse received bytes:
IF(RECEIVEDMSG.TOPIC = "shellies/shellyem3-"+dID+"/relay/0")
 St := switch(TOSTRING(RECEIVEDMSG.PAYLOAD),"on",1,0);
END
```

**Connessione:** Packet Parser → MQTT • Hostname: `shelly3em-{MAC}.local`

Possibili miglioramenti (10)

- Reactive Power (per phase) — Instantaneous reactive power in VAR per phase — useful for power-quality diagnostics.
- Short-term Energy Counter — Watt-minute counter since boot (volatile). Template uses lifetime 'total' instead.
- Short-term Returned Energy — Watt-minute returned counter since boot (volatile).
- Contactor Coil Power — Power draw through the on-board relay (small — coil only).
- Contactor Coil Energy — Energy through the on-board relay (Wm).
- Connection Status (LWT) — Last-Will-and-Testament topic — true on connect, false retained on disconnect. Could detect offline 3EM.
- Device Announcement (JSON) — Periodic JSON announce containing id, mac, ip, fw\_ver, new\_fw, model.
- Full Status JSON — Complete /status payload as JSON — could expose Wi-Fi RSSI, internal temperature, all 4 emeter channels.
- 4th CT — Theft / Leakage Detection — Optional 4th split-core CT on IN+/IN- terminal for neutral leakage / energy-theft detection. NOT published over MQTT — only HTTP.
- Total Active Power — 3EM does not publish total\_power over MQTT (only HTTP). Sum the three phase Ed values in a TapHome virtual device.

## Parametri di importazione

Inserisci questi valori quando importi l'XML.

| Richiesto nell'app       | Predefinito                  |
|--------------------------|------------------------------|
| Mqtt Broker Indirizzo IP | `192.168.0.1`                |
| Mqtt Broker port         | `1883`                       |
| Device ID                | Da inserire all'importazione |

## Fonti

- Shelly Gen1 API Reference
  
  [shelly-api-docs.shelly.cloud](https://shelly-api-docs.shelly.cloud/gen1/) 2026-03-12
- Home Assistant Shelly Integration
  
  [www.home-assistant.io](https://www.home-assistant.io/integrations/shelly/) 2026-03-12
- Shelly 3EM MQTT API — device-specific topics
  
  [shelly-api-docs.shelly.cloud](https://shelly-api-docs.shelly.cloud/gen1/#shelly-3em-mqtt) 2026-04-25
- Shelly 3EM Knowledge Base — specs & wiring
  
  [kb.shelly.cloud](https://kb.shelly.cloud/knowledge-base/shelly-3em) 2026-04-25
- Shelly 3EM — User & Safety Guide
  
  [www.netxl.com](https://www.netxl.com/shelly/docs/shelly-3em-user-manual.pdf) 2026-04-25
  
  [PDF](https://taphome.com/compatibility/devices/shelly-3em-gen1-mqtt/manufacturer/shelly-3em-user-safety-guide.pdf)

I documenti del produttore sono © dei rispettivi proprietari. Sono forniti così come pubblicati dal produttore, solo a titolo informativo.

## Documentazione correlata

- [MQTT Integration](https://taphome.com/it/compatibility/mqtt-guide/)
- [Packet Parser (HTTP, TCP, UDP, FTP, MQTT)](https://taphome.com/it/docs/integration/packet-parser/)
- [Funzioni Packet parser](https://taphome.com/it/docs/script/packet-parser/)
- [Funzioni di parsing](https://taphome.com/it/docs/script/parsing-functions/)
- [Broker MQTT](https://taphome.com/it/docs/integration/packet-parser/mqtt-broker/)
- [Script listener](https://taphome.com/it/docs/script/listener-scripts/)

