A base for interacting with Habitica's API via Tasker
-
After downloading the files, edit HabitRPGfns.js to match your API values (note the API Token like a password warning!) and CDS. Note that you'll need to uncomment them (remove the
//
at the beginning of the threesetGlobal
lines). -
In your /sdcard/Tasker directory, create a
JavaScript
directory. (You'll probably find other directories here, likelog
anduserguide
.) -
Copy the edited HabitRPGfns.js file to your newly created /sdcard/Tasker/JavaScript directory. If you hadn't edited it yet, you could paste the values in from the mobile app (see Settings/Account Details). After you confirm it's operational, you can recomment or delete those lines. New versions of HabitRPGfns.js will have them commented out.
-
Optionally import the example tasks. Copy them somewhere (e.g. /sdcard/Tasker/tasks) then, within Tasker, Import. The files need to end with ".tsk.xml" to be listed.
For the example task check done, you'll need to change the Variable Set %taskid
action to use one of your own values. I suggest cloning this task (long-press name, menu, Clone) to avoid confusion, or you could import again.
score a task now supports Task ID and direction as parameters (%par1 and %par2), you can simply use it by adding to your personal task the "Perform Task" action: specify the "score a task" task and insert the Task ID into parameter 1 and (optionally) direction into parameter 2.
An easy method to find a Task's ID is to use the User Data Display's Task Overview with "toggle developer data". A cumbersome alternative method is the following.
- Login to HabitRPG from Chrome or Firefox.
- Open the Developer Tools (press F12 or Ctrl+Shift+I).
- Choose the Network tab.
- Sync.
- Select the "user?userV=number" request.
- In the Preview (Chrome) or Response (Firefox) subtab, expand
data
. - For Chrome, find the text you seek, expand the task's entry. For Firefox, expand objects until you find the text you seek.
- The "id" has the value you'll use for the Variable Set
%taskid
action.
NOTE: All task IDs from V2 have changed in V3 so values will need to be corrected. Thanks to API V3 reporting success as true or false, you'll be alerted if you use an invalid ID.
HabitRPGfns.js is commented with each operation's inputs; use %result
(string) or %results
(array, e.g. %results2
and %results3
) as appropriate for your actions' parameters.
Create a profile that, within a Time context, runs once a day (From equals To), with a task of get streaks. No more wondering what the heck your streaks were after you accidentally didn't login for a couple of days!
Create a profile that, within a Time context, runs periodically in the day (repeats), with a task of check due (e.g. every half hour from 11:33 after CDS to 0:33 after CDS). A permanent reminder (with count) of your remaining dailys! Note that there may be a very limited amount of space to display the list (wider in landscape); AutoNotification is one way to display more.
Create a profile that, within a Time context, runs periodically in the day (repeats), with a cloned task of check done (with %taskid
specifically set).
A permanent reminder to do your daily! Optionally add a location context if your daily can't be completed everywhere.
If there's a specific daily you often forget to perform or check off, you can easily create a widget with a tap shortcut of "Perform task" action with score a task, and a profile with time context that periodically does a cloned check done with actions to change the widget's image and/or label depending on task completed (rather than notify). This functionality is included with Tasker, but you can use Zooper Widget or Minimalistic Text or other plugins for further customization.
Using tasker "Perform Task" action with InitChecklist (in conjunction with NextQuestion and score a task-checklist) and passing a tag name as the first parameter (%par1) , you can run a notification based checklist that prompts you with tasks (dailies, habits and to-dos) with that tag. This way you can tag all your morning / evening routine habits and be sure to be reminded when the time comes.
- Strip the emoji short-names from the result.
Variable Search Replace [ Variable:
%result
Search::[\w]+:
*Multi-Line:*Off *One Match Only:*Off Store Matches In: *Replace Matches:*On Replace With: ]
- Display the result but only in the Tasker UI (not elsewhere). Handy for testing.
Popup [ Text:
%result
] If [%caller1
~ui
]
- Clear all Tasker-generated notifications. Handy for testing. (From the main screen's menu: More, Run An Action.)
Notify Cancel
- For a periodic (time context with repeat) profile, make sure you can actually reach the HabitRPG server.
Test Net [ *Type:*Connection Type Store Result In:
%contype
]
Stop [ Task: ] If [%contype
~none
]
- function: replace emoji short-names with Android emoji (Kit Kat/4.4 or newer preferred)
- task: prune streaks-all to a limited count
- scene: add a task; spinners
- scene: augment above to store while offline, sync when getting online (possibly premium)
- LadyAlys: Android's Tasker app and HabitRPG's API
- Diary of a geek (some reverse engineering from screenshots)
- https://github.com/Alys/tools-for-habitrpg, especially the User Data Display
- Others who have submitted pull requests, thanks!
The term "task" is used by both Tasker (one or more actions) and HabitRPG (habit or daily or to-do or reward). I hope the contexts above disambiguate adequately, but please create an issue (or pull request) if something needs fixing.