• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Help with Tasker flow

Hi,

I have what is probably a stupid question, but I'm going to ask it anyway, as I've hit a wall/mental block... I've created a Tasker profile that works as an alarm with increasing volume. Basically, it opens Pandora, sets the media volume to 2, waits 3 minutes, sets the media volume to 4, waits three minutes, etc until max volume is reached. This all works wonderfully. However, I've noticed that Pandora will occasionally stop running. Which, seeing how this is my alarm, and I kind of enjoy food, shelter and clothing; it's a bit of an issue. I've solved this issue by running a shell script that stores the output of pgrep com.pandora.android, runs an if statement on the variable, and launches Pandora if it's not running. Again, works beautifully. Now my question.. Right now I run that shell script, and if statement every time the volume increases. It's messy but it works. Is there a better way to control the flow where the media will continually increase while checking to make sure Pandora is running? I can provide details of the tasker profile and task if needed. Any help would be appreciated.
 
Sure thing, thanks for the help! Here's how I have the profile and task set up:

Profile

Triggers:
Day – Monday, Tuesday, Wednesday, Thursday and Friday
Time – 5:30am – 6:30am

Task

1. Launch Pandora
2. Set media volume to 2
3. Wait 3 minutes
4. Run shell – command: pgrep com.pandora.android
store output in %pgrep
5. IF %pgrep ~ %*
6. Launch Pandora
7. End IF
8. Set media volume to 4
9. Wait 3 minutes
10. Clear variable - %pgrep
11. Run shell – command: pgrep com.pandora.android
store output in %pgrep
12. IF %pgrep ~ %*
13. Launch Pandora
14. End IF
15. Set media volume to 6
16. Wait 3 minutes
17. Clear variable - %pgrep
18. Run shell – command: pgrep com.pandora.android
store output in %pgrep
19. IF %pgrep ~ %*
20. Launch Pandora
21. End IF
22. Set media volume to 8

That’s pretty much it. It continues like that until it reaches the max volume of 15. Then it does:


Clear variable - %pgrep (label: check if running)
Run shell – Command: pgrep com.pandora.android
store output in %pgrep
IF %pgrep ~ %*
Launch Pandora
End IF
Wait 1 minute
GOTO: check if running

Like I said, it works but it just seems messy. There has to be a more organized, less redundant way to do it. I appreciate anything you can come up with!
 
Upvote 0
I'd suggest restructuring something like this:

1) Launch Pandora.
2) Set Media Volume to 2.
3) Wait 3 Minutes.
4) If Media Volume < 15 {
5) Run shell – command: pgrep com.pandora.android; store output in %pgrep
6) IF %pgrep ~ %* {
7) Launch Pandora​
8) End If }
9) Set Media Volume = Media Volume + 2
10) Wait 3 Minutes.
11) Goto (4)​
12) End if }
...

I don't have my phone on hand so I can't recall exactly the steps that you'll need (you'll probably want to use a local variable to store the Media Volume value, but I'm not 100% sure that's needed). Hopefully this can get you pointed in a useful direction - it's basically a poor man's while() loop :p
 
  • Like
Reactions: _DyingBreed_
Upvote 0
Codesplice,

SUCCESS! Your suggestion pointed me to exactly where I needed to be. I made some changes, and everything is running smoothly now. There is a plugin called KC Tasker Processes that checks to see if a process is running. I found it to be easier and more reliable than pgrep. So that's what I'm using now. I also added a little bit more after the media volume = 15 to keep checking if Pandora is running, and launch it if it isn't. Below is my setup:


1. Variable Set - %media_volume to 0 (create the local variable for volume)
2 Media Volume - %media_volume (set volume to variable. Set to zero so I'm not startled..haha)
3. Launch App - Pandora
4. Wait - 7 seconds (so Pandora can load)
5. Variable Add - %media_volume value 1 (set to one cuz the max volume is an odd number)
6. Media Volume - %media_volume
7. IF %media_volume < 15 {
8. Processes Started - com.pandora.android - variable %running - value set to true
9. IF %running !~ true {
10. Launch App - Pandora​
11. End IF }
12. Variable Add - %media_volume value 2
13. Media Volume - %media_volume
14. Wait - 3 minutes
15. GOTO - 7​
16. End IF }
17. Processes Started - com.pandora.android - variable %running - value set to true
18. IF %running !~ true {
19. Launch App - Pandora
20. Wait 30 seconds
21. GOTO - 17​
22. End IF }

That's it...It works perfectly! Thanks for all your help! I think I'm going to like these forums. I have another question regarding this task though...haha. What if I wanted to check to see if Pandora was running every 30 seconds, but only wanted the volume to increase every 3 minutes? I only ask because I'm a pretty heavy sleeper, so the longer it's running the more chance I have of making it to work...haha. Let me know if you have any ideas. Thanks again!!

 
  • Like
Reactions: Thom and codesplice
Upvote 0
What if I wanted to check to see if Pandora was running every 30 seconds, but only wanted the volume to increase every 3 minutes? I only ask because I'm a pretty heavy sleeper, so the longer it's running the more chance I have of making it to work...haha. Let me know if you have any ideas. Thanks again!!

Hmm, my gut's suggestion would be to move the checks for whether or not Pandora is running into a new profile. You can use "Profile Active" as the Context for it, and then just put your 30-second wait + check in there. I'm not 100% sure how a Wait task might affect a profile (will it continue to execute the wait if the Profile Active context stops being true during those 30 seconds?); you may want to tick the "If" checkbox on the task that would re-launch the stopped Pandora process and check the %PACTIVE variable for the name of your Alarm profile.

Let me know how it goes :D
 
  • Like
Reactions: Unforgiven
Upvote 0

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones