Table of Contents

FIXME This page is not fully translated, yet. Please help completing the translation.
(remove this paragraph once the translation is finished)

MQTT IO - forwarding GPIO resources to HomeAssistant via mqtt-io

To forward controller resources in MQTT, you can use the mqtt-io project.

the main advantage of this method is the use of Home Assistant MQTT discovery (entities will appear in HA without the need to manually write them in yaml)

Known issues and nuances:

Installation and manual start

Getting root

$ sudo -i

mqtt-io installation:

# pip3 install mqtt-io

The configuration file for your controller model should be copied to /etc/mqtt-io-config.yaml (don't forget to change host/user/password according to your MQTT server settings)

Before running mqtt-io, you need to remove export of all GPIOs in sysfs (the command for a specific JetHub model is indicated in the corresponding section below)

Example for JetHub D1:

# echo 436 452 453 454 455 456 462 467 469 470 471 472 | xargs -n 1 echo >/sys/class/gpio/unexport

Run mqtt-io:

# python3 -m mqtt_io /etc/mqtt-io-config.yaml

Run via systemd

We assume that mqtt-io itself and /etc/mqtt-io-config.yaml are already installed.

We start the editor:

sudo nano /etc/systemd/system/mqtt-io.service

Copy there (If you do not have JetHub D1, then you need to replace ExecStartPre):

[unit]
Description=mqtt-io
After=network.target
 
[Service]
ExecStartPre=sh -c "echo 436 452 453 454 455 456 462 467 469 470 471 472 | xargs -n 1 echo >/sys/class/gpio/unexport; exit 0"
 
ExecStart=python3 -m mqtt_io /etc/mqtt-io-config.yaml
StandardOutput=inherit
StandardError=inherit
Restart=always
user=root
 
[Install]
WantedBy=multi-user.target

We start the service:

sudo systemctl start mqtt-io

Check status/logs:

sudo systemctl status mqtt-io

Add to autoload:

sudo systemctl enable mqtt-io.service

Let's look at the log:

sudo journalctl -u mqtt-io.service -f

Configuration files and unexport for JetHub controllers