[Android General] SomebodySysop:
How to Turn Hotspot on/off Using Tasker/Autoinput/TouchTask on un-rooted Phone

I have un-rooted Galaxy S8 (Nougat). I finally was able to come up with a Tasker script (also using AutoInput and TouchTask) which does the following:

When I get in the car and turn on the engine:

1. S8 bluetooth connects to px5 head unit. I give phone a few seconds to internally SmartLock unlock. Then I issue AutoInput unlock to basically turn screen on.

2. Phone turns off wifi.

3. Phone launches Hotspot & Tethering screen, and if it is off, turns it on.

4. Head unit connects to Internet using phone wifi.

When I turn engine off:

1. Upon S8 BT disconnect, it issues AutoInput unlock (in case screen is off).

2. Phone launches Hotspot & Tethering screen and if it is on, turns it off.

2. Phone turns on WiFi.

Important Notes: Because the phone is not rooted, I could not use Tasker "wifi tether on/off" action. The bulk of this profile is manually launching the screens and pressing the buttons needed to unlock phone and turn on wifi. Oh, and this is VERY important: The only reason the screen unlocks is because the phone itself is unlocked when I get in the car. I use Android's "SmartLock" technology to automatically unlock the phone when it senses it is in my garage (by location) or BT connects to my head unit (by device).

Profile: Turn Hotspot On Off 03 (21)
State: BT Connected [ Name:Rons Xtrons Address:* ]
Enter: Hotspot On 05 (26)
A1: Wait [ MS:0 Seconds:10 Minutes:0 Hours:0 Days:0 ]
A2: Variable Set [ Name:%Hotspot To:0 Recurse Variables: Off Do Maths: Off Append: Off ]
A3: Screen unlock [ Configuration:Screen unlock Timeout (Seconds):5 Continue Task After Error: On ]
A4: Wait [ MS:0 Seconds:10 Minutes:0 Hours:0 Days:0 ]
A5: Flash [ Text:Launch hotspot app Long: Off ]
A6: Launch App [ App:Settings:Hotspot and Tethering Data: Exclude From Recent Apps: Off Always Start New Copy: On ]
A7: Wait [ MS:0 Seconds:5 Minutes:0 Hours:0 Days:0 ]
A8: Flash [ Text:Launch autoinput ui query Long: Off ]
A9: AutoInput UI Query [ Configuration:App Package: com.android.settings
Variables: off()
Only Visible: true Timeout (Seconds):45 Continue Task After Error: On ]
A10: Wait [ MS:0 Seconds:10 Minutes:0 Hours:0 Days:0 ]
A11: Flash [ Text:aitext() = off Long: Off ] If [ %aitext() ~ *Off* ]
A12: Flash [ Text:aitext() = on Long: Off ] If [ %aitext() ~ *On* ]
A13: Flash [ Text:Turning WiFi Off Long: Off ] If [ %aitext() ~ *Off* ]
A14: WiFi [ Set: Off ] If [ %aitext() ~ *Off* ]
A15: Wait [ MS:0 Seconds:5 Minutes:0 Hours:0 Days:0 ]
A16: Flash [ Text:Tap hotspot on Long: Off ] If [ %aitext() ~ *Off* ]
A17: Actions [ Configuration:Action: Tap Method: Point (x,y) Selection: 958 315 Timeout (Seconds):45 Continue Task After Error: On ] If [ %aitext() ~ *Off* ]
A18: Flash [ Text:Hotspot should be on Long: Off ] If [ %aitext() ~ *Off* ]
A19: Variable Set [ Name:%Hotspot To:1 Recurse Variables: Off Do Maths: Off Append: Off ] If [ %aitext() ~ *Off* ]
A20: Popup [ Title: Text:aitext does not contain Off or On. Copied to clipboard. Error: %err
%errmsg Background Image: Layout:Popup Timeout (Seconds):5 Show Over Keyguard: On ] If [ %aitext() !~ *On* & %aitext() !~ *Off* ]
A21: Set Clipboard [ Text:%aitext()

errors %err
%errmsg Add: Off ] If [ %aitext() !~ *Off* & %aitext() !~ *On* ]

Exit: Hotspot Off 03 (14)
A1: Screen unlock [ Configuration:Screen unlock Timeout (Seconds):5 Continue Task After Error: On ]
A2: Wait [ MS:0 Seconds:5 Minutes:0 Hours:0 Days:0 ]
A3: Launch App [ App:Settings:Hotspot and Tethering Data: Exclude From Recent Apps: Off Always Start New Copy: On ]
A4: Wait [ MS:0 Seconds:5 Minutes:0 Hours:0 Days:0 ]
A5: AutoInput UI Query [ Configuration:App Package: com.android.settings
Variables: on()
Only Visible: true Timeout (Seconds):20 Continue Task After Error: On ]
A6: Wait [ MS:0 Seconds:5 Minutes:0 Hours:0 Days:0 ]
A7: Actions [ Configuration:Action: Tap Method: Point (x,y) Selection: 958 315 Timeout (Seconds):30 ] If [ %aitext() ~ *On* ]
A8: Variable Set [ Name:%Hotspot To:0 Recurse Variables: Off Do Maths: Off Append: Off ] If [ %aitext() ~ *On* ]
A9: Wait [ MS:0 Seconds:2 Minutes:0 Hours:0 Days:0 ]
A10: WiFi [ Set: On ] If [ %Hotspot eq 0 ]