Skip to content

MQTT Configuration

Ellis Percival edited this page Jan 20, 2021 · 2 revisions

This section, unsurprisingly, handles all of the configuration for the software's connection to the MQTT server.

Configuration Elements

host

Host name or IP of the server to connect to.

port

Port on which to connect to the server on.

user

Username to use.

password

Password to use.

client_id

Client ID to use. If not provided, this is configured automatically by the software to be pi-mqtt-gpio- plus the hashed value of the configured topic_prefix configuration option. This default ensures that each instance of the software connected to the MQTT server receives the same client ID and session when they occupy the same set of topics as defined by topic_prefix. This deliberately forces only one instance of the software to run on a given topic_prefix at a given time in order to avoid confusing accidents.

If for some reason you'd like to run multiple instances of the software on a given topic_prefix then you may set the client_id here manually. However, this behaviour is not supported and may well cause weird behaviour.

topic_prefix

Prefix to prepend to every topic used by the software. You must use this to differentiate multiple instances of the software connecting to the same MQTT server.

For example, you may have one Raspberry Pi that controls your living room lights using the prefix home/livingroom/lights and another one detecting when your doorbell has been pressed on home/doorbell. All topics used by this software will be prefixed by these values, so you'd publish to home/livingroom/lights/output/tv_lamp/set to switch the TV lamp on and off, and you'd subscribe to home/doorbell/input/doorbell to receive messages when your doorbell has been pushed.

protocol

Which version of the MQTT protocol to use as specified in the paho-mqtt documentation, but the values are one of the following:

  • 3.1
  • 3.1.1

status_topic

The software will publish its status on this topic (prefixed by topic_prefix) with payloads of running, stopped and dead, which can be overridden with status_payload_running, status_payload_stopped and status_payload_dead respectively.

status_payload_running

Payload for status messages sent when the software starts running.

status_payload_stopped

Payload for status messages sent when the software is stopped and disconnects from the MQTT server cleanly.

status_payload_dead

Payload for status messages sent (by Last Will and Testament setting) when the software disconnects from the MQTT server without shutting down properly.

discovery

Boolean value to enable Home Assistant Discovery, which is off by default.

discovery_prefix

Topic prefix to send Home Assistant Discovery payloads to. Defaults to homeassistant.

discovery_name

What name to announce to Home Assistant when publishing discovery payloads. Defaults to MQTT GPIO.

tls

This is a dict subsection that contains all TLS encryption settings, when using an encrypted connection to the MQTT server.

See the MQTT TLS page for details of these settings.