{"id":17222345,"url":"https://github.com/fphammerle/systemctl-mqtt","last_synced_at":"2025-04-13T23:51:01.268Z","repository":{"id":38021602,"uuid":"272405671","full_name":"fphammerle/systemctl-mqtt","owner":"fphammerle","description":"MQTT client triggering \u0026 reporting shutdown on systemd-based systems :house_with_garden: 🐳","archived":false,"fork":false,"pushed_at":"2025-04-11T08:23:48.000Z","size":669,"stargazers_count":13,"open_issues_count":3,"forks_count":6,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-12T00:49:32.332Z","etag":null,"topics":["automation","home-assistant","internet-of-things","mqtt","poweroff","shutdown","systemd"],"latest_commit_sha":null,"homepage":"https://pypi.org/project/systemctl-mqtt/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fphammerle.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"COPYING","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-06-15T10:11:47.000Z","updated_at":"2025-03-28T16:19:14.000Z","dependencies_parsed_at":"2023-12-08T12:28:52.468Z","dependency_job_id":"51d14e78-1555-47ba-a13b-b28badd1b54a","html_url":"https://github.com/fphammerle/systemctl-mqtt","commit_stats":{"total_commits":150,"total_committers":2,"mean_commits":75.0,"dds":0.2466666666666667,"last_synced_commit":"9f01d04cf6832d9894fad6648fb70c525badb86b"},"previous_names":[],"tags_count":22,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fphammerle%2Fsystemctl-mqtt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fphammerle%2Fsystemctl-mqtt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fphammerle%2Fsystemctl-mqtt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fphammerle%2Fsystemctl-mqtt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fphammerle","download_url":"https://codeload.github.com/fphammerle/systemctl-mqtt/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248799904,"owners_count":21163400,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["automation","home-assistant","internet-of-things","mqtt","poweroff","shutdown","systemd"],"created_at":"2024-10-15T04:04:55.461Z","updated_at":"2025-04-13T23:51:01.258Z","avatar_url":"https://github.com/fphammerle.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# systemctl-mqtt\n\n[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)\n[![CI Pipeline Status](https://github.com/fphammerle/systemctl-mqtt/workflows/tests/badge.svg)](https://github.com/fphammerle/systemctl-mqtt/actions)\n![Coverage Status](https://ipfs.io/ipfs/QmP8k5H4MkfspFxQxdL2kEZ4QQWQjF8xwPYD35KvNH4CA6/20230429T090002+0200/s3.amazonaws.com/assets.coveralls.io/badges/coveralls_100.svg)\n[![Last Release](https://img.shields.io/pypi/v/systemctl-mqtt.svg)](https://pypi.org/project/systemctl-mqtt/#history)\n[![Compatible Python Versions](https://img.shields.io/pypi/pyversions/systemctl-mqtt.svg)](https://pypi.org/project/systemctl-mqtt/)\n[![DOI](https://zenodo.org/badge/272405671.svg)](https://zenodo.org/badge/latestdoi/272405671)\n\nMQTT client triggering \u0026 reporting shutdown on [systemd](https://freedesktop.org/wiki/Software/systemd/)-based systems\n\n## Setup\n\n### Via Pip\n\n```sh\n$ pip3 install --user --upgrade systemctl-mqtt\n```\n\nOn debian-based systems, a subset of dependencies can optionally be installed via:\n```sh\n$ sudo apt-get install --no-install-recommends python3-jeepney python3-paho-mqtt\n```\n\nFollow instructions in [systemd-user.service](systemd-user.service) to start\nsystemctl-mqtt automatically via systemd.\n\n### Via Docker Compose 🐳\n\n1. Clone this repository.\n2. Load [AppArmor](https://en.wikipedia.org/wiki/AppArmor) profile:\n   `sudo apparmor_parser ./docker-apparmor-profile`\n3. `sudo docker-compose up --build`\n\nPre-built docker image are available at https://hub.docker.com/r/fphammerle/systemctl-mqtt/tags\n\nAnnotation of signed tags `docker/*` contains docker image digests: https://github.com/fphammerle/systemctl-mqtt/tags\n\n## Usage\n\n```sh\n$ systemctl-mqtt --mqtt-host HOSTNAME_OR_IP_ADDRESS\n```\n\n`systemctl-mqtt --help` explains all available command-line options / parameters.\n\n### MQTT via TLS\n\nTLS is enabled by default.\nRun `systemctl-mqtt --mqtt-disable-tls …` to disable TLS.\n\n### MQTT Authentication\n\n```sh\nsystemctl-mqtt --mqtt-username me --mqtt-password-file /run/secrets/password …\n# or for testing (unsafe):\nsystemctl-mqtt --mqtt-username me --mqtt-password secret …\n```\n\n### Schedule Poweroff\n\nSchedule poweroff by sending a MQTT message to topic `systemctl/hostname/poweroff`.\n\n```sh\n$ mosquitto_pub -h MQTT_BROKER -t systemctl/hostname/poweroff -n\n```\n\nAdapt delay via: `systemctl-mqtt --poweroff-delay-seconds 60 …`\n\n### Shutdown Report\n\n`systemctl-mqtt` subscribes to [logind](https://freedesktop.org/wiki/Software/systemd/logind/)'s `PrepareForShutdown` signal.\n\n`systemctl halt|poweroff|reboot` triggers a message with payload `true` on topic `systemctl/hostname/preparing-for-shutdown`.\n\n### Lock Screen\n\nLock screen by sending a MQTT message to topic `systemctl/hostname/lock-all-sessions`.\n\n```\n$ mosquitto_pub -h MQTT_BROKER -t systemctl/hostname/lock-all-sessions -n\n```\n\n### Suspend\n\n```\n$ mosquitto_pub -h MQTT_BROKER -t systemctl/hostname/suspend -n\n```\n\n### Monitor `ActiveState` of System Units\n\n```\n$ systemctl-mqtt --monitor-system-unit foo.service\n```\nenables reports on topic\n`systemctl/[hostname]/unit/system/[unit_name]/active-state`.\n\n### Restarting of System Units\n\n```\n$ systemctl-mqtt  --control-system-unit \u003cunit_name\u003e\n```\nenables that a system unit can be restarted by a message on topic\n`systemctl/[hostname]/unit/system/[unit_name]/restart`.\n\n## Home Assistant 🏡\n\nWhen [MQTT Discovery](https://www.home-assistant.io/integrations/mqtt/#mqtt-discovery)\nis enabled (default in Home Assistant ≥0.117.0), the following entities will be\nadded automatically:\n- `binary_sensor.[hostname]_logind_preparing_for_shutdown`\n- `button.[hostname]_logind_lock_all_sessions`\n- `button.[hostname]_logind_poweroff`\n- `button.[hostname]_logind_suspend`\n- `sensor.[hostname]_unit_system_[unit_name]_active_state`\n  for `--monitor-system-unit [unit_name]`\n- `button.[hostname]_unit_system_[unit_name]_restart`\n  for `--control-system-unit [unit_name]`\n\n![homeassistant entities_over_auto_discovery](docs/homeassistant/entities-after-auto-discovery.png)\n\nPass `--homeassistant-discovery-prefix custom-prefix` to `systemctl-mqtt` when\nusing a custom discovery topic prefix.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffphammerle%2Fsystemctl-mqtt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffphammerle%2Fsystemctl-mqtt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffphammerle%2Fsystemctl-mqtt/lists"}