TapHome

Shelly EM MQTT

Packet Parser → MQTT
Inviato da
Ultimo aggiornamento: 06. 2026
Shelly EM MQTT

Lo Shelly EM è un contatore di energia monofase con due canali di misurazione indipendenti e un’uscita relè da 2A per il controllo del contattore. Ogni canale si collega a un trasformatore di corrente esterno (pinza CT) – disponibile nelle varianti 50A e 120A – consentendo il monitoraggio non invasivo di due circuiti separati contemporaneamente. Questo template si collega al dispositivo tramite un broker MQTT nella rete locale. Non è necessaria una connessione cloud.

Il template espone tre dispositivi: due contatori elettrici (uno per canale CT) che tracciano il consumo energetico cumulativo e un interruttore per il relè contattore.

Configurazione

Device ID

Lo Shelly EM utilizza un Device ID nel formato shellyem-XXXXXX, dove XXXXXX sono gli ultimi 6 caratteri dell’indirizzo MAC in formato esadecimale (es. shellyem-B929CC). Durante l’importazione del template, inserisci solo la parte esadecimale (es. B929CC) nel parametro Device ID.

Il Device ID si trova:

  • Nell’interfaccia web Shelly: Settings > Device Info
  • Tramite API: GET http://<device-ip>/settings – campo mqtt.id

Questo dispositivo supporta la scoperta mDNS. Puoi usare l’hostname shellyem-{MAC}.local invece dell’indirizzo IP quando configuri il broker MQTT. Sostituisci {MAC} con l’indirizzo MAC completo in formato esadecimale (es. shellyem-b929cc.local). L’uso dell’hostname previene problemi di connettività quando l’indirizzo IP del dispositivo cambia.

Configurazione MQTT

Prima di importare il template, abilita MQTT sullo Shelly EM:

  1. Apri l’interfaccia web Shelly su http://<device-ip>
  2. Vai su Internet & Security > Advanced — Developer Settings
  3. Spunta Enable action execution via MQTT
  4. Nel campo Server, inserisci l’indirizzo del broker MQTT nel formato broker-ip:1883
  5. Premi SAVE

Sui dispositivi Shelly Gen1, abilitare MQTT disabilita Shelly Cloud. Le due funzioni non possono funzionare contemporaneamente.

Configurazione template

Dopo l’importazione del template in TapHome:

  1. Imposta MQTT Broker IP sull’indirizzo del tuo broker MQTT
  2. Imposta MQTT Broker Port (predefinito 1883)
  3. Imposta Device ID sulla parte esadecimale del Device ID dello Shelly EM (es. B929CC)

Il modulo si iscrive a shellies/# e gli script listener su ogni dispositivo filtrano i messaggi in base al Device ID configurato.

Funzionalità del dispositivo

Misurazione energetica (per canale)

Ogni canale è esposto come dispositivo Contatore elettrico indipendente in TapHome. Lo script listener si iscrive a due topic MQTT per canale:

TopicUnitàDescrizione
emeter/{i}/energywatt-minutiEnergia cumulativa dall’ultimo riavvio – divisa per 60 000 per convertire in kWh
emeter/{i}/totalWhEnergia totale consumata persistente – sopravvive ai riavvii

Il template memorizza entrambi i valori: Ed (energia dal topic watt-minuti, convertita in kWh) e To (consumo totale in Wh dal topic persistente).

Il topic energy si azzera al riavvio del dispositivo. Per il tracciamento persistente dell’energia, il template legge anche il topic total che sopravvive ai riavvii.

Ogni canale espone anche un attributo di servizio Tensione, che legge la tensione di rete RMS dal topic MQTT emeter/{i}/voltage.

Gli script readtotalconsumption e readdemand sono boilerplate commentato del template – tutti i dati energetici arrivano tramite il listener MQTT. Ciò significa che il template non fornisce letture di potenza istantanea (W). Vengono tracciati solo l’energia cumulativa (kWh) e il consumo totale (Wh). La potenza attiva istantanea è disponibile tramite il topic MQTT emeter/{i}/power, ma questo template non vi si iscrive.

Relè contattore

L’uscita relè è esposta come interruttore in TapHome. Il relè è dimensionato per 2A / 230 VAC – è progettato solo per il controllo del contattore, non per la commutazione diretta del carico.

  • Lettura: si iscrive a shellies/shellyem-{id}/relay/0 – payload on corrisponde a acceso, off a spento
  • Scrittura: pubblica on o off su shellies/shellyem-{id}/relay/0/command

Il relè è dimensionato per soli 2A. Per carichi superiori a questo limite, usa sempre un contattore esterno. Il collegamento diretto di carichi ad alta potenza danneggia il relè.

Risoluzione dei problemi

Nessun dato energetico
  1. Verifica che MQTT sia abilitato nell’interfaccia web Shelly (Internet & Security > Advanced – MQTT)
  2. Controlla che l’indirizzo e la porta del broker MQTT siano corretti sia nelle impostazioni del dispositivo Shelly che del modulo TapHome
  3. Verifica che la variabile personalizzata Device ID corrisponda esattamente al Device ID dello Shelly (es. B929CC)
  4. Usando un client MQTT (es. MQTT Explorer), iscriviti a shellies/# e verifica che il dispositivo pubblichi i topic emeter/0/energy e emeter/1/energy
Dati da un solo canale
  1. Verifica che la pinza CT sia collegata al jack da 3,5 mm corretto (canale 0 o canale 1)
  2. Controlla che corrente scorra nel conduttore monitorato – la pinza CT deve circondare un singolo conduttore, non l’intero cavo
  3. Iscriviti separatamente ai topic shellies/shellyem-{id}/emeter/0/# e shellies/shellyem-{id}/emeter/1/# e verifica che entrambi i canali pubblichino dati
Il relè non risponde
  1. Controlla che lo Shelly EM sia alimentato e connesso al broker MQTT
  2. Pubblica manualmente on o off su shellies/shellyem-{id}/relay/0/command tramite un client MQTT per testare il funzionamento del relè indipendentemente da TapHome
  3. Verifica il cablaggio corretto dell’uscita relè (controlla le etichette dei morsetti sul dispositivo)

I dispositivi Shelly Gen1 non supportano MQTT su TLS. La comunicazione tra il dispositivo e il broker MQTT non è crittografata (plain MQTT, porta 1883). Assicurati che il broker MQTT sia su una rete locale affidabile.

Come installare in TapHome

Prerequisiti

  • Dispositivo Shelly connesso al Wi-Fi (vedi la guida alla connessione HTTP se non ancora fatto)
  • Broker MQTT attivo sulla rete locale (es. Mosquitto, Home Assistant o il broker integrato di TapHome)
  • TapHome CCU sulla stessa rete del broker

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 & SecurityAdvanced — 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 SettingsMQTT
  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

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 SettingsDevice InfoDevice ID, oppure sull’etichetta del dispositivo

Passaggio 3 — Configurazione in TapHome

  1. In TapHome, aggiungi un nuovo modulo Packet Parser (MQTT)
  2. IP Address: inserisci l’IP del broker MQTT (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

Shelly EM MQTT Modulo
Variabili personalizzate
deviceID (string)Device ID MQTT dello Shelly EM — formato 'shellyem-DEVICEID' dove DEVICEID sono gli ultimi 6 caratteri esadecimali dell'indirizzo MAC (es. B929CC)
Open http://shellyIpAddress → Settings → Device Info → copy Device ID
Contatore elettrico - Canale 1 Contatore elettrico Solo lettura

Consumo energetico sulla pinza CT canale 1 -- energia cumulativa (kWh) e consumo totale (Wh)

numeric Unità: kWh
Attributi di servizio
TensioneTensione RMS sul canale 1 letta dal topic MQTT emeter/0/voltage

Contatore elettrico - Canale 1

Lettura consumo totale
# 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
# 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
VAR whatEd := "shellies/shellyem-"+deviceID+"/emeter/0/energy";
VAR whatTo := "shellies/shellyem-"+deviceID+"/emeter/0/total";

IF (whatEd = RECEIVEDMSG.TOPIC)
 Ed := todouble(TOSTRING(RECEIVEDMSG.PAYLOAD))/60000;
END
IF (whatTo = RECEIVEDMSG.TOPIC)
 To := todouble(TOSTRING(RECEIVEDMSG.PAYLOAD));
END
Attributi di servizio
Voltage [V]
if parsejson(response, "Topic") = "shellies/shellyem-"+deviceID+"/emeter/0/voltage"
 return(todouble(parsejson(response, "Payload")));
end
Contatore elettrico - Canale 2 Contatore elettrico Solo lettura

Consumo energetico sulla pinza CT canale 2 -- energia cumulativa (kWh) e consumo totale (Wh)

numeric Unità: kWh
Attributi di servizio
TensioneTensione RMS sul canale 2 letta dal topic MQTT emeter/1/voltage

Contatore elettrico - Canale 2

Lettura consumo totale
# 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
# 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
VAR whatEd := "shellies/shellyem-"+deviceID+"/emeter/1/energy";
VAR whatTo := "shellies/shellyem-"+deviceID+"/emeter/1/total";

IF (whatEd = RECEIVEDMSG.TOPIC)
 Ed := todouble(TOSTRING(RECEIVEDMSG.PAYLOAD))/60000;
END
IF (whatTo = RECEIVEDMSG.TOPIC)
 To := todouble(TOSTRING(RECEIVEDMSG.PAYLOAD));
END
Attributi di servizio
voltage [V]
if parsejson(response, "Topic") = "shellies/shellyem-"+deviceID+"/emeter/1/voltage"
 return(parsejson(response, "Payload"));
end
Relè contattore Interruttore

Uscita relè 2A per controllo contattore -- legge lo stato relay/0 e pubblica comandi on/off

boolean
Valori / Stati: ON · OFF

Relè contattore

Lettura stato interruttore
# 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
MQTTPUBLISH("shellies/shellyem-" + deviceID + "/relay/0/command",if(St = 1, "on","off"));

# Simple HTTP Request:
# 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
VAR whatSt := "shellies/shellyem-"+deviceID+"/relay/0";
IF (whatSt = RECEIVEDMSG.TOPIC)
 IF (TOSTRING(RECEIVEDMSG.PAYLOAD) = "on")
  St := 1;
 ELSE
  St := 0;
 END
END
Connessione: Packet Parser → MQTT
Possibili miglioramenti (5)
  • Active Power — Instantaneous active power in W per channel. Available via MQTT but template listener scripts do not subscribe to it — readdemand is commented-out boilerplate.
  • Reactive Power — Instantaneous reactive power in VAR per channel. Available via MQTT topic.
  • Total Energy Returned — Total energy returned to grid in Wh per channel. Useful for solar/bidirectional setups.
  • Connection Status — LWT topic — true on connect, false on disconnect. Could detect device offline state.
  • Reset Energy Data — Payload 'reset_data' resets all accumulated energy counters on both channels.

Fonti

Hai trovato un problema con questo template?

Dicci cosa non funziona, cosa manca o come dovrebbe comportarsi il template. Il tuo feedback ci aiuta a mantenere il catalogo accurato.

Verificato da TapHome

Vuoi usarlo nel tuo TapHome Core?

Apri questo template nel Customer Portal per applicarlo a una delle tue case, o crea una proposta di modifica e inviala al catalogo.

Apri nel portale