{"id":17526677,"url":"https://github.com/ayavilevich/mqtt-win-exec","last_synced_at":"2025-03-06T06:30:39.356Z","repository":{"id":182319387,"uuid":"311638279","full_name":"ayavilevich/mqtt-win-exec","owner":"ayavilevich","description":"An agent to execute commands in response to mqtt messages and publish output of commands to mqtt topics","archived":false,"fork":false,"pushed_at":"2023-11-03T13:12:58.000Z","size":61,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-05-17T02:57:14.478Z","etag":null,"topics":["automation","execution","hass","home-assistant","mqtt","pc","windows"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/ayavilevich.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}},"created_at":"2020-11-10T11:32:00.000Z","updated_at":"2024-05-17T02:57:14.479Z","dependencies_parsed_at":null,"dependency_job_id":"9bad9d17-2423-4271-805f-18605290eacd","html_url":"https://github.com/ayavilevich/mqtt-win-exec","commit_stats":null,"previous_names":["ayavilevich/mqtt-win-exec"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ayavilevich%2Fmqtt-win-exec","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ayavilevich%2Fmqtt-win-exec/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ayavilevich%2Fmqtt-win-exec/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ayavilevich%2Fmqtt-win-exec/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ayavilevich","download_url":"https://codeload.github.com/ayavilevich/mqtt-win-exec/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":242161249,"owners_count":20081832,"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","execution","hass","home-assistant","mqtt","pc","windows"],"created_at":"2024-10-20T15:02:11.836Z","updated_at":"2025-03-06T06:30:39.347Z","avatar_url":"https://github.com/ayavilevich.png","language":"JavaScript","readme":"# mqtt-win-exec\nAn agent to execute commands in response to mqtt messages and publish result of command executions.\n\nOne example of use would be in a home automation scenario. You can install this tool on a Windows or linux machine and then control it centrally from Home Assistant or a similar software. You would also need a MQTT broker.\n\nThis tool only executes pre-defined set of commands. This is by design due to security considerations.\n\nThis was developed with Windows in mind as linux machines have more options from the get-go but it should run on any platform that is supported by nodejs. You would need to define proper command for your OS, of course.\n\n## Installation instructions\n\nHave git and the node runtime installed (https://nodejs.org/). If you prefer not to install git you can download the zip and expand it manually.\n\n```\ngit clone https://github.com/ayavilevich/mqtt-win-exec  \ncd mqtt-win-exec  \nnpm i  \n```\n\nCreate a `.env` based on `.env.sample`.  \nCreate a `topics.json5` based on `topics.sample.json5` and reference it in the `.env`.  \n\n```\nnode index.js\n```\n\nSee that it works. Check that you are able to get and send mqtt messages. If all is correct, install as a service on Windows:\n\n```\nnode windows-service-install.js\n```\n\nThis will run the Windows 'net' command several times as an Administrator to add and configure the new service.\n\nIf you don't see the service appearing in the Windows Services screen, run uninstall and then install again from a command prompt running \"as administrator\".\n\n## TODO\n\nNone at this time\n\n## Troubleshooting\n\nMQTT can be debugged per https://github.com/mqttjs/MQTT.js/blob/master/README.md#debug-logs , by setting the 'DEBUG' env var to 'mqttjs*'.\n\nThis can be set on a service by adding:\n\n```\n\tenv: [{\n\t\tname: \"DEBUG\",\n\t\tvalue: \"mqttjs*\",\n\t}],\n```\n\nto the windows-service-install.js script, then uninstalling and re-installing the service. Debug output of the service then goes to .\\daemon\\mqttwinexec.err.log .\n\n## Some useful powershell scripts that you can use with this executor\n\nupdates.ps1\n\n```\n$u = New-Object -ComObject Microsoft.Update.Session\n$u.ClientApplicationID = 'MSDN Sample Script'\n$s = $u.CreateUpdateSearcher()\n$r = $s.Search(\"IsInstalled=0 and Type='Software' and IsHidden=0\")\n#$r = $s.Search('IsInstalled=0')\n$r.updates|Select-Object -ExpandProperty Title\n```\n\nnotification.ps1\n\n```\nparam (\n\t[string]$notificationTitle = \"Notification: \" + [DateTime]::Now.ToShortTimeString()\n)\n\n$ErrorActionPreference = \"Stop\"\n\n[Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime] \u003e $null\n$template = [Windows.UI.Notifications.ToastNotificationManager]::GetTemplateContent([Windows.UI.Notifications.ToastTemplateType]::ToastText01)\n\n#Convert to .NET type for XML manipuration\n$toastXml = [xml] $template.GetXml()\n$toastXml.GetElementsByTagName(\"text\").AppendChild($toastXml.CreateTextNode($notificationTitle)) \u003e $null\n\n#Convert back to WinRT type\n$xml = New-Object Windows.Data.Xml.Dom.XmlDocument\n$xml.LoadXml($toastXml.OuterXml)\n\n$toast = [Windows.UI.Notifications.ToastNotification]::new($xml)\n$toast.Tag = \"PowerShell\"\n$toast.Group = \"PowerShell\"\n$toast.ExpirationTime = [DateTimeOffset]::Now.AddSeconds(5)\n#$toast.SuppressPopup = $true\n\n$notifier = [Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier(\"PowerShell\")\n$notifier.Show($toast);\n```\n\n## Credits\n\nInspired by\n\nhttps://gitlab.com/iotlink/iotlink  \nhttps://github.com/denschu/mqtt-exec  \nhttps://github.com/msiedlarek/winthing  \nhttps://github.com/jpmens/mqtt-launcher  \nhttps://github.com/rainu/mqtt-executor  \n","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fayavilevich%2Fmqtt-win-exec","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fayavilevich%2Fmqtt-win-exec","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fayavilevich%2Fmqtt-win-exec/lists"}