Linze99
(Jan Linzmaier)
January 16, 2023, 12:32am
1
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!
JimT
(jimtng)
January 16, 2023, 4:56am
2
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.
Linze99
(Jan Linzmaier)
January 18, 2023, 10:21pm
4
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?
rlkoshak
(Rich Koshak)
January 18, 2023, 10:27pm
5
Not without more details.
How did you try to run it? Which language? UI or text files? Post the rule. Anything in the logs?
Linze99
(Jan Linzmaier)
January 18, 2023, 10:38pm
6
It turns ou that I had to choose RuleDSL instead of javascript. Now it works!
Thank you