Overview MQTT Addresses I/O – Integration with Node-RED and Home Assistant


This page describes step by step how third-party systems such as Node-RED and Home Assistant are connected to the uni-PRO controller via the function block MQTT Addresses I/O. The block sends the values of the variables (addresses) as MQTT messages to an MQTT broker and, in the other direction, accepts values that third-party systems send to the broker.

Overview MQTT integration

Important: For this function the controller must have an image version 3.034 or higher.

MQTT basics

MQTT is a simple messaging protocol for building and device automation. All participants connect to a central server, the broker:

Structure of the MQTT messages of the block

The topic is built from the parameter "Topic prefix" (default "uniPRO") and the address main group/middle group/sub group:

Topic uniPRO/100/10/1  (address 100/10/1)
Payload sent Numeric value, e.g. "21.5". Bit variables according to the parameter "Type bit variable" as "0/1", "on/off" or "true/false". Text variables are sent as text.
Payload received "on" and "true" are accepted as 1, "off" and "false" as 0, everything else as a numeric value. For text variables the text is accepted.

Only addresses of the main groups set in the parameter "Filter main group" are sent and received.

Configuring the block

  1. Insert the function block "MQTT Addresses I/O" into the program.
  2. Server type:
  3. Filter main group: Specify the main groups of the variables to be transferred, several separated by semicolons, e.g. "100;101".
  4. Leave "Update on start" and "Retain" activated so that third-party systems always have current values.

All parameters in detail: help MQTT Addresses I/O. To check the messages, the MQTT diagnosis in the Studio can be used (menu Diagnosis).


Node-RED

Node-RED is a graphical tool for building sequences (flows) from building blocks (nodes) using drag & drop. It runs e.g. on a Raspberry Pi, a server or in Docker. The installation is described here: nodered.org/docs/getting-started. After installation the editor is opened in the browser at "http://<IP-address>:1880".

The MQTT nodes

The MQTT nodes are a core part of Node-RED and do not need to be installed separately. They can be found in the palette on the left in the "network" category:

If additional nodes are required (e.g. dashboards), they can be installed via menu (☰) → "Manage palette".

Creating the broker connection

Drag an "mqtt in" node into the flow and open it by double-clicking. Next to "Server", create a new mqtt-broker configuration using the pencil icon:

Node-RED mqtt-broker configuration

The configuration only needs to be created once and can then be selected in all MQTT nodes.

Receiving values (mqtt in)

Node-RED mqtt in configuration

Sending values (mqtt out)

Node-RED mqtt out configuration

Example flow

Node-RED example flow

  1. Connect an "mqtt in" node (topic "uniPRO/#") to a "debug" node.
  2. Connect an "inject" node (payload e.g. number 21.5) to an "mqtt out" node (topic "uniPRO/100/10/1").
  3. Click "Deploy" at the top right. "connected" must appear below the MQTT nodes.
  4. Received values appear in the debug sidebar (bug icon on the right). Clicking the inject node sends the value to uni-PRO.

Further examples: Node-RED cookbook MQTT, documentation: nodered.org/docs.


Home Assistant

Home Assistant is an open source software for home automation. The MQTT integration of Home Assistant is used for the connection.

MQTT broker

Home Assistant and the uni-PRO block must use the same broker. Two options:

Setting up the MQTT integration

In Home Assistant: Settings → Devices & services → Add integration, search for "MQTT" and enter the connection data of the broker:

Home Assistant MQTT setup

Automatic integration (auto discovery)

If the parameter "Home Assistant Auto Discovery" is activated in the block, the block sends a configuration message to Home Assistant for each variable. The variables then appear automatically as entities of type "number"; the name of the entity is the comment of the address:

Home Assistant entity

Important: With auto discovery activated, the parameter "Topic prefix" must remain at the default value "uniPRO", because the automatically generated configuration uses these topics. Currently only entities of type "number" are created; all values are then transferred as numbers.

Manual integration (configuration.yaml)

Alternatively (or additionally, e.g. for switches), entities can be created manually in the file configuration.yaml. Example for a sensor and a switch:

mqtt:
  sensor:
    - name: "Living room temperature"
      state_topic: "uniPRO/100/10/1"
      unit_of_measurement: "°C"
  switch:
    - name: "Light living room"
      state_topic: "uniPRO/101/1/1"
      command_topic: "uniPRO/101/1/1"
      payload_on: "1"
      payload_off: "0"

payload_on/payload_off must match the parameter "Type bit variable" of the block (e.g. "on"/"off" instead of "1"/"0"). After changes to configuration.yaml, Home Assistant must be restarted. Details: Home Assistant MQTT documentation.

Testing

Under Settings → Devices & services → MQTT → Configure, Home Assistant offers a test tool: With "Listen to a topic" and the topic "uniPRO/#" all messages of the block are displayed. Via "Publish a packet" a value can be sent to an address for testing (topic e.g. "uniPRO/100/10/1", payload "21.5").


Troubleshooting tips

Note: Node-RED, Home Assistant and Mosquitto are third-party products. The user is responsible for the installation, operation and security of this software; the linked documentation may change.


See also function block MQTT Addresses I/O.