How to publish a payload via zigbee2mqtt

My system is running OH2.5 (RPi4)
Everyting is set up in textfiles: Addons, Things, Items and Rules
All devices are connected via Zigbee2mqtt (Coordinater/Router: Texas Instruments LAUNCHXL-CC1352P-2).
Everything is working fine, BUT there is one thing that I can not figure out: How to publish a payload

Lets take this Gledopto GL-MC-001

Gledopto GL-MC-001 control via MQTT |

as an example:

My Things:

Thing mqtt:topic:T053 “T053” (mqtt:broker:MosquittoMqttBroker) {
Type switch : switch “T053 Power Switch” [
stateTopic = “zigbee2mqtt/053/state”,
commandTopic = “zigbee2mqtt/053/set”,
on = “ON”,
off = “OFF”
Type dimmer : dimmer “T053 Dimmer” [
stateTopic = “zigbee2mqtt/053/brightness”,
commandTopic = “zigbee2mqtt/053/set/brightness”,
min = 0,
max = 255,
step = 1
Type dimmer : color “T053 Color Temperature” [
stateTopic = “zigbee2mqtt/053/color_temp”,
commandTopic = “zigbee2mqtt/053/set/color_temp”,
min = 150,
max = 500,
step = 1


Switch T053_Switch “T053 Switch” { channel=“mqtt:topic:T053:switch” }
Dimmer T053_Brightness “T053 Brightness” { channel=“mqtt:topic:T053:dimmer” }
Dimmer T053_Color_Temperature “T053 Color Temperatur” { channel=“mqtt:topic:T053:color” }

All theese Items are working

My question is now:
What will be the script/syntax (in my Rule) for sending/publishing this payload:


…to the device?





via MQTT Explorer works fine.

Thanks in advance

From a rule you can use Rule Actions!

Thanks - looks like it is the way do do it.
But unfortunally I can not get it working
Running Mmy rule:

                val mqttActions = getActions("mqtt","mqtt:systemBroker:embedded-mqtt-broker")
                mqttActions.publishMQTT("zigbee2mqtt/053/set","{"color":{"x":0.823,"y":0.123}}", true)

i get this error:

2021-03-19 20:13:16.431 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model ‘T005.rules’ has errors, therefore ignoring it: [30,70]: missing ‘)’ at ‘color’

[30,100]: missing ‘}’ at ‘,’

[30,102]: missing ‘}’ at ‘true’

[30,106]: mismatched input ‘)’ expecting ‘end’

Can you spot what is wrong.

Yes, you need to ‘escape’ the quotes that form part of the message string. You do this by adding a backslash in front of the quotes. Try this:

mqttActions.publishMQTT("zigbee2mqtt/053/set","{\"color\":{\"x\":0.823,\"y\":0.123}}", true)

See how above the entire string is shown in red, whilst in your version certain parts of it turned a different colour? That’s because those parts were no longer part of the string as the quotes hadn’t been escaped!

YES - now it works - I also have to change to this:

val mqttActions = getActions(“mqtt”,“mqtt:broker:MosquittoMqttBroker”)
Thanks a lot for you help - what to took me one month, you solved in a few minutes.
Thnaks again.

Hi again
New discoveries raise new questions
I have this HEIMAN Smart Siren:

HEIMAN HS2WD-E control via MQTT |

You can trigger the alarm and you can set it.
Triggerring works fine but setting has no effect.
My rules looks like this:

val mqttActions = getActions(“mqtt”,“mqtt:broker:MosquittoMqttBroker”)

               mqttActions.publishMQTT("zigbee2mqtt/220/set","{\"warning\":{\"mode\": fire, \"level\": low, \"strobe\": true, \"duration\": 3}}", true)

               mqttActions.publishMQTT("zigbee2mqtt/220/set","{\"warning\":{\"duration\": 3, \"mode\": \"emergency\", \"strobe\":true}}", true)

Can you spot why the settings (middle line) have no effects on how the siren behaves.
I wonder why som parts of the payload (eg duration and strobe) are contained in both payloads.

Could you tell us what you expected to happen, and what happened instead?

We don’t know, why did you do it that way? I expect the device can only do one mode at a time, for example. So you’ll be setting mode “fire” then a few milliseconds later changing to mode “emergency”, is that what you intended?

Thanks for your quick reply.
I thought it would be like this:
By sending the settings to the device i thought the alarm would be set with the payload and first by sending the trigger, the alarm would be released and the alarm sounds.

If i send only this:

mqttActions.publishMQTT(“zigbee2mqtt/220/set”,"{“warning”:{“mode”: fire, “level”: low, “strobe”: true, “duration”: 3}}", true)

nothing happens at all
If i send only this:

mqttActions.publishMQTT(“zigbee2mqtt/220/set”,"{“warning”:{“duration”: 3, “mode”: “emergency”, “strobe”:true}}", true)

the alarm sounds/flashes for 3 seconds

What to do if i want to set the level to “low”.
Thanks in advance.

What works when you use MQTT Explorer? Or does it not work then either? From the zigbee2mqtt docs, your first example should work

{"warning": {"mode": VALUE, "level": VALUE, "strobe": VALUE, "duration": VALUE}}

Do you need to encase the VALUE for both mode and level in quotes so that you’re sending strings? Your second example has "emergency" which you said worked? So maybe try

{"warning":{"mode": "fire", "level": "low", "strobe": true, "duration": 3}}

Be aware that there are different types of quote marks in your post which will cause problems if copy/pasted: you need "" not “”