External integration - Shelly

Hi everyone :waving_hand:

After spending quite some time digging into Shelly payloads, I’m presenting you an external Shelly integration for Gladys, in version 1.0.0.

:package: Repository: GitHub - Terdious/gladys-shelly · GitHub
:open_book: Documentation: French · English


In a nutshell

Relays, smart plugs, and Shelly energy meters, locally first, without account and without cloud. A typical installation requires a completely empty configuration form: you install, you run a scan, you add your devices.


Are you already controlling your Shelly devices via a bridge?

Pierre-Gilles just published his position on the subject — Experience report: why I now recommend external integrations — and I fully share it.

If your Shelly devices currently go through an intermediate layer, you can switch them here. What you concretely gain: nothing to maintain between Gladys and your devices, and above all 100% of what the hardware can do, without going through a standard that first needs to know how to express it. A Pro 3EM comes out with its 24 features — the three phases separately, active and apparent power, voltage, current, neutral current, and the eight energy meters for consumed and reinjected energy.

Just one precaution: remove them from the old bridge before adding them here, otherwise you will see each Shelly device twice.


What it can do

Local, and in real-time. The integration speaks the RPC Gen2+ protocol directly to your devices, on a WebSocket that the device itself feeds: a relay switched at the wall switch reports back in about one second, not at the next poll.

All generations. Gen2 and later (Plus, Pro, Mini, Gen3, Gen4) and Gen1 (Shelly 1, 1PM, 2.5, Plug S, EM, 3EM). Gen1 devices speak a completely different API — REST instead of JSON-RPC, Basic instead of Digest — but they are normalized to the same model: a 3EM Gen1 exposes exactly the same 24 features as a Pro 3EM Gen2.

Three transports, from best to last resort: local → MQTT → cloud. Each has its reason to exist:

  • local is the nominal path;
  • MQTT (optional) is the most reliable way to find a large installation. mDNS announces itself in short multicast bursts that are easy to miss: at my place, the same park sometimes came back to 19, sometimes to 27 devices, with some systematically absent. A Shelly that publishes on your broker announces itself permanently — it is discovered, it reports in real-time, and it remains controllable even if it is unreachable locally;
  • Shelly Cloud (optional) takes over when a device is not reachable either locally or via MQTT.

Gladys displays the transport actually used, device by device, with the graded badge and its reason when it is not the nominal path.

The device model is deduced, not hard-coded. Features come from the components that the device actually declares in Shelly.GetStatus, never from a model table. A Pro 1 gets an On/Off, a Pro 1PM gets metrology in addition — and a Shelly released after this code still works, as long as it speaks the documented vocabulary.

Covered components: switch, em, emdata, em1, em1data, pm1, temperature, humidity, devicepower.


Real-time, and why it is adjustable

Gladys accepts 300 states per minute per integration. A single Pro 3EM pushes approximately one update per second on ~25 measurements: transmitting everything as-is would make ~900 states/minute, three times the ceiling.

Values are therefore split into two channels:

  • a real-time channel (5 s by default, adjustable from 1 s to 30 s) that carries all instantaneous powers — total, per phase, per relay — and all on/off states;
  • the rest (voltages, currents, apparent powers, energy meters, temperatures) follows the refresh interval, but served from the freshest pushed value, without HTTP round trips.

The point I care about: your setting is a floor, not a promise. The cost of the channel depends on the park, not on the setting — a value that never moves costs nothing. The integration measures what it actually publishes and extends its own interval if the park becomes too large, writing it in the logs, then returns to itself. A state refused by Gladys would be invisible; a slowed-down channel, not.

And every minute, a line says exactly where you stand:

Real-time lane: 178 state(s) published in the last minute (every 5s, from
5 WebSocket and 15 MQTT device(s)); 243/300 states/min of the Gladys budget used

Installation

In Gladys: Integrations → Install an integration → Shelly → Install, then Discovery → Scan.

There is nothing to fill for a 100% local installation. The fields (additional addresses, device password, MQTT broker, cloud key) only serve if your installation needs them, and each is explained directly in the form.

(image 4: the configuration page, empty form)

Requires Gladys ≥ 4.83.0. If a device remains undetectable during the scan, the documentation explains what to look at — and configuring MQTT is almost always the answer on a large installation.


Tested on

My installation: 19 Shelly devices, 10 x Pro 3EM, 1 x Pro 4PM, 2 x Pro 3, 1 x Plus 2PM, 2 x Plus Plug S, and 3 x 3EM Gen1. Local, MQTT, and both combined.


Thanks @pierre-gilles :folded_hands:

By the way, I hit a core limit: publishDiscoveredDevices() was getting a PayloadTooLargeError beyond a dozen devices rich in features (a Pro 3EM = 24 features ≈ 8.4 Ko). Pierre-Gilles fixed this very quickly on the core side (PR #2732). Until everyone is up to date, the integration publishes the largest acceptable subset and logs by name what has been discarded, rather than silently losing the scan.


What’s next

Not yet supported, due to lack of hardware to validate: roller shutters (cover), variable lighting (light), and inputs (input). The code is ready to welcome them, I’m missing the devices: if you have them and want to test a :dev image, let me know, I’ll prepare it with pleasure — it’s the best way for it to arrive quickly.

Shelly BLU devices are not managed either: they speak Bluetooth, and the integration does not do BLE.

The roadmap is open: Roadmap — Shelly external integration · Issue #1 · Terdious/gladys-shelly · GitHub

Bugs, feedback, exotic device payloads: issues are wide open. And if you test, tell me what it gives — especially on models that I don’t have, and especially on models that I don’t have :slightly_smiling_face:

Bravo!! Great integration

@McFlyPartages Aren’t you already on Shelly? You’re gonna love it :slight_smile:

:new_button: Update: v1.0.0 → v1.1.0

Major update of the Shelly integration: it catches up with the latest Gladys and SDK news, and the roadmap advances in one go on shutters, lights and inputs!

:warning: Now requires Gladys ≥ 5.1.0 (widgets and scenes).

:window: Roller shutters (cover)

  • Open / Stop / Close and position via the standard shutter command of Gladys, plus power, voltage, current, energy.
  • The position (100 % = open, same convention in Shelly and Gladys) only appears once the shutter is calibrated in the Shelly app.
  • Plus 2PM / Pro 2PM / Pro Dual Cover in shutter mode, and Shelly 2.5 Gen1 in roller mode.

:light_bulb: Lights (light, rgb, rgbw, cct)

  • On/off, brightness, color, color temperature (2700 K → 6500 K).
  • Changing the brightness does not turn the light on or off.
  • Gen1 also: Dimmer, Bulb, Duo, RGBW2 in color mode.

:radio_button: Inputs and buttons (input)

  • Switch mode → a real-time on/off input.
  • Button mode → a Gladys button + a new scene trigger, on every single, double, triple or long press, in real-time (WebSocket or MQTT). A Shelly i4 finally gives 4 usable buttons!
  • Counter mode → a counter.

:clapper_board: Scenes (category Integrations)

  • Button pressed on a Shelly trigger: device, input, type of press.
  • Shelly reachability trigger: a device becomes unreachable (local, MQTT and cloud), or responds again.
  • Turn on for a duration action: it’s the Shelly itself that turns off after the duration (1 s to 1 day). A Gladys restart in the meantime never leaves the pump or watering running.
  • Restart a Shelly action.

:bar_chart: 4 dashboard widgets

  • Shelly energy meter: live power gauge (below zero in reinjection), one tile per phase, energy, curve over the selected period, voltages, intensities, power factor, frequency.
  • Shelly switches: state and power of each output of a room or the whole house, All on / All off buttons.
  • Shelly shutters: a group of shutters, position of each, Open / Stop / Close / Position buttons.
  • Shelly network health: how many devices in real-time, in backup, unreachable, weak Wi-Fi, firmware updates, and the share of the Gladys budget (300 states/min) used.

(image: the widgets)

:stethoscope: Diagnostics in Configuration

  • Device diagnostics: a complete text report (transport, last data, Wi-Fi signal, firmware, outputs…) to paste into an issue.
  • Test a device: reads a device right away, even not created in Gladys (type its IP) — identity, response time, accepted or not password, real-time. The ideal tool to understand why a scan does not find a device.
  • Read-only, never any password, MAC and IP addresses hidden by default.

(image: the Configuration screen with the two buttons)

:globe_showing_europe_africa: 4 languages

  • All configuration, messages and documentation in French, English, German and Spanish.
  • New Feature names option for the devices you create afterwards.

:locked: Security and maintenance

  • MQTT library updated (6 vulnerabilities fixed); the connection to the broker continues to retry after a refusal.
  • SDK 0.15, and each version now has its release notes on GitHub, linked from the Gladys Supervision page.

:counterclockwise_arrows_button: To enjoy it

  1. Integrations → Shelly → Update.
  2. Discovery tab: Scan, then Update on each device “Already added” to retrieve the new features (shutters, lights, inputs). History, scenes and dashboards are preserved.
  3. Add the widgets from the dashboard edition.

:test_tube: Feedback very much awaited

Shutters, lights and inputs are written according to the official Shelly documentation, but I don’t have the hardware to validate them. If you have a Plus 2PM in shutter mode, a Plus RGBW PM, a Plus i4 / i4 Gen3, a Dimmer, or a 2.5 Gen1 in shutter: test and tell me what it gives! The easiest: the Device diagnostics button, and you paste the report here or in an issue.

Full changelog: https://github.com/Terdious/gladys-shelly/blob/master/CHANGELOG.md
Roadmap: Roadmap — Shelly external integration · Issue #1 · Terdious/gladys-shelly · GitHub

:new_button: v1.2.0 — thermostats « Powered by Shelly »

Thanks to @sylvainpelissier for his contribution: the integration now supports the virtual components of « Powered by Shelly » devices. First device concerned: the LinkedGo ST1820 underfloor heating thermostat, which finally reports its setpoint (controllable, bounded to the device’s range and step), the temperature and humidity of the room, and its on/off options.

:counterclockwise_arrows_button: Integrations → Shelly → Update, then Discovery → Scan.

Release notes: Release v1.2.0 · Terdious/gladys-shelly · GitHub

:new_button: v1.3.0 — Device-specific passwords and Gen1 battery-powered sensors

:key: Different password per device

New Device-specific passwords field in the configuration, for Shelly devices that don’t share the same password as others:

shellyplus1-a8032ab12345=password1; 10.5.0.42=password2

The device is identified by its Shelly ID, MAC address, or IP address. A device that rejects its password shows an orange dot on its badge, and the Configuration screen names it: no more devices disappearing without explanation. “Test a device” also indicates which password was tried.

:droplet: Gen1 battery-powered sensors

  • Flood → water leak detector; Smoke → smoke detector.
  • Door/Window 1 and 2 → opening sensor (open / closed) and brightness.
  • They sleep, and that’s normal: a sleeping H&T, Flood, or Door/Window remains displayed as “local” as long as it has been active in the last 26 hours. No more false “unreachable” alerts, no more unwanted “Shelly Reachability” triggers.
  • :light_bulb: Configure MQTT on these devices: each reading arrives when they wake up.

:radio_button: Gen1 buttons

The inputs of an i3 (and the SW inputs of a Shelly 1 / 2.5) now report single, double, triple, and long presses, like on Gen2: button functionality and Shelly Button Pressed trigger. It works via MQTT (instantaneous) as well as device reading, and a press seen from both sides is only counted once.

:counterclockwise_arrows_button: To take advantage of this

  1. Integrations → Shelly → Update.
  2. Discovery → Scan, then Update on the affected Gen1 devices.

:test_tube: Feedback welcome

Especially if you have Gen1 battery-powered devices (H&T, Flood, Door/Window, i3) or a setup with multiple passwords. The Device Diagnostics button generates a report ready to paste here.

Release notes: Release v1.3.0 · Terdious/gladys-shelly · GitHub

:new_button: v1.4.0 — Shelly Cloud backup, RGBW white channel

:cloud: Shelly Cloud

  • Devices served by the cloud are now read in a single request per cycle for the entire account, instead of one request per device. Calls are also spaced one second apart, the Shelly Cloud API limit: even an entire fleet in cloud backup no longer exceeds it.
  • :bug: Fix: a Gen1 device read via the cloud (e.g., an unreachable 3EM Gen1 locally) did not report any values. It is now read exactly as if it were local.

:light_bulb: Lights

  • An RGBW output (Plus RGBW PM, RGBW2 Gen1 in color mode) finally exposes its white LEDs, adjustable from 0 to 100 %.
  • A Shelly that changes profile (a Plus 2PM switching from relay to shutter, a dimmer switching to a switch) kept its old, empty functionalities without saying anything. The scan now names them in the logs, and the Device Diagnostics button lists them: just delete them in Gladys.

:counterclockwise_arrows_button: To take advantage

Integrations → Shelly → Update, then Discovery → Scan and Update on RGBW devices.

:test_tube: Feedback welcome

Especially if you use Shelly Cloud backup (especially with Gen1) or a Plus RGBW PM: I couldn’t validate these two points on real hardware. The Device Diagnostics generates a report ready to paste here.

Release notes: Release v1.4.0 · Terdious/gladys-shelly · GitHub