---
title: "Shelly 1PM"
description: "Shelly 1PM Wi-Fi relay with power metering via MQTT in TapHome. Control the relay and monitor real-time power and cumulative energy."
url: "https://taphome.com/en/compatibility/shelly-1pm-mqtt/"
language: en
lastmod: 2026-03-31
generator: hugo
ai:
  topics: ["mqtt","smart-plug","wifi","relay","power-metering"]
  questions: ["How to integrate Shelly 1PM with TapHome via MQTT?","What does the Shelly 1PM MQTT TapHome template measure?","How to configure multiple Shelly 1PM units in one TapHome template?","Why is my Shelly 1PM MQTT not reporting power data?","How to find the Shelly 1PM MQTT Device ID?","Does Shelly 1PM MQTT report overtemperature and overpower in TapHome?"]
---

# Shelly 1PM

Communication: Packet Parser → MQTT

- [Shelly 1PM Product Page](https://www.shelly.com/en/products/shop/shelly-1pm)
- [Shelly Gen1 MQTT API Reference](https://shelly-api-docs.shelly.cloud/gen1/)

> Network address
> 
> With the MQTT broker built into TapHome, it is one broker reached from two places. The template runs directly in the TapHome Core, so in TapHome the broker address is `127.0.0.1` (this computer). The device runs elsewhere in the network, so in the device enter the IP address of the TapHome Core and give the Core an IP reservation in the router — if the Core’s address changes, the device can no longer reach the broker.
> 
> [Network Preparation](https://taphome.com/en/docs/setup/network-preparation/)

## Integration guide

The Shelly 1PM is a compact single-channel Wi-Fi relay switch with built-in power metering. It fits behind a standard wall switch and can control one circuit up to 16 A (3500 W at 230 V). TapHome communicates with the device over MQTT — this is the MQTT variant of the Shelly 1PM template, suitable when you prefer local MQTT communication over HTTP polling.

The template supports up to 5 Shelly 1PM units per module. Each unit is distinguished by a `pulgNtopic` custom variable pointing to the device's MQTT Client ID. Each unit exposes a relay switch and an electricity meter.

## Configuration

### Device ID

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

The Device ID can be found:

- On the device label (MAC address)
- In the Shelly web UI: **Settings** → **Device Info**
- Via API: `GET http://<device-ip>/settings` → `mqtt.id` field

> [!TIP]
> This device supports **mDNS discovery**. You can use the hostname `shelly1pm-{MAC}.local` instead of an IP address when configuring TapHome. Replace `{MAC}` with the last 6 characters of the device's MAC address in lowercase hex (e.g., `shelly1pm-112233.local`). Using a hostname prevents connectivity issues when the device's IP address changes.

### Template setup

After importing the template in TapHome:

1. Open the **Shelly 1PM MQTT** module
2. Set the **MQTT Broker IP** and **Port** (default `1883`)
3. For each Shelly 1PM unit, set the `pulgNtopic` custom variable to the Device ID of the corresponding Shelly 1PM (e.g., `shelly1pm-112233`)

The module subscribes to `shellies/#` and the listener scripts filter messages by the configured topic prefix.

> [!TIP]
> Only configure the unit slots you actually use. Unconfigured slots (with the default `shelly1pm-deviceidN` value) will not match any real device and can be ignored.

## Device capabilities

### Relay control

Each unit exposes a switch device in TapHome. The relay state is read from the `shellies/<id>/relay/0` topic and controlled by publishing `on` or `off` to `shellies/<id>/relay/0/command`.

### Power metering

Each unit includes an electricity meter that reads two values:

- **Real-time power** — `shellies/<id>/relay/0/power` reported in watts, converted to kW by the template
- **Total consumption** — `shellies/<id>/relay/0/energy` reported in watt-minutes, converted to kWh by the template

The meter is read-only — it updates automatically whenever the device publishes new data.

### Thermal and overpower monitoring

Each switch device exposes four service attributes:

- **Internal temperature** — device temperature in °C read from `shellies/<id>/temperature`
- **Temperature status** — thermal level: Normal, High, or Very High (`shellies/<id>/temperature_status`)
- **Overheated** — overtemperature alarm flag (`shellies/<id>/overtemperature`)
- **Overpower** — reports the load power (W) when an overpower condition was detected (`shellies/<id>/overpower_value`)

### Additional capabilities

The Shelly 1PM also publishes an online/offline status via the MQTT Last Will and Testament (LWT) topic, a full JSON status message (firmware ≥1.8.0), physical input state, and input events (short/double/triple/long press). These capabilities can be added in a future template update.

## Troubleshooting

### Device not reporting data

1. Verify the Shelly 1PM is connected to Wi-Fi and MQTT is enabled in the device settings
2. Check that the `pulgNtopic` custom variable matches the Device ID exactly (e.g., `shelly1pm-112233`)
3. Confirm the MQTT broker IP and port are correct in the module settings
4. Use an MQTT client (e.g., MQTT Explorer) to subscribe to `shellies/#` and verify the device publishes messages

### Power readings show zero

1. Confirm the load is connected through the Shelly relay (not bypassed)
2. Check that the relay is turned on — the meter only reads when current flows through the relay
3. Subscribe to `shellies/<id>/relay/0/power` with an MQTT client and verify the device reports a non-zero value

### Overtemperature warning

The Shelly 1PM has internal thermal protection. If the device temperature exceeds safe limits, the `temperature_status` changes to "High" or "Very High" and `overtemperature` becomes `true`. Ensure adequate ventilation around the device, especially when switching high loads.

> [!WARNING]
> Gen1 Shelly devices do **not** support MQTT over TLS. Communication between the device 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 10

These devices appear in TapHome after import.

Shelly 1PM MQTT Module

Custom Variables

`pulg1topic` (string) = shelly1pm-deviceid1 MQTT device ID of the first Shelly 1PM unit — format is 'shelly1pm-DEVICEID' (find Device ID in Shelly web UI → Settings → Device Info)

Open http://shellyIpAddress → Settings → Device info → copy Device ID

`pulg2topic` (string) = shelly1pm-deviceid2 MQTT device ID of the second Shelly 1PM unit 

`pulg3topic` (string) = shelly1pm-deviceid3 MQTT device ID of the third Shelly 1PM unit 

`pulg4topic` (string) = shelly1pm-deviceid4 MQTT device ID of the fourth Shelly 1PM unit 

`pulg5topic` (string) = shelly1pm-deviceid5 MQTT device ID of the fifth Shelly 1PM unit

Electric Meter 1 Electricity Meter Read-only

Real-time power (kW) and cumulative energy (kWh) for Shelly 1PM unit 1

numeric Unit: kW / kWh

Listener

```taphome
IF(INDEXOF(pulg1topic, "shelly1pm-deviceid") = 0)
    ADDERROR("Set correct 'pulg1topic' value in module variables. Topic format is 'shelly1pm-<deviceid>'. The Device ID can be found by opening url 'http://shellyIpAddress', in Settings -> Device info.");
    RETURN(-1);
END

IF(INDEXOF(RECEIVEDMSG.TOPIC, "shellies/" + pulg1topic + "/relay/0/") != 0)
    RETURN(0);
END

IF(RECEIVEDMSG.TOPIC = "shellies/" + pulg1topic + "/relay/0/power")
    VAR valueP := TOSTRING(RECEIVEDMSG.PAYLOAD);

    Ed := IF(ISNULL(valueP), NaN, TODOUBLE(valueP) / 1000.0);
ELSEIF(RECEIVEDMSG.TOPIC = "shellies/" + pulg1topic + "/relay/0/energy")
    VAR valueE := TOSTRING(RECEIVEDMSG.PAYLOAD);

    To := IF(ISNULL(valueE), NaN, TODOUBLE(valueE) / 60000.0);
END
```

Switch 1 Switch Read and write

Relay control for Shelly 1PM unit 1 — on/off switching with thermal and overpower monitoring

boolean

Values / States: ON · OFF

Write switch state

```taphome
VAR value := IF(St = 1, "on", "off");
MQTTPUBLISH("shellies/" + pulg1topic + "/relay/0/command", value);
```

Listener

```taphome
IF(INDEXOF(pulg1topic, "shelly1pm-deviceid") = 0)
    ADDERROR("Set correct 'pulg1topic' value in module variables. Topic format is 'shelly1pm-<deviceid>'. The Device ID can be found by opening url 'http://shellyIpAddress', in Settings -> Device info.");
    RETURN(-1);
END

IF(INDEXOF(RECEIVEDMSG.TOPIC, "shellies/" + pulg1topic) != 0)
    RETURN(0);
END

IF(RECEIVEDMSG.TOPIC = "shellies/" + pulg1topic + "/relay/0")
    VAR value := TOSTRING(RECEIVEDMSG.PAYLOAD);
    
    IF(value = "on")
        St := 1;
    ELSEIF(value = "off")
        St := 0;
    ELSE
        ADDERROR("Unknown switch state");
    END
ELSEIF(RECEIVEDMSG.TOPIC = "shellies/" + pulg1topic + "/temperature")
    internalTemp := TOSTRING(RECEIVEDMSG.PAYLOAD);
ELSEIF(RECEIVEDMSG.TOPIC = "shellies/" + pulg1topic + "/overtemperature")
    overTemp := TOSTRING(RECEIVEDMSG.PAYLOAD);
ELSEIF(RECEIVEDMSG.TOPIC = "shellies/" + pulg1topic + "/temperature_status")
    tempStatus := TOSTRING(RECEIVEDMSG.PAYLOAD);
ELSEIF(RECEIVEDMSG.TOPIC = "shellies/" + pulg1topic + "/overpower_value")
    overPower := TOSTRING(RECEIVEDMSG.PAYLOAD);
END
```

Service Attributes

Internal temperature

```taphome
IF(LENGTH(internalTemp) = 0, "Unknown", internalTemp + "°C");
```

Overheated

```taphome
IF(LENGTH(overTemp) = 0, "Unknown", IF(overtemp = 0, "No", "Yes"));
```

Temperature status

```taphome
IF(LENGTH(tempStatus) = 0, "Unknown", tempStatus);
```

Overpower

```taphome
IF(LENGTH(overPower) = 0, "0W", overPower + "W");
```

Electric Meter 2 Electricity Meter Read-only

Real-time power (kW) and cumulative energy (kWh) for Shelly 1PM unit 2

numeric Unit: kW / kWh

Listener

```taphome
IF(INDEXOF(pulg2topic, "shelly1pm-deviceid") = 0)
    ADDERROR("Set correct 'pulg2topic' value in module variables. Topic format is 'shelly1pm-<deviceid>'. The Device ID can be found by opening url 'http://shellyIpAddress', in Settings -> Device info.");
    RETURN(-1);
END

IF(INDEXOF(RECEIVEDMSG.TOPIC, "shellies/" + pulg2topic + "/relay/0/") != 0)
    RETURN(0);
END

IF(RECEIVEDMSG.TOPIC = "shellies/" + pulg2topic + "/relay/0/power")
    VAR valueP := TOSTRING(RECEIVEDMSG.PAYLOAD);

    Ed := IF(ISNULL(valueP), NaN, TODOUBLE(valueP) / 1000.0);
ELSEIF(RECEIVEDMSG.TOPIC = "shellies/" + pulg2topic + "/relay/0/energy")
    VAR valueE := TOSTRING(RECEIVEDMSG.PAYLOAD);

    To := IF(ISNULL(valueE), NaN, TODOUBLE(valueE) / 60000.0);
END
```

Switch 2 Switch Read and write

Relay control for Shelly 1PM unit 2 — on/off switching with thermal and overpower monitoring

boolean

Values / States: ON · OFF

Write switch state

```taphome
VAR value := IF(St = 1, "on", "off");
MQTTPUBLISH("shellies/" + pulg2topic + "/relay/0/command", value);
```

Listener

```taphome
IF(INDEXOF(pulg2topic, "shelly1pm-deviceid") = 0)
    ADDERROR("Set correct 'pulg2topic' value in module variables. Topic format is 'shelly1pm-<deviceid>'. The Device ID can be found by opening url 'http://shellyIpAddress', in Settings -> Device info.");
    RETURN(-1);
END

IF(INDEXOF(RECEIVEDMSG.TOPIC, "shellies/" + pulg2topic) != 0)
    RETURN(0);
END

IF(RECEIVEDMSG.TOPIC = "shellies/" + pulg2topic + "/relay/0")
    VAR value := TOSTRING(RECEIVEDMSG.PAYLOAD);
    
    IF(value = "on")
        St := 1;
    ELSEIF(value = "off")
        St := 0;
    ELSE
        ADDERROR("Unknown switch state");
    END
ELSEIF(RECEIVEDMSG.TOPIC = "shellies/" + pulg2topic + "/temperature")
    internalTemp := TOSTRING(RECEIVEDMSG.PAYLOAD);
ELSEIF(RECEIVEDMSG.TOPIC = "shellies/" + pulg2topic + "/overtemperature")
    overTemp := TOSTRING(RECEIVEDMSG.PAYLOAD);
ELSEIF(RECEIVEDMSG.TOPIC = "shellies/" + pulg2topic + "/temperature_status")
    tempStatus := TOSTRING(RECEIVEDMSG.PAYLOAD);
ELSEIF(RECEIVEDMSG.TOPIC = "shellies/" + pulg2topic + "/overpower_value")
    overPower := TOSTRING(RECEIVEDMSG.PAYLOAD);
END
```

Service Attributes

Internal temperature

```taphome
IF(LENGTH(internalTemp) = 0, "Unknown", internalTemp + "°C");
```

Overheated

```taphome
IF(LENGTH(overTemp) = 0, "Unknown", IF(overtemp = 0, "No", "Yes"));
```

Temperature status

```taphome
IF(LENGTH(tempStatus) = 0, "Unknown", tempStatus);
```

Overpower

```taphome
IF(LENGTH(overPower) = 0, "0W", overPower + "W");
```

Electric Meter 3 Electricity Meter Read-only

Real-time power (kW) and cumulative energy (kWh) for Shelly 1PM unit 3

numeric Unit: kW / kWh

Listener

```taphome
IF(INDEXOF(pulg3topic, "shelly1pm-deviceid") = 0)
    ADDERROR("Set correct 'pulg3topic' value in module variables. Topic format is 'shelly1pm-<deviceid>'. The Device ID can be found by opening url 'http://shellyIpAddress', in Settings -> Device info.");
    RETURN(-1);
END

IF(INDEXOF(RECEIVEDMSG.TOPIC, "shellies/" + pulg3topic + "/relay/0/") != 0)
    RETURN(0);
END

IF(RECEIVEDMSG.TOPIC = "shellies/" + pulg3topic + "/relay/0/power")
    VAR valueP := TOSTRING(RECEIVEDMSG.PAYLOAD);

    Ed := IF(ISNULL(valueP), NaN, TODOUBLE(valueP) / 1000.0);
ELSEIF(RECEIVEDMSG.TOPIC = "shellies/" + pulg3topic + "/relay/0/energy")
    VAR valueE := TOSTRING(RECEIVEDMSG.PAYLOAD);

    To := IF(ISNULL(valueE), NaN, TODOUBLE(valueE) / 60000.0);
END
```

Switch 3 Switch Read and write

Relay control for Shelly 1PM unit 3 — on/off switching with thermal and overpower monitoring

boolean

Values / States: ON · OFF

Write switch state

```taphome
VAR value := IF(St = 1, "on", "off");
MQTTPUBLISH("shellies/" + pulg3topic + "/relay/0/command", value);
```

Listener

```taphome
IF(INDEXOF(pulg3topic, "shelly1pm-deviceid") = 0)
    ADDERROR("Set correct 'pulg3topic' value in module variables. Topic format is 'shelly1pm-<deviceid>'. The Device ID can be found by opening url 'http://shellyIpAddress', in Settings -> Device info.");
    RETURN(-1);
END

IF(INDEXOF(RECEIVEDMSG.TOPIC, "shellies/" + pulg3topic) != 0)
    RETURN(0);
END

IF(RECEIVEDMSG.TOPIC = "shellies/" + pulg3topic + "/relay/0")
    VAR value := TOSTRING(RECEIVEDMSG.PAYLOAD);
    
    IF(value = "on")
        St := 1;
    ELSEIF(value = "off")
        St := 0;
    ELSE
        ADDERROR("Unknown switch state");
    END
ELSEIF(RECEIVEDMSG.TOPIC = "shellies/" + pulg3topic + "/temperature")
    internalTemp := TOSTRING(RECEIVEDMSG.PAYLOAD);
ELSEIF(RECEIVEDMSG.TOPIC = "shellies/" + pulg3topic + "/overtemperature")
    overTemp := TOSTRING(RECEIVEDMSG.PAYLOAD);
ELSEIF(RECEIVEDMSG.TOPIC = "shellies/" + pulg3topic + "/temperature_status")
    tempStatus := TOSTRING(RECEIVEDMSG.PAYLOAD);
ELSEIF(RECEIVEDMSG.TOPIC = "shellies/" + pulg3topic + "/overpower_value")
    overPower := TOSTRING(RECEIVEDMSG.PAYLOAD);
END
```

Service Attributes

Internal temperature

```taphome
IF(LENGTH(internalTemp) = 0, "Unknown", internalTemp + "°C");
```

Overheated

```taphome
IF(LENGTH(overTemp) = 0, "Unknown", IF(overtemp = 0, "No", "Yes"));
```

Temperature status

```taphome
IF(LENGTH(tempStatus) = 0, "Unknown", tempStatus);
```

Overpower

```taphome
IF(LENGTH(overPower) = 0, "0W", overPower + "W");
```

Electric Meter 4 Electricity Meter Read-only

Real-time power (kW) and cumulative energy (kWh) for Shelly 1PM unit 4

numeric Unit: kW / kWh

Listener

```taphome
IF(INDEXOF(pulg4topic, "shelly1pm-deviceid") = 0)
    ADDERROR("Set correct 'pulg4topic' value in module variables. Topic format is 'shelly1pm-<deviceid>'. The Device ID can be found by opening url 'http://shellyIpAddress', in Settings -> Device info.");
    RETURN(-1);
END

IF(INDEXOF(RECEIVEDMSG.TOPIC, "shellies/" + pulg4topic + "/relay/0/") != 0)
    RETURN(0);
END

IF(RECEIVEDMSG.TOPIC = "shellies/" + pulg4topic + "/relay/0/power")
    VAR valueP := TOSTRING(RECEIVEDMSG.PAYLOAD);

    Ed := IF(ISNULL(valueP), NaN, TODOUBLE(valueP) / 1000.0);
ELSEIF(RECEIVEDMSG.TOPIC = "shellies/" + pulg4topic + "/relay/0/energy")
    VAR valueE := TOSTRING(RECEIVEDMSG.PAYLOAD);

    To := IF(ISNULL(valueE), NaN, TODOUBLE(valueE) / 60000.0);
END
```

Switch 4 Switch Read and write

Relay control for Shelly 1PM unit 4 — on/off switching with thermal and overpower monitoring

boolean

Values / States: ON · OFF

Write switch state

```taphome
VAR value := IF(St = 1, "on", "off");
MQTTPUBLISH("shellies/" + pulg4topic + "/relay/0/command", value);
```

Listener

```taphome
IF(INDEXOF(pulg4topic, "shelly1pm-deviceid") = 0)
    ADDERROR("Set correct 'pulg4topic' value in module variables. Topic format is 'shelly1pm-<deviceid>'. The Device ID can be found by opening url 'http://shellyIpAddress', in Settings -> Device info.");
    RETURN(-1);
END

IF(INDEXOF(RECEIVEDMSG.TOPIC, "shellies/" + pulg4topic) != 0)
    RETURN(0);
END

IF(RECEIVEDMSG.TOPIC = "shellies/" + pulg4topic + "/relay/0")
    VAR value := TOSTRING(RECEIVEDMSG.PAYLOAD);
    
    IF(value = "on")
        St := 1;
    ELSEIF(value = "off")
        St := 0;
    ELSE
        ADDERROR("Unknown switch state");
    END
ELSEIF(RECEIVEDMSG.TOPIC = "shellies/" + pulg4topic + "/temperature")
    internalTemp := TOSTRING(RECEIVEDMSG.PAYLOAD);
ELSEIF(RECEIVEDMSG.TOPIC = "shellies/" + pulg4topic + "/overtemperature")
    overTemp := TOSTRING(RECEIVEDMSG.PAYLOAD);
ELSEIF(RECEIVEDMSG.TOPIC = "shellies/" + pulg4topic + "/temperature_status")
    tempStatus := TOSTRING(RECEIVEDMSG.PAYLOAD);
ELSEIF(RECEIVEDMSG.TOPIC = "shellies/" + pulg4topic + "/overpower_value")
    overPower := TOSTRING(RECEIVEDMSG.PAYLOAD);
END
```

Service Attributes

Internal temperature

```taphome
IF(LENGTH(internalTemp) = 0, "Unknown", internalTemp + "°C");
```

Overheated

```taphome
IF(LENGTH(overTemp) = 0, "Unknown", IF(overtemp = 0, "No", "Yes"));
```

Temperature status

```taphome
IF(LENGTH(tempStatus) = 0, "Unknown", tempStatus);
```

Overpower

```taphome
IF(LENGTH(overPower) = 0, "0W", overPower + "W");
```

Electric Meter 5 Electricity Meter Read-only

Real-time power (kW) and cumulative energy (kWh) for Shelly 1PM unit 5

numeric Unit: kW / kWh

Listener

```taphome
IF(INDEXOF(pulg5topic, "shelly1pm-deviceid") = 0)
    ADDERROR("Set correct 'pulg5topic' value in module variables. Topic format is 'shelly1pm-<deviceid>'. The Device ID can be found by opening url 'http://shellyIpAddress', in Settings -> Device info.");
    RETURN(-1);
END

IF(INDEXOF(RECEIVEDMSG.TOPIC, "shellies/" + pulg5topic + "/relay/0/") != 0)
    RETURN(0);
END

IF(RECEIVEDMSG.TOPIC = "shellies/" + pulg5topic + "/relay/0/power")
    VAR valueP := TOSTRING(RECEIVEDMSG.PAYLOAD);

    Ed := IF(ISNULL(valueP), NaN, TODOUBLE(valueP) / 1000.0);
ELSEIF(RECEIVEDMSG.TOPIC = "shellies/" + pulg5topic + "/relay/0/energy")
    VAR valueE := TOSTRING(RECEIVEDMSG.PAYLOAD);

    To := IF(ISNULL(valueE), NaN, TODOUBLE(valueE) / 60000.0);
END
```

Switch 5 Switch Read and write

Relay control for Shelly 1PM unit 5 — on/off switching with thermal and overpower monitoring

boolean

Values / States: ON · OFF

Write switch state

```taphome
VAR value := IF(St = 1, "on", "off");
MQTTPUBLISH("shellies/" + pulg5topic + "/relay/0/command", value);
```

Listener

```taphome
IF(INDEXOF(pulg5topic, "shelly1pm-deviceid") = 0)
    ADDERROR("Set correct 'pulg5topic' value in module variables. Topic format is 'shelly1pm-<deviceid>'. The Device ID can be found by opening url 'http://shellyIpAddress', in Settings -> Device info.");
    RETURN(-1);
END

IF(INDEXOF(RECEIVEDMSG.TOPIC, "shellies/" + pulg5topic) != 0)
    RETURN(0);
END

IF(RECEIVEDMSG.TOPIC = "shellies/" + pulg5topic + "/relay/0")
    VAR value := TOSTRING(RECEIVEDMSG.PAYLOAD);
    
    IF(value = "on")
        St := 1;
    ELSEIF(value = "off")
        St := 0;
    ELSE
        ADDERROR("Unknown switch state");
    END
ELSEIF(RECEIVEDMSG.TOPIC = "shellies/" + pulg5topic + "/temperature")
    internalTemp := TOSTRING(RECEIVEDMSG.PAYLOAD);
ELSEIF(RECEIVEDMSG.TOPIC = "shellies/" + pulg5topic + "/overtemperature")
    overTemp := TOSTRING(RECEIVEDMSG.PAYLOAD);
ELSEIF(RECEIVEDMSG.TOPIC = "shellies/" + pulg5topic + "/temperature_status")
    tempStatus := TOSTRING(RECEIVEDMSG.PAYLOAD);
ELSEIF(RECEIVEDMSG.TOPIC = "shellies/" + pulg5topic + "/overpower_value")
    overPower := TOSTRING(RECEIVEDMSG.PAYLOAD);
END
```

Service Attributes

Internal temperature

```taphome
IF(LENGTH(internalTemp) = 0, "Unknown", internalTemp + "°C");
```

Overheated

```taphome
IF(LENGTH(overTemp) = 0, "Unknown", IF(overtemp = 0, "No", "Yes"));
```

Temperature status

```taphome
IF(LENGTH(tempStatus) = 0, "Unknown", tempStatus);
```

Overpower

```taphome
IF(LENGTH(overPower) = 0, "0W", overPower + "W");
```

**Connection:** Packet Parser → MQTT • Hostname: `shelly1pm-{MAC}.local`

Possible improvements (5)

- Connection Status — LWT topic — true on connect, false on disconnect. Could detect offline units.
- Full Status JSON — Complete /status as JSON (fw ≥1.8.0). Could parse wifi\_sta.rssi, uptime, has\_update.
- Input State — Physical input state (0/1). Shelly 1PM has one input — could be used for detached switch scenarios.
- Input Event — JSON with event type (S=short, SS=double, SSS=triple, L=long) and event\_cnt. Useful for button automation.
- Internal Temperature (Fahrenheit) — Same as temperature topic but in Fahrenheit. Redundant — Celsius already implemented via service attribute.

## 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`        |

## 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

## 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/)

