New IFTTT queries: query all types of variables in your IFTTT applets

Hello everyone!

We are happy to announce a little extension to our IFTTT integration: you’ll now be able to use queries in IFTTT to get your variable values into your applets. This lets you build very interesting applets including filter code to do even more with your applets.

As always, for complex automations that don’t require filter code, you can simply build them in Apilio directly!

New Variable queries

To query a variable in IFTTT, you’ll just need to specify the variable name:

You’ll need to add filter code to use the information from the query.

How are queries used in IFTTT?

In IFTTT, you can use triggers, queries and actions to build Applets. Triggers specify what has to happen in order for your applet to get started. Queries check values/states of elements to make more complex decisions. Actions are what gets executed as a result of the applet being evaluated. Adding queries to your applet allows you to use this information in what IFTTT calls “filter code”, which is JavaScript code that you can write to specify whether to actually run the action or not.

brands are slowly adding queries to their services: https://platform.ifttt.com/blog/the-art-of-the-query and you can find these when you look at the service’s main page:

https://ifttt.com/apilio/details → Let’s you see all available triggers, queries and actions

Apilio is a Swiss Army knife, full of possibilities!

:crown: Even if a service in IFTTT today doesn’t have queries, you can build these yourself using Apilio as your storage service for data. :crown:

Using Apilio to build queries for services that don’t have them yet

  • Create a variable to store your data. Depending on the type of data you are storing, you’ll choose a boolean (yes/no, on/off information), a numeric variable (stores figures) or a string variable (stores text)
  • Create an applet that starts with the service that is lacking a query: your trigger will be the information you want to gather and store for your query
  • The action for your applet will be to update the variable you first created in Apilio
  • You can now use this variable as a query in any applet

What is filter code?

JavaScript! If this is not your forte, IFTTT has put together a few examples: it’s easier to look at the format of the example that matches what you want to achieve and modify it to suit your use case.

I need some examples!!

Here you’ll find some examples from IFTTT using queries and filter code:

You can also visit these three examples we have created to illustrate what can be build with Apilio’s queries:

:large_blue_circle: Boolean variable query in IFTTT
:orange_circle: Numeric variable query in IFTTT
:red_circle: String variable query in IFTTT

A couple of tips

Tip #1: times are always UTC

You’ll see that you can use timestamps in your filter code for queries, remember these are always in UTC.

Tip #2: your query won’t run if your variable has no history!

If you are using previous states for a variable that doesn’t have them, your applet will fail due to this. For example, using Slack:

const changeDate = new Date(Apilio.booleanVariableHistory[0].UpdatedAt);

Slack.postToChannel.setMessage('Updated ' + 
Apilio.booleanVariableHistory[0].VariableName + ' from ' + 
Apilio.booleanVariableHistory[1].Value + ' to ' + 
Apilio.booleanVariableHistory[0].Value + ' at ' + changeDate.getHours() +':' + 
changeDate.getMinutes() + '\n Source: ' + Apilio.booleanVariableHistory[0].URL)

You can see we are using both Apilio.booleanVariableHistory[1] and Apilio.booleanVariableHistory[0]. But if the variable has no history, value 1 won’t exist. Please be careful if this is the case with your variables: make sure the history will be populated if you intend on using it.

I have more questions

As always, put them below, we are happy to help!

2 Likes

That looks very interesting, and it is really good that you have posted some examples, as I don’t find it easy to write code in the Filter section.

2 Likes

It can take a few tries to get it right! :slight_smile: Finding ready-made examples can be super-helpful I think.

1 Like

Hi @Anna ,

This is great news, and extremely useful.

But… you only allow one query to each type of variable, which means that you can’t action things that depend (for example) on more than one Boolean value. I have a horrid suspicion that this is an IFTTT limitation… is that the case?

Robin

1 Like

Hey @robin, you are right that IFTTT only allows one type of trigger, query or action per applet today, it’s a known limit today. You can see that it happens for every element and not just queries.

1 Like

Hi @Anna , how many entries can we expect the history to hold?

1 Like

We return up to the last 10 values of a variable :slight_smile:

1 Like

Thanks @Anna … Haha… should have checked! Thanks for this. :smiley:

I’ve been musing about how you could get around this, as I can see instances where it would be great to have access to more than one variable value… I suppose if you needed more than one value it might be possible to stack up the history of a dummy variable to allow different values to be read from a history query. So, after an IFTTT trigger, rather than acting on this direct, you could call an Apilio logicblock “load_up_variables”, then in that logicblock do:

  • Webhook to add variable1 to dummy_variable
  • Webhook to add variable2 to dummy_variable
  • Webhook to add variable3 to dummy_variable
  • Webhook to add variable10 to dummy_variable
  • Call IFTTT routine “Process multiple variables”

When that subsequent IFTTT routine is then triggered, it should be possible to use the “History of xxx values” query to return dummy_variable and so access up to 10 multiple values in the filter, and act on that accordingly in the action.

Would that work? Would the Apilio webhook calls to set up the dummy_variable be implemented in strict chronological order, so that you could depend on them holding the variable that you wanted in the appropriate array location?

1 Like