A home automation switch augmented with Home Assistant MQTT discovery protocol.
sudo apt-get install libjson-c-dev libpaho-mqtt-dev
sudo apt-get install build-essential libssl-dev cmake gcc make cmake-gui cmake-curses-gui libssl-dev doxygen graphviz
For UPnP functionality:
sudo apt-get install miniupnpc
Compile the project using:
gcc -o mqt_hook mqt_hook.c config.c -ljson-c -lpaho-mqtt3c
- Create a systemd service file:
sudo nano /etc/systemd/system/mqt_hook.service
- Add the following content to /etc/systemd/system/mqt_hook.service
[Unit]
Description=MQTT Hook Service
After=network.target
[Service]
Environment="MQTT_HOST=your_mqtt_host"
Environment="MQTT_USERNAME=your_username"
Environment="MQTT_PASSWORD=your_password"
ExecStart=/home/pi/c/mqt_hook/mqt_hook
WorkingDirectory=/home/pi/c/mqt_hook
Restart=always
RestartSec=30
User=pi
Group=pi
Environment="LD_LIBRARY_PATH=/usr/local/lib"
StandardOutput=journal
StandardError=journal
[Install]
WantedBy=multi-user.target
Note: You can optionally specify a config file path: /home/pi/c/mqt_hook/config.json
Check service status:
sudo systemctl status mqt_hook.service
Restart service:
sudo systemctl restart mqt_hook.service
View service logs:
sudo journalctl -f -n 100 | grep mqt_hook