Sending MQTT Command with script

Hi,

I have a seamingly basic question:

How can I publish a MQTT Message with a script?`

The only thing I found was this:
var actions = getActions(“mqtt”,“mqtt:broker:MQTTBroker”)
actions.publishMQTT(“/Test/HelloWorld”)

My MQTT Brokers UID is “mqtt:broker:MQTTBroker”. All other mqtt stuff I did so far with openhab works just fine. Why isnt this script working? Is there another solution?

Thanks in advance!

Did you forget the payload? Is the topic correct? All the mqtt topics I’ve come across so far don’t start with a slash.

I assume you are using some 3rd part MQTT client to monitor Broker.

Try

val mqttActions = getActions("mqtt","mqtt:broker:MQTTBroker")
mqttActions.publishMQTT("mytopic","myvalue", true)

Then you should see myvalue in mytopic topic.

First of all thanks for the answers.
I can indeed monitor all messages with a 3rd party MQTT Client.

Unfortunately your solution didnt work. I put the code in a script and treid to run it. No message was sent to the mqtt network.

Any ideas why it doesnt work?

Not without more details.

How did you try to run it? Which language? UI or text files? Post the rule. Anything in the logs?

It turns ou that I had to choose RuleDSL instead of javascript. Now it works!
Thank you