IFTTT Macros

IFTTT Triggers can pass data on to Actions (IFTTT calls this data Trigger Ingredients).

Some of those data types are things that a person might want to beemind, but they’re not necessarily in a format that the Beeminder Add Datapoint Action recognizes, so rather than try to be overly clever and make guesses about what you meant and if you meant it, we’ve added in some macros for the Value field.

Trigger Ingredients

First lemme provide a little illustration of what I’m talking about with Trigger Ingredients, and how to find them. Setting up an IFTTT recipe from scratch, when you get to the THAT, you’ll find Trigger Ingredients by clicking on the blue erlenmeyer flask that shows up when you click on a text field.

ff502d279d82e5e4

When you pick an Ingredient it then gets subbed into the field like this:

dab58f6593479cfb

Now if you were to send this time ingredient to Beeminder as the value for your datapoint, it would generate an error. This is where our macros come in. So far we’ve noticed two types of Trigger data that people commonly want to send to Beeminder, and made macros.

TOD[]

Say you want to use the time-of-day part of a full DateTime string, e.g., the IssueClosedAt Ingredient I used in the Github example above. Or more likely useful, the AwokeAt Ingredient from Fitbit’s “New Sleep Logged” Trigger. We’ve seen people using the time from this ingredient for “Do Less oversleeping” goals, for example.

Use:

In the Add Datapoint Action’s “Value” field, wrap the Trigger Ingredient with TOD[], so e.g., TOD[{{AwokeAt}}]. (Originally we called this “pumpkin” so that’s what the image shows and both now work.)

d1f9593c3639222e

Then when we get a string TOD[May 12, 2015 at 06:30AM], we will throw away the rest of the date portion and use only the time, 6:30, and submit that to Beeminder just as when you submit 6:30 through the web interface (Beeminder interprets it as 6.5).

HMS[]

IFTTT Triggers also sometimes provide a duration value, e.g., in the case of Fitbit Sleep again, we have TimeAwake, which is the duration of the time Fitbit figures you were actually awake, despite being in sleep mode. This is typically a string that looks like “30m”, or “6h 23m”.

Use:

In the Add Datapoint Action’s “Value” field, wrap the Trigger Ingredient with HMS[], e.g., HMS[{{AwakeTime}}].

Then when we see HMS[] submitted for a Beeminder value from IFTTT, we get rid of the d,h,m,or s part and turn it into a value that Beeminder recognizes, e.g. 6h 23m => 6:23 => 6 + 23/60.

NUM[]

Say you have GoodReads autotweeting your page number and you want to send that to Beeminder. But the tweet is something like “Bethany is on page 54 of 512 of…”. You want to grab just that first “54”.

Use:

In the Add Datapoint Action’s “Value” field, wrap the Trigger Ingredient for the tweet text in NUM[] like NUM[{{Text}}].

SUM[]

We don’t know if you’d ever need this but it sounds theoretically useful! If you wrap a Trigger Ingredient in SUM[] then we’ll parse out all the numbers and sum them up and send that along to Beeminder!

PROD[]

And the same for multiplying, because @peppertoni has a great use case for this with assigning points per minute of different activities.

WORDCOUNT[]

Counts the words between []. So WORDCOUNT[Alpha, Beta, Gamma, Delta, Epsilon] would count 5 words.

CHARCOUNT[]

Same but counts all the characters.


This post is a wiki. Let us know what other macros would be useful!

16 Likes

This looks useful! Will a macro like this be doable to grab page numbers from my Goodreads RSS?
Thanks!

1 Like

Hmm. Looking at this and I think we could do a macro that just looked for the first number in a block of text and used that… (A good example of the sort of thing that could fail in a super confusing way if we just assumed, but works nicely with a macro). It looks like the IFTTT RSS trigger can match on a simple word or phrase, so here’s an item from my GoodReads RSS:

<item>
      <guid isPermaLink="false">UserStatus66774885</guid>
      <pubDate>Tue, 19 May 2015 09:41:04 -0700</pubDate>
          <title><![CDATA[
      Bethany
      is on page 54 of 512 of Thinking, Fast and Slow
    ]]></title>
    <link><![CDATA[https://www.goodreads.com/user/show/360001-bethany]]></link>
    <description><![CDATA[
        <a href="/book/show/12385458-thinking-fast-and-slow"><img align="right" alt="Thinking, Fast and Slow by Daniel Kahneman" hspace="10" src="https://d.gr-assets.com/books/1328312644s/12385458.jpg" title="Thinking, Fast and Slow by Daniel Kahneman" /></a>
      <a href="/user/show/360001-bethany">Bethany</a>
      is on page 54 of 512 of &lt;a href=&quot;/book/show/12385458-thinking-fast-and-slow&quot;&gt;Thinking, Fast and Slow&lt;/a&gt;.
    ]]></description>
    </item>

You could trigger on matches Bethany is on page, and then apply the first number macro to the EntryTitle.

1 Like

We just updated the wiki at the top of this post with new macros! Quick summary:

  • TOD   to extract time of day from a timestamp
  • HMS   to turn things like “6h30m” to 6.5
  • NUM   to extract the first number from arbitrary text like a tweet or RSS entry
  • SUM   to extract all the numbers from arbitrary text and sum them

Let us know what else you might need. We could get arbitrarily fancy and let you specify regexes but @bee suggests that at that point maybe you just want to write your own code and use our API. (But if you’d use more fanciness if we made it available, let us know! This stuff is easy to add.)

4 Likes

Thank you! I had just set up a bunch of kludgy autodata goals, but NUM[] will simplify things a ton for me!

1 Like

Okay so I used

and it seems my recipe did not function like I expected.

My goal instead received a datapoint of 22341276. Any idea where I went wrong?

Here is the RSS target.

1 Like

Looks like the ingredient you’re using, the entry content, has a link in it which contains the number 22341276 before the other numbers. Inspecting the RSS feed, it looks like you should try the EntryTitle.

2 Likes

Can you do Math with these macros? Say I want to mind the time I leave for work in the morning, but my SmartThings presense doesn’t time out (by design) for 15 minutes after I have left. Can I somehow input TOD[time presense left]-15min to compensate for that? (I know I could just change the goal to mind a different amount, I’m just curious if I can correct the input.)

1 Like

I’d love to support that! But before we dive into rabbit holes, is that a real use-case that you’d actually use?

Assuming it is, the shortest path to supporting that use case is probably a bit of rearchitecting on our end so that you can nest the macros. Then you could get what you need like so:

SUM[TOD[{{Time}}], -.25]

or

SUM[TOD[{{Time}}], HMS[15m]]

More generally, it would be cool to support something like

MTH[2+2] → 4

(And it would actually be pretty handy if arithmetic were supported for manual data entry too!)

[Click the heart if you’re excited about any of this and chime in with real-world use-cases that you’d personally use!]

10 Likes

The above is a real use case that I would love to use. I have been trying to figure out how to mind leaving for work for a while. The addition of macros enables it (!), and now I’m just thinking about how to operationalize it.

[There are a couple of other things I have to consider, like how to treat Saturdays and Sundays, when my leave time is more erratic, how to deal with false alarms, etc.]

2 Likes

Thanks a lot for implementing the macros! I already imagine how their introduction will make the recipes I already have even more automated (=> less time consuming).
As for the maths-related macros, here is another real-world example in which it will be highly appreciated:
I have a goal for the number of steps I make a day. I also have a more general physical-activity goal, and I have decided that the number of steps exceeding my daily average accounts towards that goal, each step over the average being 1/1000 of the unit in the physical-activity goal. So I would very much appreciate the possibility to create a recipe using the point entered to steps goals as a trigger component, feeding the result of (X-6000)/1000 into the physical activity goal.
However, even the introduced num macros will help me with this somewhat. I can definitely do the math myself and enter the result into the comment and make the recipe feed on it…

2 Likes

Success! Between these two recipes I can essentially track the whole goal through Goodreads status updates now.

Thank you!

2 Likes

Brilliant! The need for the second “started reading” recipe (using the odometer reset feature) is going to be super confusing to newbees. And it means this only works for beeminding reading when you read books strictly sequentially. It might be time for a proper Goodreads integration!

There’s no way to get the deltas (actual number of pages read) as RSS entries or tweets or anything, is there?

2 Likes

@scarabaea : Also remember that you can chain these together, so if you need multiple calculation steps you can create intermediate (and lenient!) Beeminder goals that calculate one element, then use the IFTTT datapoint-added trigger to feed that to another Beeminder goal…

If that doesn’t satisfy your mad-scientist desires, then you can run your own callback server with arbitrary logic. Here’s example working code in dance.pl.

2 Likes

Wearing my programming language hat, I shudder at the thought of setting
up entire Beeminder goals just to serve as intermediate variables in a
computation!

4 Likes

True! Ideally the intermediate variable will have value in its own right.

e.g. my RunKeeper goal tracks my total mileage (in km, of course), but my ‘exercise’ goal only gets updated if each session exceeds a threshold. That sounds similar to the OP’s desire to only count steps in excess of a threshold as exercise. Both the step-counting and the mileage have some QS value independent of the real-world goal.

5 Likes

Right, that makes sense.

Definitely this would be a better method, since I’ve just found another drawback of my recipes. I read 91 pages and finished my book, but the RSS feed update for completing a book is not the same as the one for progress in a book. It has no mention of page numbers, so there is nothing for an IFTTT recipe to grab.

Therefore, I will still need to manually input the book’s total pagecount when I finish a book. I am glad I noticed this before I started another book and the recipe automatically zero’d the odometer!

2 Likes

Ok, the IFTTT macros are now nestable. So you can do SUM[NUM[{{Ingredient}} TOD[{{OtherIngredient}}]] etc. I’m still holding out on implementing a complete calculator and doing a MATH macro. It seems like overkill to me.

Warning: at this point things are very forgiving/lazy in terms of error checking, so if you have several nested macros, you will only see an error if the final result is not numeric. For example, if you TOD[something that isn’t a time of day], you’ll just get the empty string. Submitting a nothing for a datapoint value will produce an error, but if that TOD[] is nested down inside another macro that does have a numeric result, you won’t hear of the empty TOD.

This is maybe a feature, or maybe a bug, depending on how you look at it :smile:

6 Likes

I would like some math. I have a homebrewed rewards system where I get points for doing positive things. I would like to able to multiply the number of minutes logged to time based goals by their points value. So, I could be given half a point per minute of yoga and three points per minute of running. Then ifttt can send the points straight to my system and I can get more rewards :smile:

I could also see it being useful for those with bucket goals fed by subgoals who want to get twice as much credit for harder tasks or activities.

I don’t need a whole calculator yet but an ability to multiply would be great and I’d use it heaps!

4 Likes