Skip to content

Guides

Shelly Plus 1PM

Connect a Shelly Plus 1PM relay with power metering to Thinger.io over MQTT and switch it, read its status and store its energy readings.

Guide3 min read

This guide connects a Shelly Plus 1PM, a one-channel Wi-Fi relay with power metering, to Thinger.io over MQTT, keeping its original firmware. The Shelly Plus 1PM product turns its status messages into a property and a Data Bucket, and gives the device API resources to switch the relay and query the device.

Shelly Plus 1PM, a small square relay module with its screw terminals
Shelly Plus 1PM

Before you start ​

  • A Thinger.io account. YOUR_SERVER is iot.thinger.io on the free Cloud account, or the hostname of your private instance, and YOUR_USER is your username.
  • The Shelly Plus 1PM plugin, installed from Plugins > Marketplace. It creates the product. Plugins are not available on the free Cloud account; there, create the same product by hand with the profile described in What the product does.
  • The relay connected to your Wi-Fi network, with access to its web interface.

Steps ​

  1. Configure MQTT on the relay

    In the web interface of the relay, enable MQTT and set the connection with these values. The names of the settings are those of the Shelly firmware; see the Shelly documentation if your version differs.

    SettingValue
    ServerYOUR_SERVER:1883
    Client IDThe device ID, such as shellyplus1pm-441793a50208: the default client ID of the relay.
    UsernameYOUR_USER
    PasswordThe device credentials you choose for this relay.

    The relay must publish its switch status, which it does on <client ID>/status/switch:0, and accept commands on <client ID>/rpc.

  2. Let the product create the device

    The product's Auto Provision rule accepts any device whose ID matches shellyplus1pm-[a-fA-F0-9]+. On its first connection, the device is created as an MQTT device of the product, with the password it sent as its device credentials. That first connection is refused; the relay connects on its next attempt.

    To use a different ID, create the device first as an MQTT device in Devices, with the product Shelly Plus 1PM. See MQTT.

What the product does ​

The relay sends its status as JSON on {{device}}/status/switch:0. The product keeps it in the property relay and in the Data Bucket shelly_plus_1pm_status, both with the payload {{payload:statusProcessor}}. The function statusProcessor of the product script keeps the useful fields and converts the energy from watt-minutes to kWh:

js
function statusProcessor(payload){
    return {
        energy: payload.aenergy.total/60/1000,
        power: payload.apower,
        current: payload.current,
        output: payload.output,
        temperature: payload.temperature.tC,
        voltage: payload.voltage
    };
}

API resources ​

Each API resource publishes an RPC request on {{device}}/rpc. The relay answers on the topic given in src followed by /rpc, and the resource returns the result of the answer:

API resourceRPC methodReturns
relaySwitch.SetNothing. The input is true or false.
statusShelly.GetStatusThe full status, such as the Wi-Fi IP address.
infoShelly.GetDeviceInfoModel, firmware version and device ID.
configShelly.GetConfigThe configuration of the relay.
locationShelly.DetectLocationThe location of the relay, for a map.
updatesShelly.CheckForUpdateThe available firmware updates.

The request of relay is:

json
{"src":"{{device}}/switch/set","method":"Switch.Set","params":{"id":0,"on":{{payload=property.relay.output}}}}

=property.relay.output makes the current state of the relay the default value of the input, so a switch starts in the right position.

Switch the relay ​

Console

Open the device in Devices, go to its API and set the relay input to on or off.

API

YOUR_DEVICE is the device ID of the relay, and YOUR_TOKEN an access token of your account.

POST/v3/users/{user}/devices/{device}/resources/{resource}API reference
bash
curl -X POST "https://YOUR_SERVER/v3/users/YOUR_USER/devices/YOUR_DEVICE/resources/relay" \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d 'false'

AI

Ask your AI agent

Switch off the Shelly relay YOUR_DEVICE.

The agent uses thinger_device_resource_call on the relay resource. See MCP tools.

Result ​

The relay appears in Devices, connected and assigned to the product. Its relay property holds the output, power, voltage, current, energy and temperature of the last status, the Data Bucket shelly_plus_1pm_status keeps every status, and the product dashboard shows the power switch, the consumption and the device information.

Next steps ​