This project is a Windows service that listens for MQTT messages and executes PowerShell scripts based on received commands. It's designed for home automation tasks, allowing remote control of a Windows PC through MQTT messages.
- Go 1.15 or later
- Windows 10 or later
- PowerShell 5.1 or later
- An MQTT broker (e.g., Mosquitto) set up and running
-
Download the latest release of WinSenseConnect from the GitHub releases page.
-
Extract the downloaded zip file to a directory of your choice.
-
Open PowerShell as Administrator and run the following commands to install and start the service:
- Replace
C:\path\to\extracted\folder
with the path where you extracted the files.
New-Service -Name "WinSenseConnect" -BinaryPathName "C:\path\to\extracted\folder\WinSenseConnect.exe" -DisplayName "MQTT Powershell Automation Service" -StartupType Automatic -Description "Listens for MQTT messages and runs PowerShell scripts" Start-Service -Name "WinSenseConnect"
- Replace
-
After installation, open a web browser and navigate to
http://localhost:8080
to access the web dashboard. -
Use the web dashboard to configure your MQTT settings, manage scripts, and view logs.
Once the service is running and configured through the web dashboard, it will listen for messages on the specified MQTT topic. When a message is received, it will execute the corresponding PowerShell script.
To trigger a command, publish a message to your MQTT topic with the command as the payload. For example, to switch to your MacBook, you would publish the message "switch_to_macbook" to the topic you configured in the dashboard.
The web dashboard provides an easy-to-use interface for managing your WinSenseConnect service. Here's what you can do:
- Configure MQTT settings: Set your broker address, credentials, and topics.
- Manage scripts: Add, edit, or remove PowerShell scripts that can be triggered via MQTT.
- View logs: Check the service logs directly from the dashboard.
- Monitor service status: See if the service is running and connected to the MQTT broker.
The service logs its activities to two places:
- Windows Event Log: You can view these logs in the Event Viewer under Windows Logs > Application.
- Web Dashboard: Logs can be viewed directly in the web interface.
To add or modify commands:
- Open the web dashboard at
http://localhost:8077
. - Navigate to the Scripts section.
- Add a new script or edit an existing one.
- Save your changes.
The service will automatically reload the configuration, so there's no need to restart it.
If you encounter issues:
-
Check the logs in the web dashboard.
-
Ensure your MQTT broker is running and accessible.
-
Verify that the PowerShell scripts exist and are correctly configured in the dashboard.
-
Check that the service is running:
Get-Service -Name "WinSenseConnect"
To remove the service:
-
Stop and delete the service:
Stop-Service -Name "WinSenseConnect" Remove-Service -Name "WinSenseConnect"
For older versions of PowerShell:
sc.exe delete "WinSenseConnect"
-
Delete the WinSenseConnect folder and all its contents.
- Access to the web dashboard should be restricted to trusted users only.
- Be cautious about what commands you allow and what the PowerShell scripts do.
- Consider network-level security to restrict access to your MQTT broker and the web dashboard.
- The service uses a secure method to store sensitive information like MQTT credentials.
Contributions to improve the service are welcome. Please feel free to submit pull requests or open issues for bugs and feature requests.
This project is licensed under the MIT License - see the LICENSE file for details.