systemctl-mqtt
MQTT client triggering & reporting shutdown on systemd-based systems
Setup
Via Pip
$ pip3 install --user --upgrade systemctl-mqtt
On debian-based systems, a subset of dependencies can optionally be installed via:
$ sudo apt-get install --no-install-recommends python3-jeepney python3-paho-mqtt
Follow instructions in systemd-user.service to start systemctl-mqtt automatically via systemd.
Via Docker Compose 🐳
- Clone this repository.
- Load AppArmor profile:
sudo apparmor_parser ./docker-apparmor-profile sudo docker-compose up --build
Pre-built docker image are available at https://hub.docker.com/r/fphammerle/systemctl-mqtt/tags
Annotation of signed tags docker/* contains docker image digests: https://github.com/fphammerle/systemctl-mqtt/tags
Usage
$ systemctl-mqtt --mqtt-host HOSTNAME_OR_IP_ADDRESS
systemctl-mqtt --help explains all available command-line options / parameters.
MQTT via TLS
TLS is enabled by default.
Run systemctl-mqtt --mqtt-disable-tls … to disable TLS.
MQTT Authentication
systemctl-mqtt --mqtt-username me --mqtt-password-file /run/secrets/password …
# or for testing (unsafe):
systemctl-mqtt --mqtt-username me --mqtt-password secret …
Schedule Poweroff
Schedule poweroff by sending a MQTT message to topic systemctl/hostname/poweroff.
$ mosquitto_pub -h MQTT_BROKER -t systemctl/hostname/poweroff -n
Adapt delay via: systemctl-mqtt --poweroff-delay-seconds 60 …
Shutdown Report
systemctl-mqtt subscribes to logind's PrepareForShutdown signal.
systemctl halt|poweroff|reboot triggers a message with payload true on topic systemctl/hostname/preparing-for-shutdown.
Lock Screen
Lock screen by sending a MQTT message to topic systemctl/hostname/lock-all-sessions.
$ mosquitto_pub -h MQTT_BROKER -t systemctl/hostname/lock-all-sessions -n
Suspend
$ mosquitto_pub -h MQTT_BROKER -t systemctl/hostname/suspend -n
Monitor ActiveState of System Units
$ systemctl-mqtt --monitor-system-unit foo.service
enables reports on topic
systemctl/[hostname]/unit/system/[unit_name]/active-state.
Control System Units
$ systemctl-mqtt --control-system-unit <unit_name>
enables that a system unit can be started, stopped, restarted and isolated by a message on topic
systemctl/[hostname]/unit/system/[unit_name]/start, …/stop, …/restart, …/isolate.
Home Assistant 🏡
Note: Home Assistant 2025.10+ is required for MQTT Discovery of
systemctl-mqttentities.
When MQTT Discovery is enabled (default in Home Assistant ≥0.117.0), the following entities will be added automatically:
binary_sensor.[hostname]_logind_preparing_for_shutdownbutton.[hostname]_logind_lock_all_sessionsbutton.[hostname]_logind_poweroffbutton.[hostname]_logind_suspendsensor.[hostname]_unit_system_[unit_name]_active_statefor--monitor-system-unit [unit_name]button.[hostname]_unit_system_[unit_name]_startfor--control-system-unit [unit_name]button.[hostname]_unit_system_[unit_name]_stopfor--control-system-unit [unit_name]button.[hostname]_unit_system_[unit_name]_restartfor--control-system-unit [unit_name]button.[hostname]_unit_system_[unit_name]_isolatefor--control-system-unit [unit_name], when the unit allows isolation (e.g., targets)
Pass --homeassistant-discovery-prefix custom-prefix to systemctl-mqtt when
using a custom discovery topic prefix.
Release files for systemctl-mqtt 3.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| systemctl_mqtt-3.0.0.tar.gz | 96.3 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| systemctl_mqtt-3.0.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 128.7 kB
Release files / systemctl_mqtt-3.0.0.tar.gz
| Download URL | systemctl_mqtt-3.0.0.tar.gz |
|---|---|
| Size | 96.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
43dc12d95df0ccac357ecf50e6b0914352a029ab374a4d0cc25c43b08a28fdd3
|
|
BLAKE2b-256 checksum How to use checksums |
9482660d0611c464eeb2645628ffcba037d22a751f30516fbe1cebdda4cd8b01
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.5
|
Release files / systemctl_mqtt-3.0.0-py3-none-any.whl
| Download URL | systemctl_mqtt-3.0.0-py3-none-any.whl |
|---|---|
| Size | 32.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
363e5b38e18aca9909eb08225a4e1b90e7ce83598b9cb193737c2521f30e21f9
|
|
BLAKE2b-256 checksum How to use checksums |
c09444de9fdc63234090a3b4fb2089e299968e27350e3e84d7d1e1f54832c32c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.5
|