Automatically connect to VPN

I have set up a Wireguard VPN connection in the system settings. How can I get it to automatically connect when I am connected to my Wifi?

I tried:

  • Wifi: Connect automatically with priority: 0
  • Wifi: Automatically connect to VPN
  • VPN: Connect automatically with priority: 0

But then it will not connect to the Wifi, saying something like “secondary connection failed”. If I untick the “automatically connect to VPN” box then it connects to the Wifi but won’t connect to the VPN unless I do it manually. I played around with these settings (e.g. giving the VPN a connection priority of 1 which I assume is lower) but it doesn’t work.