{"id":15728261,"url":"https://github.com/rytilahti/mqtt-bridge","last_synced_at":"2026-05-11T02:04:49.486Z","repository":{"id":226448047,"uuid":"768360209","full_name":"rytilahti/mqtt-bridge","owner":"rytilahti","description":"\"mqtt-bridge\" -- execute shell commands on incoming MQTT messages","archived":false,"fork":false,"pushed_at":"2024-03-07T14:24:04.000Z","size":32,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-25T03:25:15.823Z","etag":null,"topics":["home-assistant","mqtt","rust"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rytilahti.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2024-03-06T23:58:43.000Z","updated_at":"2024-03-08T15:44:34.000Z","dependencies_parsed_at":null,"dependency_job_id":"aa41eb96-76ac-48d3-b6bb-182adb817c7f","html_url":"https://github.com/rytilahti/mqtt-bridge","commit_stats":{"total_commits":1,"total_committers":1,"mean_commits":1.0,"dds":0.0,"last_synced_commit":"56e6a095d588d0168acb1d07715c044194c8ae7c"},"previous_names":["rytilahti/mqtt-bridge"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rytilahti%2Fmqtt-bridge","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rytilahti%2Fmqtt-bridge/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rytilahti%2Fmqtt-bridge/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rytilahti%2Fmqtt-bridge/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rytilahti","download_url":"https://codeload.github.com/rytilahti/mqtt-bridge/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246403902,"owners_count":20771527,"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":["home-assistant","mqtt","rust"],"created_at":"2024-10-03T23:01:45.726Z","updated_at":"2026-05-11T02:04:44.461Z","avatar_url":"https://github.com/rytilahti.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003e [!CAUTION]\n\u003e This project was made as a quick \"hello world\" project to learn a bit about rust and its ecosystem.\n\u003e Not aimed for production use, but feel free to use and experiment [without guarantees](https://fi.wiktionary.org/wiki/per%C3%A4valotakuu).\n\n## \"mqtt-bridge\" -- execute predefined shell commands on incoming MQTT messages\n\n- **What:** a simple daemon written in rust, that executes pre-defined shell commands when MQTT topic gets a message.\n- **Why:** to allow home automation systems like Home Assistant to trigger some actions on your computer, e.g., turning off the display when the lights are turned off.\n\nAll exposed commands are also advertised using the [Home Assistant's MQTT discovery protocol](https://www.home-assistant.io/integrations/mqtt#mqtt-discovery) as buttons,\nmaking them accessible out-of-the-box without any further configuration.\n\n![Screenshot](screenshot.png)\n\n### Usage\n\n```\n$ mqtt-bridge --help\n\n\"mqtt-bridge\" -- execute predefined shell commands on incoming MQTT messages\n\nUsage: mqtt-bridge [OPTIONS]\n\nOptions:\n  -c, --config \u003cCONFIG\u003e  Configuration file [default: config.yaml]\n  -d, --debug...         Debug level, more is more\n  -h, --help             Print help\n  -V, --version          Print version\n```\n\n### Configuration\n\nThe actions defined in the configuration file are made callable under MQTT topics following the format `mqttbridge/\u003cinstance_name\u003e/\u003cslugified_action_name\u003e/call`.\nWith the following configuration, sending a message to `mqttbridge/moin/sleep_some/call` will execute the `sleep` command.\n\n```\nmqtt:\n  host: 192.0.2.123\n  username: admin\n  password: nimda\n  instance_name: moin\nactions:\n  - name: Turn screen off\n    icon: mdi:power\n    command: /usr/bin/dbus-send --session --print-reply --dest=org.kde.kglobalaccel /component/org_kde_powerdevil org.kde.kglobalaccel.Component.invokeShortcut string:'Turn Off Screen'\n  - name: Sleep some\n    command: /usr/bin/sleep 10\n```\n\n\u003e [!NOTE]\n\u003e If `instance_name` is not defined in the configuration, hostname is used instead.\n\n### systemd config\n\nModify `mqttbridge.service` to contain the correct path to the compiled binary, link or copy to the unit directory, and start it.\n\n```\nln -s $(realpath mqttbridge.service) ~/.config/systemd/user/\nsystemctl --user start mqttbridge\nsystemctl --user enable mqttbridge\n```\n\n### Used libraries\n\nThis project leverages several external crates, including:\n\n- `runmqttc` for mqtt connectivity\n- `log`, `env_logger` for logging\n- `dirs` for locating the config\n- `tokio` for asyncio\n- `clap` for cli arg handling\n- `serde`, `serde_{json,yaml}` for serialization and deserialization\n- `gethostname` to use hostname as a unique id\n- `shlex` for parsing the commands\n\n### TODO\n\n- [ ] Error handling and fault tolerance (broker failures, invalid creds, general failures, ..)\n- [ ] [Tests](https://rust-cli.github.io/book/tutorial/testing.html)\n- [ ] [Package](https://rust-cli.github.io/book/tutorial/packaging.html) and publish?\n\n### Links\n\nSome resources that I found useful while hacking this together, in no specific order.\n\n- [The Rust Programming Language](https://doc.rust-lang.org/book/)\n- [Rust by Example](https://doc.rust-lang.org/rust-by-example)\n- [Carefully exploring Rust as a Python developer](https://karimjedda.com/carefully-exploring-rust/)\n- [py2rs - From Python into Rust](https://rochacbruno.github.io/py2rs/)\n- [hamatti's learning rust series](https://hamatti.org/posts/learning-rust-pattern-matching/)\n- [Command line apps in Rust](https://rust-cli.github.io/book/)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frytilahti%2Fmqtt-bridge","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frytilahti%2Fmqtt-bridge","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frytilahti%2Fmqtt-bridge/lists"}