Automatically VPN based on WiFi state
Prerequisites
WireGuard app installed on your phone with a tunnel set up. Tasker installed and battery saving features turned off.
WireGuard app
Settings - Advanced. Check Allow remote control apps.
Disconnect from VPN when you're connected to your WiFI network.
Profiles - Tap +
State - Search for and select WiFi Connected.
Tap the magnifying glass and select your WiFi.
Tap the arrow in the top left corner and tap the New Task popup.
Name it or not, doesn't matter. Then tap the checkmark.
Tap +. Search for and select Tasker Function.
Search for and select WireGuard Set Tunnel.
Tunnel Up - No
Tunnel name: The same name as the Interface in the Wireguard app.
Tap the arrow in the top left corner.
Connect to VPN when you're leaving you're WiFi network.
Profiles - Tap +
State - Search for and select WiFi Connected.
Tap the Magnifying glass and select your WiFi.
Tap the checkbox next to Invert to select it.
Tap the arrow in the top left corner and tap the New Task popup.
Name it or not, doesn't matter. Then tap the checkmark.
Tap +. Search for and select Tasker Function.
Search for and select WireGuard Set Tunnel.
Tunnel Up - Yes
Tunnel name: The same name as the Interface in the Wireguard app.
Tap the arrow in the top left corner.
Finally tap the checkmark next to the magnifying glass to save.