Home Assistant Companion for Linux - a background service that exposes your Linux system's state to Home Assistant via MQTT.
Inspired by the Home Assistant iOS app.
| Sensor | Type | Description | Requirements |
|---|---|---|---|
online |
binary_sensor | System online/offline status | None (uses MQTT LWT) |
microphone |
binary_sensor | Microphone in use | PulseAudio or PipeWire |
webcam |
binary_sensor | Webcam in use | None |
wifi_ssid |
sensor | Current WiFi network name | iwgetid or NetworkManager |
location |
device_tracker | GPS coordinates | GeoClue2 |
distro |
sensor | Linux distribution name | None |
The WiFi SSID sensor automatically detects the distribution and uses nmcli on Fedora/RHEL-based systems, falling back to iwgetid on others.
- Home Assistant MQTT Discovery (auto-registers entities)
- Per-sensor configurable poll intervals
- MQTT Last Will and Testament for reliable offline detection
- Systemd integration
Planned:
- Idle/active detection
- Suspend/resume detection
- Battery status
- Linux with systemd
- Python 3.10+
- MQTT broker (e.g., Mosquitto)
- Home Assistant with MQTT integration
Optional (for specific sensors):
- PulseAudio or PipeWire (
pactl) - for microphone sensor iwgetidor NetworkManager (nmcli) - for WiFi SSID sensor- GeoClue2 (
gdbus) - for location sensor
-
Download the latest release tarball from the Releases page
-
Extract and install:
tar -xzf ha-linux-*.tar.gz cd ha-linux-* sudo ./scripts/install.sh
-
Edit the configuration:
sudo nano /etc/ha-linux/config.yaml
-
Enable and start the service:
sudo systemctl enable ha-linux sudo systemctl start ha-linux
git clone https://github.com/alastairm/ha-linux.git
cd ha-linux
pip install -e ".[dev]"Run locally with a custom config:
ha-linux -c ./config.example.yaml -vConfiguration is stored in /etc/ha-linux/config.yaml:
mqtt:
host: "192.168.1.100"
port: 1883
username: "ha-linux"
password: "your-password"
device:
name: "My Linux PC" # Optional, defaults to hostname
# Each sensor can be:
# false - disabled
# true - enabled with default poll_interval
# <number> - enabled with custom poll interval (seconds)
sensors:
poll_interval: 60 # Default poll interval (seconds)
online: true # System online/offline
microphone: 5 # Poll every 5 seconds
webcam: 5
wifi_ssid: true
location: 300 # Poll every 5 minutes
distro: true # Linux distributionOnce the service is running, your device will automatically appear in Home Assistant via MQTT Discovery.
Device: "Linux Companion - <hostname>"
Entities:
binary_sensor.<hostname>_online- ON when system is runningbinary_sensor.<hostname>_microphone- ON when mic is in usebinary_sensor.<hostname>_webcam- ON when camera is in usesensor.<hostname>_wifi_ssid- Current network name or "disconnected"device_tracker.<hostname>_location- GPS coordinates with lat/lon attributessensor.<hostname>_distro- Linux distribution (e.g., "Fedora Linux 41")
The online sensor uses MQTT's Last Will and Testament feature, so Home Assistant will correctly show the device as unavailable when it goes offline unexpectedly.
The location sensor requires GeoClue2. On most systems it's installed but may need configuration.
-
Ensure GeoClue2 is installed:
# Fedora/RHEL sudo dnf install geoclue2 # Debian/Ubuntu sudo apt install geoclue-2.0
-
Add ha-linux to allowed apps in
/etc/geoclue/geoclue.conf:[ha-linux] allowed=true system=true users=
-
Restart GeoClue:
sudo systemctl restart geoclue
# Check status
sudo systemctl status ha-linux
# View logs
journalctl -u ha-linux -f
# Restart service
sudo systemctl restart ha-linux
# Stop service
sudo systemctl stop ha-linuxsudo /opt/ha-linux/scripts/uninstall.shOr if you still have the tarball extracted:
sudo ./scripts/uninstall.shMIT