AndroidApps

Creating a nap mode with Tasker

Most of my Tasker profiles were created to fill certain needs, and as such, the idea for them came from realizing that there had to be a better way to do certain things. So, when I lay down to take a nap today, it didn’t take long before I was tapping away in tasker. I didn’t get any rest, but I did come up with a pretty decent system for future naps.

This setup has a lot of stuff going on between profiles and tasks, so I thought I’d try something new and try to illustrate how it all works together. Click for larger version:

nap mode schematic1 - for some reason we don't have an alt tag here

The entire system is triggered with a button in my pop-up settings scene. It runs a task which basically has two internal groups of actions, and each click alternates between which one runs. To achieve this toggle system, the entire task is divided into two groups using If, Else, and End If actions. If %Napmode is 0, it runs the first group, which also sets %Napmode to 1. Then, next time it runs, %Napmode won’t be 0, and the other group runs, which resets %Napmode back to 0. This system also allows other tasks to change the value of %Napmode to reset the system without the button having to be pressed.

Activation

activation - for some reason we don't have an alt tag here

The first group activates nap mode. First, it uses Variable Query to ask for a time to set the alarm for. This action is a simple way to make a scene appear where you can input data. It expects a input in the format HH.MM, 24 hour mode only. I live in Norway and only use 24 hour mode, so I don’t have to go through the pain of converting AM/PM input.

Following Variable Query, there’s a second If action to restrict the rest of that group to instances where a time was actually put into the Variable Query, rather than the user hitting the cancel button. The If action is “%napcon doesn’t match *napcon*”. %napcon (the variable asked for in Variable Query) will match *napcon* when it’s blank, as the value will then also be the name. If it’s set, %napcon won’t match *napcon*, and the rest of the actions will run. Note the use of a local variable here – it resets itself every time the task runs all the way through. If it had been a global variable (capital letter), you’d have to clear it manually at the end of the task.

After the If check, the %Napmode variable is switched over. Note that %Napmode is a global variable (contrary to %napcon) because it will be used outside this task, and shouldn’t be reset after the task finishes. Next the %napcon variable is split by the period that separates the hours and minutes. This creates %napcon1 and %napcon2, hours and minutes respectively. Separate variables are needed for the next task, Set Alarm, which lets you use variables to control the hours and minutes of the alarm. Set Alarm is a built in Tasker action that works with alarm clocks that support external setting of the alarm, which unfortunately doesn’t include all alarm clocks out there. The stock alarm clock on my Galaxy S II doesn’t, but Alarm Clock Plus (which is what I use) does.

The next action, Write File, has to do with my self-built “social network.” It just writes my current status (in this case, “taking a nap until %napcon”) to a text file. Dropsync then picks the file up and puts it in my Dropbox, where family and friends can check it if they need to get a hold of me. This system is tied into all the automated profiles I use, like home, school, and outside. Following that, there’s a Say action that simply confirms the activation of nap mode, as well as the time the alarm is set for.

The next action is a plugin action for my home automation system. It sends a message to my Tellstick Net telling it to turn off my ceiling lamp. Finally, there’s an action to activate silent mode.

Alarm goes off at intended time

alarm goes off - for some reason we don't have an alt tag here

The second separate task is tied to a profile with two contexts. There’s an event context for a notification with Alarm as the title, which Alarm Clock Plus generates when it goes off. Depending on the alarm clock you use, and just what method you fancy using, there’s both a Alarm Done and an Alarm Clock event context available – the former for when you dismiss the alarm, the latter for when it goes off. It seems that Alarm Clock Plus doesn’t generate the right system events to make these work, so I ended up using the notification.

The second context is a Variable value state for %Napmode matches 1. This refers back to the variable originally used to make the other task toggle, but also helps filter alarm events. By using this second context, only alarms that go off during nap mode will trigger the Napmode Deactivation task, which is good.

As for that task, it basically reverts everything the activation task did. Writes a different status, turns silent mode off, lights back on, and flips %Napmode to off.

If the nap mode button is clicked while nap mode is active

nap mode interruption - for some reason we don't have an alt tag here

Obviously there needs to be a way to deactivate nap mode without having to wait for the alarm, and that’s what the rest of the schematic shows. Since %Napmode is 1 at this point, clicking the scene button again runs the second group of actions. First there’s a Say action that notifies that nap mode has been deactivate, and just for the heck of it, it also asks if you couldn’t sleep. Then you have an utterly pointless Variable Set that doesn’t actually have to be there, as it’s also run later through the next action. Sometimes when you try and fail your way to a working setup, you end up noticing pointless actions later on, like when you’ve made a huge schematic of screenshots…

Anyways, the next action is a Perform Task which runs the same task that is tied to the profile that runs when the alarm goes off. The actions in that task is shared between the two deactivation modes, so I might as well run it with an action instead of  copying the actions. The fact that this task contains a Variable Set to flip %Napmode off is why that action isn’t needed in the first task.

Finally, the task opens up Alarm Clock Plus for me. There’s no way that I know of to turn off the alarm in Tasker, so I need to go into the app to do that. This saves me from having to launch it manually.

Video time

Final words

I didn’t get my nap, but I did get a system for making naps more pleasant in the future. No light, no interruptions, and ironically it takes fewer button presses to set the alarm this way than to add a new alarm in Alarm Clock Plus.

Of course this particular setup only allows for situations where you set an alarm, there’s no option for taking an nap for an unspecified amount of time. I should mention that my latest version of this setup has an option built in to allow for an alarm-less nap, which affects both what it says, what the second click of the button does, and so on. I chose to present the simpler version as to not end up with a schematic that would resemble driving instructions from Apple Maps, and because the system wasn’t built that way from the ground up – likely making it more complicated than necessary. If anyone really wants the details of the second mode however, leave a comment below and I’ll respond with a rundown of what needs to be changed.

Pocketables does not accept targeted advertising, phony guest posts, paid reviews, etc. Help us keep this way with support on Patreon!
Become a patron at Patreon!

Andreas Ødegård

Andreas Ødegård is more interested in aftermarket (and user created) software and hardware than chasing the latest gadgets. His day job as a teacher keeps him interested in education tech and takes up most of his time.

Avatar of Andreas Ødegård