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

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

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

but they end command which does not set the output,

Anyone have succeeded with sending MQTT to Shelly pro 1 switch ?
I can toggle it via HTTP but would like to figure out how to do it in MQTT

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

Which I'm guessing is something like this for your case:

 - or -

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

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.

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.

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

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()

Hope this helps.

1 Like

thanks a lot, works like a charm

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)

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

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

Correct and thanks, I have already done that.

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.

1 Like

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.

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