# Shelly Relay 1 pro MQTT command for Turn Switch on/off

**URL:** <https://forum.inductiveautomation.com/t/shelly-relay-1-pro-mqtt-command-for-turn-switch-on-off/81137>\
**Category:** 3rd Party Modules\
**Tags:** ignition81, scripting\
**Created:** [October 29, 2023, 4:24pm UTC](https://forum.inductiveautomation.com/t/shelly-relay-1-pro-mqtt-command-for-turn-switch-on-off/81137 "2023-10-29T16:24:06Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![hans\_odgaard](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/hans_odgaard/32/83110_2.png) [@hans\_odgaard](https://forum.inductiveautomation.com/u/hans_odgaard)\
**Post date:** [October 29, 2023, 4:24pm UTC](https://forum.inductiveautomation.com/t/shelly-relay-1-pro-mqtt-command-for-turn-switch-on-off/81137/1 "2023-10-29T16:24:06Z")

</div>

Trying to publish a command to My Shelly Plus Relay but can't quit figure how to build the payload.

All statusses are read without any problems. Only the rpc channel is open

see for shelly config and Tag in MQTT Engine

 ![Skærmbillede 2023-10-28 kl. 20.07.28](https://us1.discourse-cdn.com/inductiveautomation/original/3X/d/2/d28b189eb4f6073e2237fbeb02b30caff7a04e0b.png)

I can send the data via system.cirruslink.transmission.publish

but they end command which does not set the output,

 ![Skærmbillede 2023-10-29 kl. 17.00.59](https://us1.discourse-cdn.com/inductiveautomation/original/3X/5/e/5e20d2924e52944cf4d1ae372715178a0fcc56e9.png)

Anyone have succeeded with sending MQTT to [Shelly pro 1](https://www.shelly.com/en-dk/products/product-overview/shelly-pro-1) switch ?  
I can toggle it via HTTP but would like to figure out how to do it in MQTT

---

<div class="post-metadata">

**Author:** ![michael.flagler](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/michael.flagler/32/26272_2.png) [@michael.flagler](https://forum.inductiveautomation.com/u/michael.flagler)\
**Post date:** [October 29, 2023, 6:57pm UTC](https://forum.inductiveautomation.com/t/shelly-relay-1-pro-mqtt-command-for-turn-switch-on-off/81137/2 "2023-10-29T18:57:21Z")

</div>

I don't have this device, but when looking at the following documentation for MQTT (you gotta scroll down a bit), it looks like you need to publish a simple command to the appropriate topic

Topic:\<topic\_prefix\>/command/switch:  
Which I'm guessing is something like this for your case:

```auto
shellies/relay/command/switch:0
 - or -
shellies/relay/ventilation/command/switch:0

```

Payload/Command (string): "on", "off", or "toggle"

> **[Switch | Shelly Technical Documentation](https://shelly-api-docs.shelly.cloud/gen2/ComponentsAndServices/Switch/)**
>
> The Switch component handles a switch (relay) output terminal with optional power metering capabilities. It uses Switch as RPC namespace and provides the methods:

---

<div class="post-metadata">

**Author:** ![hans\_odgaard](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/hans_odgaard/32/83110_2.png) [@hans\_odgaard](https://forum.inductiveautomation.com/u/hans_odgaard)\
**Post date:** [October 29, 2023, 7:11pm UTC](https://forum.inductiveautomation.com/t/shelly-relay-1-pro-mqtt-command-for-turn-switch-on-off/81137/3 "2023-10-29T19:11:28Z")

</div>

Thanks, even though I have been through their documentation and tried all sorts of different setups, based on their info, but I probably don’t understand it.

---

<div class="post-metadata">

**Author:** ![michael.flagler](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/michael.flagler/32/26272_2.png) [@michael.flagler](https://forum.inductiveautomation.com/u/michael.flagler)\
**Post date:** [October 29, 2023, 8:58pm UTC](https://forum.inductiveautomation.com/t/shelly-relay-1-pro-mqtt-command-for-turn-switch-on-off/81137/4 "2023-10-29T20:58:00Z")

</div>

Have you tried just using a tool like MQTT Explorer to publish values to the topics and get it working manually that way first? That would then get the topic and message figured out so you can program it then.

---

<div class="post-metadata">

**Author:** ![brandon1](https://avatars.discourse-cdn.com/v4/letter/b/ea666f/32.png) [@brandon1](https://forum.inductiveautomation.com/u/brandon1)\
**Post date:** [October 30, 2023, 12:48pm UTC](https://forum.inductiveautomation.com/t/shelly-relay-1-pro-mqtt-command-for-turn-switch-on-off/81137/5 "2023-10-30T12:48:16Z")

</div>

Here is a snippet of code I got working for a Shelly Relay

```auto
recircHOA = system.tag.readBlocking('[default]Pool/SolarHeater/RecircPump/OC_HOA')[0].value
if recircHOA==2:
	import java
	autoPermissive = event.getCurrentValue().getValue()
	data = java.lang.String("off").getBytes()
	if autoPermissive:
		data = java.lang.String("on").getBytes()
	server = "Chariot SCADA"
	topic = "RecircPump/command/switch:0"
	#data = java.lang.String(strCmd).getBytes()
	system.cirruslink.engine.publish(server,topic,data,0,0)
	system.tag.writeBlocking(['[default]Pool/SolarHeater/RecircPump/OS_RS'],[autoPermissive])

```

Hope this helps.

---

<div class="post-metadata">

**Author:** ![hans\_odgaard](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/hans_odgaard/32/83110_2.png) [@hans\_odgaard](https://forum.inductiveautomation.com/u/hans_odgaard)\
**Post date:** [October 30, 2023, 3:29pm UTC](https://forum.inductiveautomation.com/t/shelly-relay-1-pro-mqtt-command-for-turn-switch-on-off/81137/6 "2023-10-30T15:29:54Z")

</div>

thanks a lot, works like a charm

---

<div class="post-metadata">

**Author:** ![hans\_odgaard](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/hans_odgaard/32/83110_2.png) [@hans\_odgaard](https://forum.inductiveautomation.com/u/hans_odgaard)\
**Post date:** [October 30, 2023, 3:37pm UTC](https://forum.inductiveautomation.com/t/shelly-relay-1-pro-mqtt-command-for-turn-switch-on-off/81137/7 "2023-10-30T15:37:34Z")

</div>

See the post below and should have read your post where you mentioned Payload (string) I was still trying to make a json.

But here is my working test script.

import java  
mqttServerName ="Chariot SCADA"  
topic = "shellies/relay/ventilation/command/switch:0"  
data = java.lang.String("toggle").getBytes() #on/off/toggle  
print params  
qos = 0  
retained = 0  
system.cirruslink.transmission.publish(mqttServerName, topic, data, qos, retained)

---

<div class="post-metadata">

**Author:** ![michael.flagler](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/michael.flagler/32/26272_2.png) [@michael.flagler](https://forum.inductiveautomation.com/u/michael.flagler)\
**Post date:** [October 30, 2023, 3:55pm UTC](https://forum.inductiveautomation.com/t/shelly-relay-1-pro-mqtt-command-for-turn-switch-on-off/81137/8 "2023-10-30T15:55:34Z")

</div>

Per the documentation at CirrusLink, you could probably simplify the encoding of your string for the data/payload.

```auto
mqttServerName ="Chariot SCADA"
topic = "shellies/relay/ventilation/command/switch:0"
data = str("toggle").encode() #on/off/toggle
qos = 0
retained = 0
system.cirruslink.transmission.publish(mqttServerName, topic, data, qos, retained)

```

See: [MQTT Publishing via MQTT Transmission - MQTT Modules for Ignition 8.x - Confluence](https://docs.chariot.io/display/CLD80/MQTT+Publishing+via+MQTT+Transmission)

---

<div class="post-metadata">

**Author:** ![hans\_odgaard](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/hans_odgaard/32/83110_2.png) [@hans\_odgaard](https://forum.inductiveautomation.com/u/hans_odgaard)\
**Post date:** [October 30, 2023, 4:51pm UTC](https://forum.inductiveautomation.com/t/shelly-relay-1-pro-mqtt-command-for-turn-switch-on-off/81137/9 "2023-10-30T16:51:54Z")

</div>

Correct and thanks, I have already done that.

---

<div class="post-metadata">

**Author:** ![msteele](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/msteele/32/77889_2.png) [@msteele](https://forum.inductiveautomation.com/u/msteele)\
**Post date:** [October 30, 2023, 7:11pm UTC](https://forum.inductiveautomation.com/t/shelly-relay-1-pro-mqtt-command-for-turn-switch-on-off/81137/10 "2023-10-30T19:11:14Z")

</div>

So Shelly's do MQTT out of the box? I was always tempted to get a Shelly Pro 4PM (ethernet-connected) but didn't take the leap because I try to minimize IP-based Home IOT devices vs using Z-Wave or Zigbee.

---

<div class="post-metadata">

**Author:** ![brandon1](https://avatars.discourse-cdn.com/v4/letter/b/ea666f/32.png) [@brandon1](https://forum.inductiveautomation.com/u/brandon1)\
**Post date:** [October 30, 2023, 7:25pm UTC](https://forum.inductiveautomation.com/t/shelly-relay-1-pro-mqtt-command-for-turn-switch-on-off/81137/11 "2023-10-30T19:25:14Z")

</div>

Yes, they do have MQTT out of the box. It works pretty well, and I had no problems getting it setup. Mine is actually in a IPX4 box outdoors and still managed to hold up through the summer.

---

<div class="post-metadata">

**Author:** ![hans\_odgaard](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/hans_odgaard/32/83110_2.png) [@hans\_odgaard](https://forum.inductiveautomation.com/u/hans_odgaard)\
**Post date:** [October 30, 2023, 7:49pm UTC](https://forum.inductiveautomation.com/t/shelly-relay-1-pro-mqtt-command-for-turn-switch-on-off/81137/12 "2023-10-30T19:49:55Z")

</div>

Getting my Shelly HT modules up and running, creating UDT's for reference tags didn't take long.

I'm planning to let my ignition maker take over the home automation.  
Next project will be able to handle the load balancing on our charging points where I live approx 5-6 charges where I might use one of Shellies to measure current power consumption and then determine what is left for charging points and thereby set the limit on them. But that is the day after tomorrow problem
