OpenVPN on Android with Tasker
Table of Contents
I got myself a pfsense firewall and dedicated access points for my home network. I might do a seperate post about all that, but for now, only one thing is important. I configured OpenVPN on it to allow me to connect to my home network while on the go. I immediately wanted my phone to automatically connect with OpenVPN. I am not going through the detail on how to configure OpenVPN Connect. That might also end up in a dedicated post.
Now that I said what I won’t document here, let me shoot myself in the foot. Don’t you hate it when you find documentation on how to do something but it leaves out an important step? I found this page on the OpenVPN website. What it leaves out is how to get to that action. It also doesn’t give any hints about the profiles. Let’s hope that this will help you.
Get the ID of your OpenVPN profile#
Just open that already an go to the profile ID. You will need it later when you configure the task in tasker.
- Open you OpenVPN Connect app
- Click the pencil beside your profile.
- Scroll all the way down.
- There is a profile ID. Beside it is a copy icon.
I followed the FAQ and used that. There are other documentations out there that show you how to do it with the profile name.
Tasker tasks#
We will need two tasks. One that does the connect and one that does the disconnect of.
- Go to the tasks tab
Connect task#
- Click the plus to add a new task
- Tasker might ask you if you want to create one or download one. Select create.
- Give it a name, e.g. OpenVPN connect
- Add an action by selecting the plus
- Select the Category “System”
- Select the action “Send intent”
- Fill out the following fields
- Action: net.openvpn.openvpn.CONNECT
- Extra: net.openvpn.openvpn.AUTOSTART_PROFILE_ID:’{your_profile_id}'
- Extra: net.openvpn.openvpn.AUTOCONNECT:true
- Package: net.openvpn.openvpn
- Class: net.openvpn.unified.MainActivity
- Target: Activity
- Use the back arrow on the top to go back
- (Optional) You can click the play button on the bottom to test that it works
- Use the back arrow on the top to go back
Disconnect task#
- Click the plus to add a new task
- Tasker might ask you if you want to create one or download one. Select create.
- Give it a name, e.g. OpenVPN disconnect
- Add an action by selecting the plus
- Select the Category “System”
- Select the action “Send intent”
- Fill out the following fields
- Action: net.openvpn.openvpn.DISCONNECT
- Extra: net.openvpn.openvpn.STOP:true
- Package: net.openvpn.openvpn
- Class: net.openvpn.unified.MainActivity
- Target: Activity
- Use the back arrow on the top to go back
- (Optional) You can click the play button on the bottom to test that it works
- Use the back arrow on the top to go back
Profiles#
We need two profiles.Go to the profiles tab.
- Detect that you are not connected to your home wifi and execute the connect.
- Detect that you are connected to your home wifi and then executes the disconnect.
Connect profile#
- Click the plus to create a new profile.
- Tasker might ask you if you want to create one or download one. Select create.
- Select “State”.
- Select “Net”.
- Select “Wifi connected”.
- Input your SSID, the name of your Wifi network.
- Check “Invert”. This means this profile is active when it’s not connected to your wifi.
- Click the back arrow on the top.
- Select the “OpenVPN connect” task.
Connect profile#
- Click the plus to create a new profile.
- Tasker might ask you if you want to create one or download one. Select create.
- Select “State”.
- Select “Net”.
- Select “Wifi connected”.
- Input your SSID, the name of your Wifi network.
- Leave “Inverted” unchecked.
- Click the back arrow on the top.
- Select the “OpenVPN connect” task.