MQTT IO - forwarding GPIO resources to HomeAssistant via mqtt-io
To forward controller resources in MQTT, you can use the https://github.com/flyte/mqtt-io/ " target="_blank">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:
- < li>Using one of the CPU cores can reach 40-60% (https://github.com/flyte/mqtt-io/issues/236 " target="_blank">Issue on github )
- Unable to use GPIO concurrently via sysfs.
Installation and manual launch
Getting root
$ sudo -i
Installing mqtt-io:
# pip3 install< mqtt-io
Copy the configuration file for your controller model 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 remove export of all GPIOs in sysfs (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
Run via systemd
We assume that mqtt-io itself and /etc/mqtt-io-config.yaml are already installed.
Launch the editor:
sudo nano /etc/systemd/system/mqtt-io.service
Copy there (If you don't have JetHub D1, then ExecStartPre should be replaced with):
[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
Start the service:
sudo systemctl start mqtt-io
Check status/logs:< /p>
sudo systemctl status mqtt-io
Add to autoload:
sudo systemctl enable mqtt-io .service
View log:
sudo journalctl -u mqtt-io.service -f