MQTT Actions

logo

This library adds a block to perform MQTT actions. You need the MQTT binding installed and a configured broker Thing.

Blocks

image

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

  • initial release

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

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 :wink:

this block has the same problem that is telegram actions

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

Is there also a “subscribe MQTT message” block?

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.