MQTT client triggering & reporting shutdown on systemd-based systems
Project description
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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file systemctl_mqtt-3.0.0.tar.gz.
File metadata
- Download URL: systemctl_mqtt-3.0.0.tar.gz
- Upload date:
- Size: 96.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
43dc12d95df0ccac357ecf50e6b0914352a029ab374a4d0cc25c43b08a28fdd3
|
|
| MD5 |
96afecb458eff5857e449ef65c3807b9
|
|
| BLAKE2b-256 |
9482660d0611c464eeb2645628ffcba037d22a751f30516fbe1cebdda4cd8b01
|
File details
Details for the file systemctl_mqtt-3.0.0-py3-none-any.whl.
File metadata
- Download URL: systemctl_mqtt-3.0.0-py3-none-any.whl
- Upload date:
- Size: 32.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
363e5b38e18aca9909eb08225a4e1b90e7ce83598b9cb193737c2521f30e21f9
|
|
| MD5 |
0c993d2d4eb80250a5b1d5416e9a8f17
|
|
| BLAKE2b-256 |
c09444de9fdc63234090a3b4fb2089e299968e27350e3e84d7d1e1f54832c32c
|