---
title: "Shelly Plug S"
description: "Shelly Plug S connects to TapHome over MQTT: power (kW), energy (kWh), relay on/off and internal temperature. Enable MQTT in the plug web UI at its IP."
url: "https://taphome.com/en/compatibility/shelly-plug-s-mqtt/"
language: en
lastmod: 2026-03-31
generator: hugo
ai:
  topics: ["mqtt","smart-plug","wifi","energy-monitoring","relay-control"]
  questions: ["How to integrate Shelly Plug S with TapHome via MQTT?","What does the Shelly Plug S TapHome template measure?","How to find the Shelly Plug S MQTT Device ID?","Why is my Shelly Plug S not reporting power data?","How to control the Shelly Plug S relay from TapHome?","Does the Shelly Plug S template report energy consumption in kWh?"]
---

# Shelly Plug S

Communication: Packet Parser → MQTT

- [Shelly Plug S Product Page](https://www.shelly.com/en/products/shop/shelly-plug-s)

> Network address
> 
> With the MQTT broker built into TapHome, enter `127.0.0.1` as the broker address in TapHome. In the device, enter the IP address of the TapHome Core and give the Core an IP reservation in the router.
> 
> [Network Preparation](https://taphome.com/en/docs/setup/network-preparation/)

## Integration guide

The Shelly Plug S is a compact Wi-Fi smart plug with built-in energy monitoring, rated at 12A / 2500W. TapHome communicates with the device over MQTT — the plug subscribes to a broker and publishes relay state, power consumption, energy counter, and internal temperature data.

The template exposes two devices: an Electric Meter for energy monitoring and a Switch for relay control. A module-level service attribute reports the internal device temperature.

## Configuration

### Device ID

Each Shelly Plug S has a unique MQTT Device ID in the format `shellyplug-s-<MAC6>`, where `<MAC6>` is the last 6 characters of the MAC address in lowercase hex (e.g., `shellyplug-s-112233`).

The Device ID can be found:

- In the Shelly web UI: **Settings** → **Device Info** → **Device ID** (use the first string of characters, not in brackets)
- Via API: `GET http://<device-ip>/settings` → `mqtt.id` field

### Enabling MQTT

To enable MQTT on the Shelly Plug S:

1. Open the device web interface in a browser (navigate to the device IP address)
2. Go to **Internet and Security** → **Advanced - Developer Settings**
3. Tick **"Enable action execution via MQTT"**
4. Fill the **"Server"** input with `{MQTT broker IP}:{port}` (default port `1883`)
5. Press **SAVE**

### Template setup

After importing the template in TapHome:

1. Open the **Shelly Plug S MQTT** module
2. Set the **MQTT Broker IP** and **Port** (default `1883`)
3. Set the **deviceID** custom variable to the Device ID of the Shelly Plug S (e.g., `112233` — just the last 6 hex characters of the MAC address)

The module subscribes to `shellies/#` and the listener scripts filter messages by the configured device ID prefix `shellyplug-s-{deviceID}`.

## Device capabilities

### Energy monitoring

The Electric Meter device reads two values from the plug:

- **Total consumption** — cumulative energy from the `relay/0/energy` topic. The device reports energy in Watt-minutes; the template converts to kWh by dividing by 60000.
- **Instantaneous demand** — current power draw from the `relay/0/power` topic. The device reports power in Watts; the template converts to kW by dividing by 1000.

Both values update according to the MQTT reporting interval (default 30 seconds, configurable in the Shelly web UI via `mqtt_update_period`).

> [!TIP]
> The energy counter resets on device reboot. For persistent energy tracking, use TapHome's built-in energy logging which stores cumulative values independently of the device counter.

### Relay control

The Switch device controls the plug's relay:

- **Read state** — listens to `shellies/shellyplug-s-{deviceID}/relay/0` and maps `on` → 1, `off` → 0
- **Write state** — publishes to `shellies/shellyplug-s-{deviceID}/relay/0/command` with `on` or `off`

The relay supports up to 2500W / 12A load.

### Temperature monitoring

A module-level service attribute reports the internal device temperature in °C, read from the `shellies/shellyplug-s-{deviceID}/temperature` topic. This is the temperature of the plug's electronics, not ambient room temperature.

### Additional capabilities

The Shelly Plug S also publishes an online/offline status via the MQTT LWT topic, overtemperature alerts (when the device exceeds safe operating temperature), a human-readable temperature status classification (Normal/High/Very High), and button input events (short press, long press, double press). These capabilities can be added in a future template update.

## Troubleshooting

### No data from the plug

1. Verify the Shelly Plug S is connected to Wi-Fi and MQTT is enabled in the device settings (**Internet and Security** → **Advanced - Developer Settings**)
2. Check that the **deviceID** custom variable matches the Device ID exactly (e.g., `112233`)
3. Use an MQTT client (e.g., MQTT Explorer) to subscribe to `shellies/#` and verify the plug publishes messages

### Power readings show zero

1. Confirm a load is connected and the relay is switched on
2. Check the `relay/0/power` topic with an MQTT client — the value should be non-zero when a load is drawing power
3. Verify the Electric Meter device shows values in TapHome — total consumption in kWh, demand in kW

### Relay not responding to commands

1. Verify MQTT is enabled and the broker address is correct in the Shelly web UI
2. Check that TapHome can reach the MQTT broker (correct IP and port in the module settings)
3. Test by publishing `on` or `off` to `shellies/shellyplug-s-{deviceID}/relay/0/command` via an MQTT client

> [!WARNING]
> Gen1 Shelly devices do **not** support MQTT over TLS. Communication between the plug and the MQTT broker is unencrypted (plain MQTT, port 1883). Ensure the MQTT broker is on a trusted local network.

## How to install in TapHome

### Prerequisites

- Shelly device connected to Wi-Fi (2.4 GHz), e.g. through the Shelly app or the device's own access point
- MQTT broker running on your local network (e.g., Mosquitto, Home Assistant, or TapHome built-in broker)
- TapHome CCU on the same network as the broker

> [!WARNING]
> On **Gen1** devices, enabling MQTT **disables Shelly Cloud**. Both cannot run simultaneously. On Gen2/Plus devices this limitation does not apply.

### Step 1 — Enable MQTT on the Shelly device

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

1. Open the Shelly web UI: `http://<device-ip>/`
2. Navigate to **Internet & Security** → **Advanced — MQTT**
3. Enable **MQTT**
4. Set **MQTT Server**: `<broker-ip>:<port>` (e.g., `192.168.1.10:1883`)
5. Optionally set **MQTT User** and **MQTT Password** if your broker requires authentication
6. Click **Save** — the device will reboot and connect to the broker

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

1. Open the Shelly web UI: `http://<device-ip>/`
2. Navigate to **Settings** → **MQTT**
3. Enable **MQTT**
4. Set **Server**: `<broker-ip>:<port>` (e.g., `192.168.1.10:1883`)
5. The **Client ID** is pre-filled with the device ID (e.g., `shellyplus1pm-AABBCCDDEE`) — leave as-is unless you have a specific reason to change it
6. Click **Save** and reboot the device

With the TapHome built-in broker, `<broker-ip>` is the IP address of the TapHome Core. Give the Core an IP reservation in the router, otherwise the device loses the broker when the router changes the address → [Network Preparation](https://taphome.com/en/docs/setup/network-preparation/).

> [!TIP]
> To verify MQTT is working, use an MQTT client (e.g., MQTT Explorer) and subscribe to `shellies/#` (Gen1) or `<device-id>/#` (Gen2). You should see status messages from the device.

### Step 2 — Find the Device ID / MQTT Client ID

Some templates require a **Device ID** or **MQTT Client ID** parameter. This is the unique identifier used in MQTT topics.

- **Gen1:** found on the label as MAC address (e.g., `AABBCCDDEE`). Device ID = `shelly<model>-<mac>`, e.g., `shelly1pm-AABBCCDDEE`
- **Gen2/Plus:** found in the Shelly web UI under **Settings** → **Device Info** → **Device ID**, or on the device label

### Step 3 — Configure in TapHome

1. In TapHome, add a new **Packet Parser (MQTT)** module
2. **IP Address:** `127.0.0.1` for the TapHome built-in broker (the control unit connects to itself, the address never changes); for an external broker its IP address (e.g., `192.168.1.10`)
3. **Port:** `1883` (default; use `8883` for TLS)
4. **Device ID / MQTT Client ID:** enter the value from Step 2 (if required by the template)
5. Import the template — TapHome will subscribe to the device topics automatically

## Available devices 2

These devices appear in TapHome after import.

Shelly Plug S MQTT Module

Service Attributes

|             |                                                            |
|-------------|------------------------------------------------------------|
| Temperature | Internal device temperature — not ambient room temperature |

Custom Variables

|                     |                                                                                                                                              |
|---------------------|----------------------------------------------------------------------------------------------------------------------------------------------|
| `deviceID` (string) | MQTT Device ID of the Shelly Plug S — last 6 characters of the MAC address in lowercase hex (find in Shelly web UI → Settings → Device Info) |

Listener

```taphome
VAR whatT := "shellies/shellyplug-s-"+deviceID+"/temperature";
IF (whatT = RECEIVEDMSG.TOPIC)
 temperatureC := TOSTRING(RECEIVEDMSG.PAYLOAD);
END
```

Service Attributes

Temperature \[°C ]

```taphome
temperatureC
```

Electric Meter Electricity Meter Read-only

Power consumption and energy metering — instantaneous power (kW) and cumulative energy (kWh)

numeric Unit: kWh (total), kW (demand) energy: Watt-minutes /60000 = kWh; demand: Watts /1000 = kW

Read total consumption

```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");
```

Read demand

```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
VAR whatTo := "shellies/shellyplug-s-"+deviceID+"/relay/0/energy";
IF (whatTo = RECEIVEDMSG.TOPIC)
 To := TODOUBLE(TOSTRING(RECEIVEDMSG.PAYLOAD))/60000;
END
VAR whatEd := "shellies/shellyplug-s-"+deviceID+"/relay/0/power";
IF (whatEd = RECEIVEDMSG.TOPIC)
 Ed := TODOUBLE(TOSTRING(RECEIVEDMSG.PAYLOAD))/1000;
END
```

Switch Switch Read and write

string on→1, off→0 (read); 1→on, 0→off (write)

Values / States: ON · OFF

Read switch state

```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");
```

Write switch state

```taphome
# Simple HTTP Request:
MQTTPUBLISH("shellies/shellyplug-s-"+deviceID+ "/relay/0/command",if(St = 1, "on","off"));
# 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






#MQTTPUBLISH(topic + "/relay/0/command",if());
```

Listener

```taphome
VAR whatSt := "shellies/shellyplug-s-"+deviceID+"/relay/0";
IF (whatSt = RECEIVEDMSG.TOPIC)
 IF (TOSTRING(RECEIVEDMSG.PAYLOAD) = "on")
  St := 1;
 ELSE
  St := 0;
 END
END
```

**Connection:** Packet Parser → MQTT

Possible improvements (6)

- Connection Status — LWT topic — true on connect, false on disconnect. Could detect offline device.
- Overtemperature Alert — 1 = overheated, 0 = normal. Could trigger safety alarm when device exceeds safe operating temperature.
- Temperature Status — String: Normal, High, or Very High. Human-readable temperature classification.
- Button Input State — 0 or 1 — physical button state on the device.
- Button Input Event — JSON payload with event type (S=short, L=long, SS=double, SSS=triple) and event counter.
- Overpower State — Relay topic can report 'overpower' payload when load exceeds rating. Not parsed in listener script.

## Import parameters

Enter these values when you import the XML.

| Asked in the app       | Default         |
|------------------------|-----------------|
| Mqtt Broker IP address | `192.168.0.1`   |
| Mqtt Broker port       | `1883`          |
| Device ID              | Enter at import |

## Sources

- 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 Plug S — Device-Specific MQTT API
  
  [shelly-api-docs.shelly.cloud](https://shelly-api-docs.shelly.cloud/gen1/#shelly-plug-plugs-mqtt) 2026-03-31

## Related Documentation

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

