Detect if VPN is active?

Is there any way to do this with OpenVPN Connect / Tasker? Specifically whilst connected to Mobile Data.

I’m currently using AutoNotification to regex match the “OpenVPN is activated” notification text, but this feels like a bit of a bodge.

Is there a better way?

I set a variable based on the VPN Connected state.

VPN Connected → Active: Any

This works beautifully. To disconnect from VPN I’ve had success with both AutoInput (previously) and AutoNotification (currently using).

I switched to “OpenVPN for Android” which can use the “OpenVpn Tasker Plugin”. I use it to connect and disconnect on certain conditions but I think it can report when it is active or not.

I’ve used the shell command ifconfig and regex for tun0 or tun1 to detect if on VPN, but this is a command that has to be explicitly run, it won’t monitor, if that’s what you’re looking for.

Perfect. It didn’t even occur to me to do that.

All sorted :slight_smile: thanks!

hi, how are you disconnecting VPN using AN?

Thanks!

Cool, didn’t realise this was a thing.

I’ve been using autonotification to intercept the notification thrown up by the vpn app.

I’m very new to Tasker and as such am undoubtedly missing something obvious, but I’ve clicked through every item in tasker I can find and have looked through the list of status items available for ‘Variable Select’ and I don’t see “VPN Connected” anywhere (the list appears to be in alphanumeric order and jumps straight from “Volume - System” to “WiFi Info”). If you can elaborate a bit on where to find that state, it would be super-helpful.

Excellent - This will likely cover what I need. I’ll take a look.

How do you use this shell command? (yes I have root access)

In all fairness, it’s a pretty new ability. I went for years doing bank hacky ways until someone told me about it.

I use Private Internet Access and use this task, a tip from another Reddit thread:

VPND (56)
A1: AutoNotification Query [ Configuration:Persistency Type: Persistent Only
Notification Apps: PIA VPN Timeout (Seconds):20 ]
A2: AutoNotification Actions [ Configuration:Intercept Action ID: %anbutton1action() Timeout (Seconds):0 ]

It just clicks the first button of PIA’s persistent notification.

For State I set (in the Net subcategory) VPN Connected - Any. My entry task is a simple task with Variable Set %VPNC to 1 and my exit task is a simple task with Variable Set %VPNC to 0.

Thanks! Thought I have missed something but it’s just OperaVPN does not allow for disconnection from notification :frowning: