MQTT Alive Daemon reports the status of your computer and custom commands to Home Assistant via MQTT. It's designed to be lightweight, easy to configure, and deployable across multiple machines.
- Aliveness Reporting: Regularly reports if the computer is online and running the daemon.
- Custom Command Monitoring: Execute and report the status of user-defined commands.
- Home Assistant Integration: Uses MQTT discovery for seamless integration with Home Assistant.
- Multi-Machine Deployment: Automatically generates a unique client ID for each machine, allowing easy deployment across multiple computers.
- Flexible Configuration: Simple YAML configuration file for easy setup and modification.
With MQTT Alive Daemon, you can monitor various aspects of your computer(s) in Home Assistant, such as:
-
USB Device Connection: Check if specific USB devices are connected.
Example command:lsusb | grep "Device Name"
(Linux)
Example command:ioreg -p IOUSB -l -w 0 | grep "Device Name"
(macOS) -
Disk Space: Monitor available disk space.
Example command:df -h / | awk 'NR==2 {print $5}' | sed 's/%//' | awk '$1 < 90 {exit 1}'
-
Process Running: Check if a particular process is running.
Example command:pgrep -x "process_name" > /dev/null && echo "Running" || echo "Not running"
-
Network Connectivity: Test connection to a specific host.
Example command:ping -c 1 example.com > /dev/null && echo "Reachable" || echo "Unreachable"
-
Temperature Monitoring: Report CPU temperature (on supported systems).
Example command:sensors | grep "CPU Temperature" | awk '{print $3}' | cut -c2-3
-
Battery Status: Check laptop battery level (on supported systems).
Example command:pmset -g batt | grep -Eo "\d+%" | cut -d% -f1
- Go 1.16 or later
- Git
- Root access (sudo)
-
Clone the repository:
git clone https://github.com/crmne/mqtt-alive-daemon.git cd mqtt-alive-daemon
-
Build and install the application:
make install
This command will:
- Build the application
- Install the binary to
/usr/local/bin
- Copy an example configuration file to the appropriate location
- Set up and start the system service (launchd on macOS, systemd on Linux)
-
Edit the configuration file:
- On macOS:
/usr/local/etc/mqtt-alive-daemon/config.yaml
- On Linux:
/etc/mqtt-alive-daemon/config.yaml
- On macOS:
To uninstall the application and remove all associated files:
sudo make uninstall
The daemon looks for the configuration and device files in the following locations (in order):
/etc/mqtt-alive-daemon/
/usr/local/etc/mqtt-alive-daemon/
~/.config/mqtt-alive-daemon/
~/Library/Application Support/mqtt-alive-daemon/
(macOS only)
The main configuration file is named config.yaml
, and the device-specific configuration is stored in device_config.json
.
Edit the config.yaml
file:
mqtt_broker: "mqtt://your-mqtt-broker:1883"
mqtt_username: "your_username"
mqtt_password: "your_password"
device_name: "My Computer"
interval: 10
commands:
usb_audio:
command: "lsusb | grep 'Audio Device'"
device_class: "plug"
disk_space:
command: "df -h / | awk 'NR==2 {print $5}' | sed 's/%//' | awk '$1 < 90 {exit 1}'"
device_class: "problem"
The device_config.json
file is automatically generated and managed by the application. It stores a unique client ID for each machine, allowing for multi-machine deployment.
After installation and configuration, the daemon will start automatically on system boot. You can manually start, stop, or check the status of the service:
-
On macOS:
sudo launchctl load /Library/LaunchDaemons/me.paolino.mqtt-alive-daemon.plist sudo launchctl unload /Library/LaunchDaemons/me.paolino.mqtt-alive-daemon.plist sudo launchctl list | grep mqtt-alive-daemon
-
On Linux:
sudo systemctl start mqtt-alive-daemon sudo systemctl stop mqtt-alive-daemon sudo systemctl status mqtt-alive-daemon
To build the application without installing:
make build
To run tests:
make test
To clean up build artifacts:
make clean
The daemon will automatically create binary sensors in Home Assistant for the aliveness check and each configured command. You can use these sensors in automations, scripts, or display them on your dashboard.
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License.