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:

  • The load of one of the CPU cores can reach 40-60% ( Issue on github )
  • Impossibility of simultaneous use of GPIO through sysfs.

Installation and manual start

Getting root

 $ sudo -i

mqtt-io installation:

 # pip3 install < mqtt-io

The configuration file for your controller model needs to 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 the export of all GPIOs in sysfs (the command for a specific JetHub model is listed in the appropriate 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

Running 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

We copy there ( If you do not have JetHub D1, then ExecStartPre needs to be replaced ):

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

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