{"id":15095818,"url":"https://github.com/rainu/mqtt-executor","last_synced_at":"2025-04-14T23:08:33.757Z","repository":{"id":45088763,"uuid":"260961326","full_name":"rainu/mqtt-executor","owner":"rainu","description":"A simple MQTT client written in go that subscribes to a configurable list of MQTT topics on the specified broker and  executes a given shell script/command whenever a message arrives.","archived":false,"fork":false,"pushed_at":"2022-11-23T16:19:18.000Z","size":42,"stargazers_count":12,"open_issues_count":0,"forks_count":3,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-14T23:08:11.290Z","etag":null,"topics":["arm","command","customizable","homeassistant","iot","linux","mqtt","mqtt-client","platform-independent","windows"],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rainu.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-05-03T15:33:27.000Z","updated_at":"2025-03-03T01:44:44.000Z","dependencies_parsed_at":"2022-09-04T18:20:56.502Z","dependency_job_id":null,"html_url":"https://github.com/rainu/mqtt-executor","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rainu%2Fmqtt-executor","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rainu%2Fmqtt-executor/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rainu%2Fmqtt-executor/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rainu%2Fmqtt-executor/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rainu","download_url":"https://codeload.github.com/rainu/mqtt-executor/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248975316,"owners_count":21192209,"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":["arm","command","customizable","homeassistant","iot","linux","mqtt","mqtt-client","platform-independent","windows"],"created_at":"2024-09-25T15:42:20.290Z","updated_at":"2025-04-14T23:08:33.737Z","avatar_url":"https://github.com/rainu.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# mqtt-executor\n\n![Go](https://github.com/rainu/mqtt-executor/workflows/Go/badge.svg)\n\nA simple MQTT client written in go that subscribes to a configurable list of MQTT topics on the specified broker and \nexecutes a given shell script/command whenever a message arrives. Furthermore you can define commands that are executed \nin a configurable interval. This can be useful for sensor data. Also this application supports [Homeassitant](https://www.home-assistant.io)\n[mqtt descovery](https://www.home-assistant.io/docs/mqtt/discovery/).\n\n# Get the Binary\nYou can build it on your own (you will need [golang](https://golang.org/) installed):\n```bash\ngo build -a -installsuffix cgo ./cmd/mqtt-executor/\n```\n\nOr you can download the release binaries: [here](https://github.com/rainu/mqtt-executor/releases/latest)\n\n# Configuration\nCreate a configuration file named \"config.json\"\n```json5\n{\n  \"availability\": {\n    \"topic\": \"tele/__DEVICE_ID__/status\",\n    \"payload\": {\n      \"available\": \"On\",\n      \"unavailable\": \"Off\"\n    }\n  },\n  \"trigger\": [{\n    \"name\": \"Touch file\",\n    \"topic\": \"cmnd/touch/file\",\n    \"command\": {\n      \"name\": \"/usr/bin/touch\",\n      \"arguments\": [\"/tmp/example\"]\n    }\n  }],\n  \"sensor\": [{\n    \"name\": \"Free Memory\",\n    \"topic\": \"tele/__DEVICE_ID__/memory/free\",\n    \"retained\": false,\n    \"unit\": \"kB\",       //used for hassio\n    \"icon\": \"hass:eye\", //used for hassio\n    \"interval\": \"10s\",\n    \"command\": {\n      \"name\": \"/bin/sh\",\n      \"arguments\": [\n        \"-c\",\n        \"cat /proc/meminfo | grep MemFree | cut -d\\\\: -f2 | sed 's/ //g' | grep -o [0-9]*\"\n      ]\n    }\n  }],\n  \"multi_sensor\": [{\n    \"topic\": \"tele/__DEVICE_ID__/stats\",\n    \"retained\": false,\n    \"interval\": \"10s\",\n    \"command\": {\n      \"name\": \"/bin/sh\",\n      \"arguments\": [\n        \"echo\",\n        \"{\\\"mem\\\":1, \\\"cpu\\\":2}\"\n      ]\n    },\n    \"values\": [{\n        \"name\": \"Memory\",\n        \"unit\": \"kB\",       //used for hassio\n        \"icon\": \"hass:eye\", //used for hassio\n        \"template\": \"{{value_json.mem}}\" //used for hassio\n    },{\n        \"name\": \"CPU\",\n        \"unit\": \"%\",       //used for hassio\n        \"icon\": \"hass:eye\", //used for hassio\n        \"template\": \"{{value_json.cpu}}\" //used for hassio\n    }]\n  }]\n}\n```\n\n# Usage\n\nStart the tool with the path to the config file and the URL of the MQTT broker\n```bash\nmqtt-executor -broker tcp://127.0.0.1:1883 -config /path/to/config.json\n```\n\nEnable the Homeassitant discovery support\n```bash\nmqtt-executor -broker tcp://127.0.0.1:1883 -config /path/to/config.json -home-assistant\n```\n\n## Trigger command execution\n\nTo execute a trigger:\n\n```bash\nmosquitto_pub -t cmnd/touch/file -m \"START\"\n```\n\nTo interrupt a trigger\n```bash\nmosquitto_pub -t cmnd/touch/file -m \"STOP\"\n```\n\nRead the trigger state:\n```bash\nmosquitto_sub -t cmnd/touch/file/STATE\n```\n* RUNNING -\u003e the command is running\n* STOPPED -\u003e the command has (not) been executed\n\nRead the trigger result (command's output):\n```bash\nmosquitto_sub -t cmnd/touch/file/RESULT\n```\n\n### Get the trigger results\n\nRead the trigger state:\n```bash\nmosquitto_sub -t cmnd/touch/file/STATE\n```\n* RUNNING -\u003e the command is running\n* STOPPED -\u003e the command has (not) been executed\n\nRead the trigger result (command's output):\n```bash\nmosquitto_sub -t cmnd/touch/file/RESULT\n```\n\n## Get the (multi) sensor results\n\nRead the trigger state:\n```bash\nmosquitto_sub -t tele/+/memory/free\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frainu%2Fmqtt-executor","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frainu%2Fmqtt-executor","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frainu%2Fmqtt-executor/lists"}