Command line switch fails

On a different Raspberry Pi I use a VPN (Windscribe). I want to be able to enable and disable it from my HA. I have set up 2 command line switches. #1 to turn off the VPN and #2 to turn it on.

Turning off the VPN works perfectly - no errors. However, the script to turn it on fails when run in HA. It does work from the command line. I run each of the scripts from within HA using the following command line commands:

switch:
  - platform: command_line
    switches:
      vpn_status:
        command_on: "sshpass -p redacted ssh [email protected] ./windscribelogin"
        command_off: "sshpass -p redacted ssh [email protected] ./windscribelogout"
        command_state: '/home/john/./vpnscript'
        value_template: '{{ value == "VPN Running" }}'

The working, logout, script on the remote Pi (192.168.1.3) looks like this:

#!/bin/bash 
windscribe logout

This works perfectly. But the script to log in, this one doesn’t work from within HA:

#!/usr/bin/expect -f
spawn windscribe logout
interact
spawn windscribe login
expect "Windscribe Username:"
send "redacted\n"

expect "Windscribe Password:"
send "redacted\n"

interact

spawn windscribe connect GB

interact

Any ideas why the logout one runs, but the login one fails? Both work perfectly from the command line of the (Ubuntu) box that is running HA.

This is the error I see:

Command failed: sshpass -p redacted ssh [email protected] ./windscribelogin

HA is installed on ubuntu no venv.
Many thanks
truxntrax

Anyone any ideas how I can turn on any extra logging to find out why the script is failing? The script with the expect stuff in it takes at least 30 seconds to run, perhaps even a minute. Could there be a timeout because it doesn’t complete?

Or my other thought is perhaps the state value gets set before the script completes and therefore aborts?

Any help is much appreciated.

Perhaps there is a better way to script enabling the windscribe VPN on the pi?