ysc
(Yannick Schaus)
December 12, 2021, 4:58pm
1
This library adds a block to perform MQTT actions. You need the MQTT binding installed and a configured broker Thing.
Blocks
This block will publish the provided message on the provided topic via the specified broker, which you can select in a popup by clicking inside the thing block. Only choose a MQTT broker when picking the thing.
You can optionally retain the message on the broker.
Changelog
Version 0.1
Resources
uid: mqtt
tags: []
props:
parameters: []
parameterGroups: []
component: BlockLibrary
config:
name: MQTT
slots:
blocks:
- component: BlockType
config:
type: publish
message0: Publish MQTT message %1 on topic %2 via broker %3 %4 retain
lastDummyAlign0: right
args0:
- type: input_value
name: MESSAGE
align: right
- type: input_value
name: TOPIC
align: right
- type: input_value
name: BROKER
align: right
- type: field_checkbox
name: RETAIN
align: right
previousStatement: ""
nextStatement: ""
inputsInline: false
colour: 0
tooltip: ""
helpUrl: ""
slots:
code:
- component: BlockCodeTemplate
config:
template: >
{{utility:things}}.getActions('mqtt', {{input:BROKER}}).publishMQTT({{input:TOPIC}}, {{input:MESSAGE}}, '{{field:RETAIN}}' === 'TRUE');
toolbox:
- component: PresetInput
config:
name: MESSAGE
type: text
shadow: true
fields:
TEXT: message
- component: PresetInput
config:
name: TOPIC
type: text
shadow: true
fields:
TEXT: topic
- component: PresetInput
config:
name: BROKER
type: oh_thing
shadow: true
utilities:
- component: UtilityJavaType
config:
name: things
javaClass: org.openhab.core.model.script.actions.Things
6 Likes
Oekel
(David K.)
January 10, 2024, 10:58am
2
Sorry can you give some brainstorming for what this could be more efficient than creating a generic MQTT Item with sam cmnd topics?
The only think I can image is to upload a bunch of firmware to all groupTopics. But in this cases I am not good enough in MQTT to say where the binary is coming from
d51x
(StriboYar)
January 11, 2024, 10:22am
3
this block has the same problem that is telegram actions
openHAB 4.1.1
when I use blockly rule to determine thing status and send notification to telegram I have a problem
Script execution of rule with UID âscratchpadâ failed: org.graalvm.polyglot.PolyglotException: TypeError: invokeMember (getThing) on org.openhab.core.model.script.actions.Things failed due to: Unknown identifier: getThing
[image]
Generated code is here
var currentState;
var things = Java.type('org.openhab.core.model.script.actions.Things');
currentState = things.getThing('yaâŠ
uid: mqtt
tags:
- marketplace:129967
props:
parameters: []
parameterGroups: []
component: BlockLibrary
config:
name: MQTT
slots:
blocks:
- component: BlockType
config:
args0:
- align: right
name: MESSAGE
type: input_value
- align: right
name: TOPIC
type: input_value
- align: right
name: BROKER
type: input_value
- align: right
name: RETAIN
type: field_checkbox
colour: 0
helpUrl: ""
inputsInline: false
lastDummyAlign0: right
message0: Publish MQTT message %1 on topic %2 via broker %3 %4 retain
nextStatement: ""
previousStatement: ""
tooltip: ""
type: publish
slots:
code:
- component: BlockCodeTemplate
config:
template: >
{{utility:thingsHelper}}.getActions('mqtt', {{input:BROKER}}).publishMQTT({{input:TOPIC}}, {{input:MESSAGE}}, '{{field:RETAIN}}' === 'TRUE');
toolbox:
- component: PresetInput
config:
fields:
TEXT: message
name: MESSAGE
shadow: true
type: text
- component: PresetInput
config:
fields:
TEXT: topic
name: TOPIC
shadow: true
type: text
- component: PresetInput
config:
name: BROKER
shadow: true
type: oh_thing
utilities:
- component: UtilityJavaType
config:
javaClass: org.openhab.core.model.script.actions.Things
name: thingsHelper
binderj1
(Johannes Binder)
September 19, 2024, 3:25pm
4
Is there also a âsubscribe MQTT messageâ block?
rlkoshak
(Rich Koshak)
September 19, 2024, 3:38pm
5
No, you have to create a Generic MQTT Thing with a Channel to subscribe to messages.
It makes no sense to subscribe to a topic in a rule so the MQTT binding doesnât implement such an action.
s0170071
(S0170071)
August 17, 2025, 8:56am
6
Ahhh, this is for the blocky language. I was wondering all along what this is. It should say so in the addon store. It has the same icon as the mqtt binding too.
rlkoshak
(Rich Koshak)
August 18, 2025, 2:33pm
7
It is in the Block Library category. Everything posted in Add-on Marketplace â Block Libraries is for Blockly. In MainUI â Add-on Store ->Automation, everything under the âBlock Librariesâ is for Blockly.
s0170071
(S0170071)
August 18, 2025, 5:50pm
8
That you donât see if you search for mqtt