How to put Android phone into "deep sleep" using Tasker? I have a Sony Xperia Z running factory Android 5.1.1 I'd like to use in my car for navigation/ music.

I've installed Tasker &amp; configured it to start Spotify playing on power &amp; turn off Spotify when power is switched off.

However this still leaves the phone active &amp; using it's battery while the car is not being used. We don't use our car that much so the battery runs flat over a couple of days.

What I'd really like to do is have Tasker shut down as much of the phone as possible - wireless, mobile data, location services. Ideally I'd like the phone doing absolutely nothing &amp; waiting for power to start playing Spotify again.

Options for "Airplane Mode", "Mobile Data" &amp; "Power Mode" are all unavailable/ red in Tasker. The phone is not rooted but am I correct that these aren't available in Android 5.1?

The Sony Xperia Z has got Ultra Stamina mode that would be perfect. But I can't work out how to activate Ultra Stamina via Tasker (I don't think it's possible) &amp; the phone might need a reboot to come out of Ultra Stamina - which isn't great if I've just stopped the car/ turned off the phone for 5 minutes.

What is the best way to put the phone into "deep sleep" while the phone isn't receiving power where it uses as little services/ battery as possible in Tasker?
Options for "Airplane Mode", "Mobile Data" &amp; "Power Mode" are all
  unavailable/ red in Tasker. The phone is not rooted but am I correct
  that these aren't available in Android 5.1?


On recent versions of Android,  restrictions have been put in place that prevent lot of previously easily toggleable settings (e.g. location, mobile data, night mode, more) and are no longer available without root. 

As expected there are workarounds to help toggle many settings without root.

Conventional methods employed involve circumventing Android's security policy on this permission (android.permission.WRITE_SECURE_SETTINGS)  and declaring the appropriate permission for toggling secure settings explicitly on the target app/plugin that will be used to toggle these "secure settings" via Tasker.




Using a plugin


It is possible to get most of the "power toggles" switched off using Tasker and an  additional plugin Auto Tools.


Autools offers built-in options to toggle location mode (off, device only, battery saving, high accuracy), mobile-data (on/off), battery saver (enable/disable), notification listeners etc.
Additionally you can toggle flight mode using any of the methods listed here (without root).


Setup

In tasker create a new action:

Plugin >> Auto Tools >> Secure Settings




Pseudo plugin


This detailed method described here offers useful steps to toggle most of these secure settings with ease.




  You will have to create an app using Tasker and declare the
  appropriate permission for toggling secure settings. You will then
  need to explicitly grant permission to that app.
  
  This is to workaround Android's security policy on this permission.
  Ordinarily, you wouldn't want to grant this level of permission to
  other apps, but since this an app you're creating yourself, you don't
  need to worry about it. The actual toggling is done with Java calls.



The app you created works as a sort of pseudo-plugin. In a task, use the Launch App action and choose your new app. 
In the Data field, you will specify the setting to change and the value to change to. The format of the Data field should be as such: [setting name space]|[setting name]|[value]|[value type] .


Important!

In both cases remember to explicitly grant the app(s) two extra permissions added called

android.permission.WRITE_SECURE_SETTINGS and android.permission.WRITE_SETTINGS.


Connect your device to your computer, and open up a command prompt.
Run the command adb shell pm grant [your package name] android.permission.WRITE_SECURE_SETTINGS


E.g adb shell pm grant [com.joaomgcd.autotools] android.permission.WRITE_SECURE_SETTINGS

Acknowledgements


[Project Share] Toggle settings (e.g. location, mobile data, night mode, more) WITHOUT root