Skip to content

Guides

Shelly Plug S

Connect a Shelly Plug S smart plug to Thinger.io over MQTT, without reflashing it, and control it with a ready-made product.

Guide3 min read

This guide connects a Shelly Plug S, a Wi-Fi smart plug with power metering, to Thinger.io. The plug speaks MQTT out of the box, so you keep its original firmware: you point it to your instance, and the Shelly Plug S product stores its state, power and energy and lets you switch it on and off.

Shelly Plug S smart plug, a white plug-in socket with the Shelly logo
Shelly Plug S

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 Plug S 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 plug connected to your Wi-Fi network, and its web interface open in a browser.

Steps ​

  1. Find the device ID

    In the web interface of the plug, open Internet & Security and then Advanced - Developer Settings.

    Main menu of the Shelly Plug S web interface, with the Timer, Weekly schedule, Internet & Security, Safety, Actions and Settings buttons
    Web interface of the plug

    The MQTT client ID of the plug is not editable: it shows in the Will Topic, such as shellies/shellyplug-s-C18B12/online. The part between the slashes, shellyplug-s-C18B12, is the ID the device gets in Thinger.io.

  2. Point the plug to your instance

    On the same screen, enable action execution via MQTT and fill in:

    FieldValue
    UsernameYOUR_USER
    PasswordThe device credentials you choose for this plug.
    ServerYOUR_SERVER:1883
    Advanced - Developer Settings of the Shelly Plug S with MQTT enabled, the username, the password, the server on port 1883 and the Will Topic shellies/shellyplug-s-C18B12/online
    MQTT settings of the plug

    Save. Enabling MQTT turns off the connection of the plug to the Shelly cloud.

  3. Let the product create the device

    The product's Auto Provision rule accepts any device whose ID matches shellyplug-s-[0-9A-F]+. 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 plug retries and connects on the next attempt.

    To use other credentials, or a plug with another ID, create the device first as an MQTT device in Devices with the plug's client ID as its device ID and the product Shelly Plug S. See MQTT.

What the product does ​

DEVICEMQTTPRODUCTShelly Plug Sdevice ID shellyplug-s-C18B12PUBLISHESSUBSCRIBESshellies/<id>/relay/0shellies/<id>/relay/0/powershellies/<id>/relay/0/energyshellies/<id>/temperatureshellies/<id>/overtemperatureshellies/announceshellies/<id>/relay/0/commandon / offtoOnOff: true → on, false → offShelly Plug S producttopics use {{device}} for the device IDPROPERTIESDATA BUCKETSAPI RESOURCErelaypowershelly_plug_s_powershelly_plug_s_temperatureshelly_plug_s_announcerelaytoBoolean: true or falselatest readingfields energy (kWh) and powerdefault: property.relay
Shelly Plug S topics to the product

The product listens to the topics the plug publishes, so the device needs no code. The device topics use the placeholder {{device}} for the device ID.

Properties ​

PropertyTopicPayload
relayshellies/{{device}}/relay/0{{payload:toBoolean}}
powershellies/{{device}}/relay/0/power{{payload}}

The plug reports its relay as the text on or off. {{payload:toBoolean}} passes it through the toBoolean function of the product script, so the property holds true or false.

Data Buckets ​

Data BucketTopicPayload
shelly_plug_s_powershellies/{{device}}/relay/{{relay}}/{{field=energy|power}}{{payload:processData}}
shelly_plug_s_temperatureshellies/{{device}}/{{field=temperature|overtemperature}}{{payload}}
shelly_plug_s_announceshellies/announce{{payload}}
  • {{field=energy|power}} listens to both topics and stores them in one record, with a field named after each topic: energy and power.
  • {{relay}} captures the relay number from the topic and stores it as a tag of the record, so you can filter by relay.
  • processData converts the energy, which the plug reports in watt-minutes, to kWh.
  • The plug publishes its model, firmware version (fw_ver), IP address (ip) and whether a firmware update is available (new_fw) on shellies/announce.

A product bucket is created with its first message, so the first reading of each topic only creates the bucket and the data starts with the next one.

Switch the plug ​

The API resource relay publishes on shellies/{{device}}/relay/0/command, with the payload {{payload:toOnOff=property.relay}}. toOnOff turns true and false into the on and off the plug expects, and =property.relay makes the current state of the relay the default value, so a switch in a dashboard or in the device API starts in the right position.

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 plug, 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

Turn off the Shelly plug YOUR_DEVICE.

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

Script ​

js
function toBoolean(value){
    return value == "on" ? true : false;
}

function toOnOff(value){
    return value ? "on" : "off";
}

function processData(value){
    // energy is missing when the plug is off
    if(!value.energy) value.energy=0;
    // convert energy from watt-minutes to kWh
    value.energy = value.energy/60/1000;
    return value;
}

To find the topics and payloads of other devices, use the device's events inspector, which shows every MQTT message it publishes, or the vendor's documentation.

Result ​

The plug appears in Devices, connected and assigned to the product. Its relay and power properties follow the plug, the three Data Buckets fill with its readings, and the product dashboard shows the power switch, the consumption and the temperature.

Next steps ​