by Pratham Jaiswal
Version 2 (July 19, 2026)
Download (102 downloads)
Automatically enables or disables a WireGuard tunnel based on whether the configured app is in the foreground.
When the app is opened, the specified WireGuard tunnel is enabled. When you leave the app, the tunnel is disabled automatically.
### Requirements
1. Install the official WireGuard app.
2. In WireGuard → Settings → Advanced, enable "Allow remote control apps"
3. In Automate → Settings → Privileges, enable "control WireGuard tunnels"
4. Disable battery optimization for both Automate and WireGuard for the flow to work at all.
### Setup
1. Edit the wg_tunnel_name variable and set it to the name of your WireGuard tunnel.
2. To monitor a different app, edit the "When foreground app" block and select or enter the desired application's package name.
3. (Optional) Set show_toast to 1 if you want a toast notification whenever the tunnel is enabled or disabled.
### Notes
The flow monitors the configured app and only sends tunnel commands when a state change is required, avoiding unnecessary broadcasts.
If the required permissions are not enabled, WireGuard will ignore the commands.