Thursday, July 25, 2013

Tasker for Android Profiles

In a recent post I discussed the steps I took to customize my phone, including rooting and modding it, installing some great apps from the Google Play Store, and automating some common phone processes using Tasker, an Android automation app.  Because I wanted to share the profiles and tasks that I wrote but couldn't find a way to fit them within that post, I created this post specifically for posting Tasker profiles.  I will update this regularly as I create more and refine other profiles and tasks.  When possible, I included a description of what I was trying to do and why.

Tasker Profiles

Here is a list of the Tasker profiles I have created over the past few months.  I no longer use all of these as I ran into issues with the screen on and screen off event not always behaving properly.  I have tried to explain these as best as I can, since the result may not always be apparent.

CommCon

Description

This profile enables my wifi radio when I get close to home, and disables it when I leave. Since I have poor location accuracy through my 4G data and I didn't want to waste my battery using GPS, I added a check when leaving so that if it detects me leaving but I am still connected to a wireless network, it does nothing, and a check when I get within the range but have not connected to a wireless network within twenty minutes, it turns the wifi radio off.  The profile also enables Bluetooth when I leave and disables it when I get home since the only time I use Bluetooth is in the car.

Initiating Event

Location: xx.xxxxxx / -xx.xxxxxx / 2000.0m

Enter Task

If [ %WIFI !~ *CONNECTION* ]
  WiFi [ Set:On ]
  For [ Variable:%xxxx Items:1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20 ]
    If [ %WIFII ~ *CONNECTION* ]
      Bluetooth [ Set:Off ]
      Music Play [ File:FF.ogg Start:0 Loop:Off Stream:3 ]
      Stop [ With Error:Off Task: ]
    End If
    Wait [ MS:0 Seconds:0 Minutes:1 Hours:0 Days:0 ]
  End For
  If [ %WIFII !~ *CONNECTION* ]
    WiFi [ Set:Off ]
  End If
End If 

Exit Task

For [ Variable:%yyyy Items:1,2,3,4,5,6,7,8,9,10 ]
  If [ %WIFII !~ *CONNECTION* ]
    WiFi [ Set:Off ]
    Bluetooth [ Set:On ]
    Music Play [ File:Rew.ogg Start:0 Loop:Off Stream:3 ]
    Stop [ With Error:Off Task: ]
  End If 
  Wait [ MS:0 Seconds:30 Minutes:0 Hours:0 Days:0 ] 
End For

02:50 (disabled)

Description

Ten minutes before the daily system restart (using Auto Reboot), change the live wallpaper to a new one for the day.  Because live wallpapers are apps, there is no easy way to automate the process of changing a live wallpaper without doing so manually.  I found a workaround, which actually navigates through the phone like an actual person would, pressing buttons and going to the correct pages.  This process is very phone-specific, and can also be different if you have multiple gallery apps like I have.  Because this profile is just blindly pressing buttons, if you don't do it just right, it could go in and change settings you were not planning on.  You also cannot be using the phone while this profile is running, since the profile requires a very specific order to its button presses.  I ended up disabling this profile because it did not run every night like it was supposed to, and the live wallpapers were taking up too much memory and processor power for my underpowered phone.  The one second waits interspersed are probably unnecessary, but I wanted to be sure my phone didn't get over burdened and skip steps or hang up while this was running.

Initiating Event

Time: From 02:50 Till 02:55

Enter Task

Wait [ MS:0 Seconds:5 Minutes:0 Hours:0 Days:0 ]
Button [ Button:Back ]
Button [ Button:Back ]
Button [ Button:Back ]
Wait [ MS:0 Seconds:1 Minutes:0 Hours:0 Days:0 ]
Go Home [ Page:0 ]
Wait [ MS:0 Seconds:1 Minutes:0 Hours:0 Days:0 ]
Load App [ App:Settings Data: Exclude From Recent Apps:Off ]
Wait [ MS:0 Seconds:1 Minutes:0 Hours:0 Days:0 ]
Button [ Button:Back ]
Button [ Button:Back ]
Button [ Button:Back ]
Button [ Button:Back ]
Go Home [ Page:0 ]
Wait [ MS:0 Seconds:1 Minutes:0 Hours:0 Days:0 ]
Load App [ App:Settings Data: Exclude From Recent Apps:Off ]
Wait [ MS:0 Seconds:1 Minutes:0 Hours:0 Days:0 ]
Dpad [ Button:Down Repeat Times:4 ]
Wait [ MS:0 Seconds:1 Minutes:0 Hours:0 Days:0 ]
Dpad [ Button:Press Repeat Times:3 ]
Wait [ MS:0 Seconds:1 Minutes:0 Hours:0 Days:0 ]
Dpad [ Button:Down Repeat Times:2 ]
Wait [ MS:0 Seconds:1 Minutes:0 Hours:0 Days:0 ]
Dpad [ Button:Press Repeat Times:1 ]
Wait [ MS:0 Seconds:1 Minutes:0 Hours:0 Days:0 ]
If [ %DAYW ~ Monday ]
Else If [ %DAYW ~ Tuesday ]
  Dpad [ Button:Down Repeat Times:1 ]
Else If [ %DAYW ~ Wednesday ]
  Dpad [ Button:Down Repeat Times:6 ]
Else If [ %DAYW ~ Thursday ]
  Dpad [ Button:Down Repeat Times:3 ]
Else If [ %DAYW ~ Friday ]
  Dpad [ Button:Down Repeat Times:7 ]
Else If [ %DAYW ~ Saturday ]
  Dpad [ Button:Down Repeat Times:4 ]
Else If [ %DAYW ~ Sunday ]
  Dpad [ Button:Down Repeat Times:2 ]
End If
Wait [ MS:0 Seconds:1 Minutes:0 Hours:0 Days:0 ]
Dpad [ Button:Press Repeat Times:2 ]
Wait [ MS:0 Seconds:1 Minutes:0 Hours:0 Days:0 ]
Button [ Button:Back ]
Button [ Button:Back ]
Button [ Button:Back ]
Button [ Button:Back ]
Wait [ MS:0 Seconds:1 Minutes:0 Hours:0 Days:0 ]
Go Home [ Page:0 ]
System Lock

Exit Task

None

Pocket Protect

Description

Turns the screen off if a screen on event is detected and the phone is in my pocket.  This profile used to use the proximity sensor to detect whether it was in my pocket, but that did not work all the time and the phone would not always stay off in my pocket.  I have since switched to basing the location on phone orientation (upside down), since this is how I put it in my pocket and I never use it this way.  I also added five checks within the first second to try and catch if the phone is not really upside down but the IsUDown Boolean was incorrectly set.  This is to try and reduce the number of times I turn on the phone right-side up, but the IsUdown variable has not toggled to 0 (false) yet.

Initiating Event

Event: Display On

Enter Task

If [ %IsUdown ~ 1 ]
  For [ Variable:%wwww Items:1,2,3,4,5 ]
    Wait [ MS:200 Seconds:0 Minutes:0 Hours:0 Days:0 ]
    If [ %IsUdown ~ 0 ]
      Stop [ With Error:Off Task: ]
    End If
  End For
  System Lock
End If

Exit Task

None

Proximity Sensor

Description

Because the system tracks the state of the proximity sensor, but it does not store this data in a system variable that I could find, I created a separate profile to toggle a variable based on the state of the proximity sensor.

Initiating Event

State: Proximity Sensor

Enter Task

Variable Set [ Name:%Prox To:1 Do Maths:Off Append:Off ]

Exit Task

Variable Set [ Name:%Prox To:0 Do Maths:Off Append:Off ]

Wave Screen

Description

This profile went through a few changes over the past few weeks.  It originally just turned the screen on for five seconds, displaying the lock screen which had the time, battery level, and any notifications.  I then changed it to open a clock app that also displayed the weather and had a nice fade-in effect, but the screen only came on sometimes, and if the system got bogged down the app might load five minutes later while I was using it.  In the end, I set it to just turn the screen on, that way I didn't have to detect whether the screen was on or off.  It is initiated by the proximity sensor, waits one second, then if the phone is laying flat and the proximity sensor is no longer activated (simulates a wave), the screen comes on.

This profile also uses the Secure Settings Plugin to handle the screen on event.

Initiating Event

Event: Variable Set [ Variable:%Prox Value:1 ]

Enter Task

Wait [ MS:0 Seconds:1 Minutes:0 Hours:0 Days:0 ]
If [ %IsFlat ~ 1 ]
  If [ %Prox ~ 0 ]
    Secure Settings [ Screen:Bright Time:5s ]
  End If 
End If 

Exit Task

None

Is Flat

Description

Similar to the Proximity Sensor profile, Is Flat just detects when the orientation of the phone is face up and toggles a Boolean 1 (true) or 0 (false).  This variable is used by other profiles like Wave Screen.

Initiating Event

State: Orientation [ Is:Face Up ] ]

Enter Task

Variable Set [ Name:%IsFlat To:1 Do Maths:Off Append:Off ] 

Exit Task

Variable Set [ Name:%IsFlat To:0 Do Maths:Off Append:Off ] 

Udown

Description

Similar to the Proximity Sensor profile, Udown just detects when the orientation of the phone is upside down and toggles a Boolean 1 (true) or 0 (false).  This variable is used by other profiles like Pocket Protect.

Initiating Event

State: Orientation [ Is:Upside Down ]

Enter Task

Variable Set [ Name:%IsUdown To:1 Do Maths:Off Append:Off ] 

Exit Task

Variable Set [ Name:%IsUdown To:0 Do Maths:Off Append:Off ] 


7/29/2013 UPDATE:

Headphones In

Description

When headphones are inserted, start BeyondPod app and increase media volume to full.

Initiating Event

State: Headset Plugged [ Any ]

Enter Task

Secure Settings [ Screen:Bright Time:20s ]
Run [ BeyondPod]
Media Volume [ 15 ]

Exit Task

Variable Set [ Name:%IsUdown To:0 Do Maths:Off Append:Off ] 

No comments:

Post a Comment