Automation is supposed to be about simplifying everyday tasks to give you more precious time doing the things you love. At XDA, we’ve shown you how you can use Tasker to secure your device, improve productivity, or make driving safer, all a part of our series called ‘Tasker Week.’
But the fun doesn’t end there. If you’ve been itching for some seriously awesome Tasker tasks (and are tired of the boring stuff like telling you how to reboot your phone or shake your phone to wake the display), then our new Tasker Pro series is for you.
We will be posting a series of highly advanced Tasker profiles that will show you just how powerful Tasker can be if you are willing to think outside of the box. Although we’ve done most of the hard work for you and you’re certainly free to import my profiles and use them as-is, I highly recommend you give learning how to use Tasker a shot if you want to be able to customize these tasks yourself. Over on our Tasker Tips & Tricks forums or on Reddit’s /r/Tasker subreddit, you can share and work with others on how to implement an idea you might have (as I have done many times).
This is Week 5 of Tasker pro. Last week, we showed you how you can use Tasker to copy two-factor authentication codes sent via SMS without leaving your app. This week, we will show you how to set a calendar-based alarm and disable any alarms set to go off during work!
Tasker Pro #5: Calendar Based Alarm
You wake up at 7AM. You shower, eat breakfast, grab a cup of coffee, hop in your car, and you’re on your way to work. If this is your routine every morning, you probably don’t have many issues with remembering to set an alarm clock. For those of us who work irregular hours, it’s pretty crucial for us to check our work schedule to be sure of what time we need to be up and ready to arrive on time. Remembering to set an alarm clock is crucial to being a punctual worker, but we’re all humans so we’re bound to make mistakes. That’s why I’ve devised this calendar-based alarm clock using Tasker and the AlarmPad app to make sure that if you have work scheduled the next day, you are guaranteed to have an alarm set for that time.
Requirements
Instructions
You will need some preparation to make this task truly work for you. First of all, you will actually need to make sure you are keeping track of your work schedule in a Google Calendar. My work schedule for example has an option to export to Google Calendar which is how I set it up. After you’ve set up your calendar, we will now discuss the two separate, independent Tasker scripts that will work to ensure that you both make it on time to work and to ensure that you never have an embarrassing situation where you forgot to turn off an alarm at work. You can implement one or both of these set-ups as you see fit.
First, how to make a calendar-based alarm. Below is a screenshot of the actions needed to set up this task. This task should be run once every night, preferably before you go to bed. You can set it up to run based off of a time context (eg. every night at midnight) or based off of some other trigger like an NFC tag (this is my preferred method).
- Task –> Perform Task. Name: Get Events. If you’ll notice, the first action in this step actually calls upon another task. This is a task I edited from the work of a Redditor on Tasker and showed off to XDA back in March during Tasker Week. A full guide on what this task is and what it does can be found in our Tasker Tips & Tricks forum. You can download that task in the thread linked or down below as I’ve re-uploaded it for the sake of this guide. A bit of a warning here, if you use your calendar for a whole bunch of different things that you don’t want to have an alarm set for, then be sure that you edit the ‘Get Events’ script to only pull from your specific work calendar.
- Task –> If. If %Calstart1 is Set. This will make the script only run if there is actually an event in your Google Calendar for tomorrow.
- Plugins –> AutoAlarm. This will pull a ton of detail about the next occurring alarm. Technically this is possible to do with a few Java functions, but it involves more steps than is necessary and the plugin just makes it far easier.
- Variables –> Variable Set. Name: %nextalarm to %TIMES + %seconds. Check “Do Maths.” This will pull the time that the next alarm is currently scheduled at (represented as seconds since the epoch) as a variable called ‘nextalarm.’
- Variables –> Variable Set. Name: %diff to (%Calstart1-%nextalarm)/3600. Check “Do Maths.” This formula will determine the difference in time between the next event on your calendar and the time that the next alarm is set to, in hours.
- Task –> If. If %diff < 2. If the next alarm is greater than 2 hours away (before or after the calendar event, it doesn’t matter), then we need to schedule a more appropriate alarm.
- Variables –> Variable Set. Name: %alarm to %Calstart1*1000. All we’re doing here is preparing the time we need to set the alarm clock to so we can feed it into AutoTools in a format it can recognize.
- Plugins –> AutoTools –> AutoTools Time. Click on Add Time. Go to Date and click on Data Millis and enter %alarm. Go back and for Add Unit set it to Hours. For Add Value set it to -2 (this is how long prior to the calendar event that Tasker will set an alarm for, if you think 2 hours before work is too long you can change the number, but make sure it’s a negative number). For Output Format: set it to HH:mm.
- Variables –> Variable Split. Name: %atcalculateddate. Splitter : (yes, that’s a colon). This will get the next alarm into two separate variables, one for the hours and one for the minutes.
- Plugins –> AlarmPad run action. Disable: Next occurring alarm.
- Plugins –> AlarmPad set alarm. For hour make it %atcalculateddate1 and for minute make it %atcalculateddate2. Check “automatically delete after running.”
- Task –> End if.
- Task –> End if.
And that’s it for the calendar-based alarm part! Now if you’ve been using AlarmPad for awhile now, you might think this entire task is redundant because AlarmPad itself has a feature to monitor for calendar events, but it only asks you if you want to set them (meaning you have to do it manually) and it doesn’t discriminate between your various calendars. Assuming you’ve set up your work calendar properly, this will do everything automatically so you don’t have to worry about anything.
Next up, a variation of a pretty common Tasker script that involves silencing your phone at work … but with the added benefit of disabling any alarms that happen to be set to go off during work! Here is an overview of how it looks:
As you can see, you’ll be creating a state profile that is active whenever a calendar event is detected. Create a new profile and name it Silent Calendar. Leave the title, location, description all blank but for the calendar choose your work calendar. Create an entry task without a name. Here are the steps in order, which we’ll cover in detail below.
- Audio –> Silent Mode. Mode: Vibrate. Self explanatory. Set your phone to vibrate only mode when at work.
- App –> Test App. Type: Calendar Start (Seconds). Data: %TIMES. Store result in: %currstart. Get the start time of the current calendar event. We will use this to compare with the next alarm that is set.
- Plugin –> AutoAlarm. Get info about the next alarm.
- Variables –> Variable Set. Name: %nextalarm to %TIMES+%seconds. Get the time that the next alarm is set to, defined in seconds since the epoch.
- Test App. Type: Calendar Title. Data: %nextalarm. Store result in: %title. Get the title of the event that matches, if any, the time that the next alarm is set to.
- Test App. Type: Calendar Calendar. Data: %nextalarm. Store result in %calendar. Get the calendar that corresponds to the event above.
- Test App. Type: Calendar Start (Seconds). Data: %nextalarm. Store result in: %nextstart. Get the start time of the calendar event that corresponds to the next alarm, if any.
- Plugin –> AlarmPad run action. Disable: Next occurring alarm. Check If and set it to if %title1 is Set & %calendar1 ~ YOURWORKCALENDARNAME & %currstart1 = %nextstart1. This is doing three checks to ensure that the next alarm is disabled properly. If the next alarm is set during a calendar event AND that calendar event is from your work calendar AND that calendar event overlaps with your current work right now, then and ONLY THEN disable the next alarm.
You can use this script separately from the one above or in coordination with it. I use both and it helps me out really well with my irregular work schedule. Give it a shot!
And voila! If you are able to follow along this, then congratulations, you’re pretty much a master of Tasker! Confused on a step and just want to import the script and get on with your life? I can’t blame you, this one took myself a lot of thinking to get it down right.
If you want to import this Tasker script, you can download it from Android File Host. You will need to download these three files and import them all: [1] [2] [3] In order to import the task, you need to first disable Beginner Mode in Tasker by going to the menu –> preferences. Under the UI tab, uncheck ‘Beginner Mode.’ Then back in the main Tasker menu, click on the ‘Tasks’ tab. Then long-press on the ‘Tasks’ tab and press ‘Import.’ Navigate to where you downloaded my .prf.xml file and select it to import it. Once you import it, you’re free to play around with it as you see fit.
Next week for Tasker Pro I will show you how to unlock your Windows PC using your fingerprint!
Check out all Tasker Pro scripts!
What would you like to see me make with Tasker? Let us know below and we might feature your idea in a future article!
from xda-developers http://ift.tt/28OUtqi
via
IFTTT