Differences
This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision | |||
| indigo_2023.2_documentation:shortcuts [2024/05/08 19:38] – [Obtaining an API Key] davel17 | indigo_2023.2_documentation:shortcuts [2025/04/14 20:10] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| + | ===== Using Apple Shortcuts with Indigo ===== | ||
| + | Apple' | ||
| + | |||
| + | If you'd like to ask questions or share your Shortcuts success stories with others, use the [[https:// | ||
| + | |||
| + | * The shortcuts app for macOS is only available for Monterey (12.x) and newer versions. It has been available for iOS and iPadOS since version 12.</ | ||
| + | |||
| + | ==== Obtaining an API Key ==== | ||
| + | In order to use authorization keys as used in the following examples, you'll need an active Indigo Up-To-Date subscription and an activated reflector. | ||
| + | |||
| + | - Log into [[https:// | ||
| + | - Go to '' | ||
| + | - Select the Server that you want to use to accept the key. | ||
| + | - Click on the '' | ||
| + | |||
| + | <color red> | ||
| + | ==== Building Your First Shortcut ==== | ||
| + | Building your shortcut in the Shortcuts app is largely the same whether you do it on macOS or iOS, and -- depending on the type of activity you want to initiate -- only takes a couple of steps. The information you'll need depends on what you want to do, but all the API events are constructed in the same way. For this example, we'll use the macOS Shortcuts App to build our shortcut (you can also do it on iOS and iPadOS). At first, this looks like a lot of steps, but there' | ||
| + | |||
| + | You'll need: | ||
| + | * The base URL: '' | ||
| + | * Your authentication key: '' | ||
| + | * The command you want to execute -- such as: '' | ||
| + | * The Indigo ID of the device (or action, or variable, etc.) you want the command to apply to: '' | ||
| + | * Any parameters you want to include (some are optional, some are required.) | ||
| + | |||
| + | === The Steps === | ||
| + | - New shortcut ('' | ||
| + | - In the search box on the right side, type "Get Contents of URL". | ||
| + | - Drag (or double-click) the action to add it to the editor. | ||
| + | - Click on the '' | ||
| + | - Click on "Show More". | ||
| + | - Select Method: '' | ||
| + | - Expand the Headers section by clicking on the ''>'' | ||
| + | - Within the Headers section, click the '' | ||
| + | - Under Key: '' | ||
| + | - Under Value: '' | ||
| + | - Make sure that '' | ||
| + | - Within the Request Body section, click the '' | ||
| + | - Under Key: '' | ||
| + | - Under Value: '' | ||
| + | - Within the Request Body section, click the '' | ||
| + | - Under Key: '' | ||
| + | - Under Value: '' | ||
| + | |||
| + | At the top of the Shortcut editor window, you can change "Get Contents of URL" to something descriptive like " | ||
| + | |||
| + | {{: | ||
| + | |||
| + | Once you've built and tested your first Shortcut, it's easy to duplicate and edit additional shortcuts. All HTTP API commands should work in a similar way. | ||
| + | |||
| + | === Optional Parameters === | ||
| + | In order to add parameters to the command (for those calls that take parameters -- not all commands do), you include those as a dictionary attached to the command payload like this: | ||
| + | |||
| + | <color red> | ||
| + | |||
| + | {{: | ||
| + | |||
| + | Of course, you can add additional Shortcuts Apps and Actions to the workflow as needed. | ||
| + | |||
| + | ==== Action Group Shortcuts ==== | ||
| + | There is currently only one API command for Action Groups -- '' | ||
| + | |||
| + | * The command: '' | ||
| + | * The Action ID: 123456 | ||
| + | |||
| + | {{: | ||
| + | |||
| + | ==== Variable Shortcuts ==== | ||
| + | === Get a Variable Value === | ||
| + | This example shows how to obtain a variable' | ||
| + | |||
| + | {{: | ||
| + | |||
| + | * You can get an individual variable object by referencing its Indigo ID directly '' | ||
| + | |||
| + | * The " | ||
| + | |||
| + | {{: | ||
| + | |||
| + | === Update a Variable Value === | ||
| + | There is currently only one API command for Variables -- '' | ||
| + | |||
| + | * The command: '' | ||
| + | * The Action ID: 123456 | ||
| + | * A parameters dictionary that has one key/value pair (required): | ||
| + | * '' | ||
| + | * the new variable value <color red> | ||
| + | |||
| + | {{: | ||
| + | |||
| + | === Variable Value as a Conditional === | ||
| + | You can include conditions in your shortcuts and take action -- or not -- based on the condition. For example, turn on a light -- but only if it's dark outside. | ||
| + | |||
| + | {{: | ||
| + | |||
| + | * As with the other examples, set up your '' | ||
| + | * Take the returned dictionary and extract the value of the '' | ||
| + | * Add an '' | ||
| + | * If the Text value is not '' | ||
| + | |||
| + | ==== Running an External Python Script ==== | ||
| + | In most instances, it's recommended that you use Indigo' | ||
| + | |||
| + | The example below prompts the user for text, passes the text to the script, receives the script' | ||
| + | |||
| + | - Shell: //'' | ||
| + | - Pass Input: //'' | ||
| + | |||
| + | |||
| + | {{: | ||
| + | |||
| + | The rest is up to you. | ||
| + | |||
| + | **Note: the Run Shell Script action is not supported on iOS or tvOS.** | ||
| + | |||
| + | ==== Using Your Shortcuts ==== | ||
| + | How you use your shortcuts is a matter of taste -- and you can always run them from the shortcuts app -- but here are a few other suggestions to get you started: | ||
| + | |||
| + | * Save shortcuts to your Home Screen in iOS (using the Share menu), | ||
| + | * Using a Shortcuts Widget, | ||
| + | * Create a folder of your shortcuts on iOS to mimic a widget, | ||
| + | * Add shortcuts to the Dock in macOS (File menu), | ||
| + | * Using Siri: "Hey Siri -- Living Room Lamp" (name of the shortcut). | ||
| + | |||
| + | === Location Based Shortcuts === | ||
| + | You can run location-based shortcuts too, but they require " | ||
| + | |||
| + | * Time of Day, | ||
| + | * Alarm, | ||
| + | * Sleep, | ||
| + | * Arrive, | ||
| + | * Leave, | ||
| + | * Before I Commute, and | ||
| + | * and many others. | ||
| + | |||
| + | Location-based shortcuts are not currently available in macOS (so you'll need to set up the location control piece on iPhone or iPad). The '' | ||
| + | |||
| + | **Using the Indigo Reflector service is recommended (the URL you use for a location-based shortcut can't be one that only works on your local network.)** | ||
| + | - Review your automation. | ||
| + | |||
| + | - Create the shortcut using the steps outlined above using macOS or iOS. For example, you could update a variable value set to '' | ||
| + | - In the Shortcuts app for iOS (or iPadOS), select '' | ||
| + | - Click the '' | ||
| + | - Choose " | ||
| + | - Choose '' | ||
| + | - On the Location setting, select '' | ||
| + | - Select " | ||
| + | - Select '' | ||
| + | - Search for and select "Run Shortcut" | ||
| + | - Next to " | ||
| + | - Select '' | ||
| + | |||
| + | Now, your iPhone (or iPad) should run your shortcut when you Arrive/ | ||
| + | |||
| + | If you don't like the requirement to confirm the shortcut each time, there are other apps that allow for URL calls to be fired based on location. | ||
| + | |||
| + | ==== Firing Shortcuts From Indigo ==== | ||
| + | Using shortcuts to make Indigo //do something// is an awesome feature. But you can also use Indigo to run your shortcuts as well. | ||
| + | |||
| + | === Run from Indigo Action === | ||
| + | The easiest way to run a shortcut is via an Indigo Action (this feature was introduced with Indigo 2023.1). Create a new Action and select ''// | ||
| + | |||
| + | {{: | ||
| + | |||
| + | === Run from the Command Line === | ||
| + | When calling a shortcut from the "Run Shell Script" | ||
| + | |||
| + | {{: | ||
| + | |||
| + | This specific approach requires the shortcut to be accessible by the Indigo server machine. If you don't have access to your shortcuts on the server, there are other ways to do this such as using Indigo to send a text message and linking the shortcut to Messages. Note that the Run Shell Script action doesn' | ||
| + | |||
| + | === Run Shell Script Action === | ||
| + | Sometimes, you may want to pass information to your shortcut from Indigo. For example, you can have Indigo fire a Notification on the server machine that includes real-time information. In this example, Indigo is asking the shortcut to run, and then the shortcut requests the pertinent data through the HTTP API. | ||
| + | |||
| + | - Run the shortcut using a Run Shell Script Action. | ||
| + | - Configure the shortcut to request the text value from Indigo using the appropriate API method outlined above. | ||
| + | |||
| + | {{: | ||
| + | |||
| + | === Run Python Script Action === | ||
| + | If you'd like to avoid the round trip of the example above, you can pass data directly to a shortcut using a simple Python script. In this example, we'll use Indigo' | ||
| + | |||
| + | == os.system() == | ||
| + | <code python> | ||
| + | import os | ||
| + | |||
| + | val = indigo.variables[123456].value | ||
| + | os.system(f'/ | ||
| + | </ | ||
| + | Note the escaped double-quotes for the shortcut payload. These are important to ensure that payloads with embedded spaces are sent as an encapsulated string object. For more information on the //'' | ||
| + | |||
| + | **Apple Shortcut** | ||
| + | * Get Text From - Shortcut Input | ||
| + | * Calendar - Add New Event | ||
| + | |||
| + | {{: | ||
| + | |||
| + | == subprocess.run() == | ||
| + | When using the //'' | ||
| + | |||
| + | <code python> | ||
| + | import subprocess | ||
| + | result = subprocess.run(['/ | ||
| + | </ | ||
| + | Notice that the input is also a bytes object and will need to be decoded to use it. With this command, the shortcut will receive //'' | ||
| + | |||
| + | This type of call would be useful for things like getting a list of upcoming appointments or reminders. For example, you could send the number of appointments you want in the //'' | ||
| + | === External Shell Scripts === | ||
| + | You can also accomplish the same result using a shell script. | ||
| + | |||
| + | - Create your Notification shortcut named "Test Alert": | ||
| + | - Create a new shortcut and add the "Show Notification" | ||
| + | - For '' | ||
| + | - Double-click " | ||
| + | |||
| + | It should look something like this: | ||
| + | |||
| + | {{: | ||
| + | |||
| + | Using a plain text editor, create a new file called '' | ||
| + | |||
| + | < | ||
| + | #!/bin/bash | ||
| + | |||
| + | # Note that redirects such as `pipe` aren't supported in the Indigo Run Shell | ||
| + | # Script dialog and will require a script file method. | ||
| + | |||
| + | echo " | ||
| + | </ | ||
| + | |||
| + | We need to make our script executable, so in Terminal, head to the folder where your script is saved and type: | ||
| + | '' | ||
| + | |||
| + | - Under Actions, create a new Action (or add a new Action to an existing Action Group. | ||
| + | - Select Type: '' | ||
| + | - Select '' | ||
| + | - Enter the full path to your script and the custom message you want to send: ''/ | ||
| + | - If you like, you can elect to have the result saved to an Indigo Variable (optional). | ||
| + | - Select '' | ||
| + | |||
| + | From within Indigo, execute your action. The custom message you sent (in this example, "Hello world." | ||
| + | |||
| + | {{: | ||
| + | |||
| + | You probably want to send something more interesting than '' | ||
| + | |||
| + | < | ||
| + | |||
| + | Notice the quotes around the substitution. If you don't enclose the substitution in quotes, you'll get the variable text value only up to the first space. Quotes will ensure the whole value is sent. | ||
| + | |||
| + | {{: | ||
| + | |||
| + | The opportunities here are only limited by the boundaries of the Shortcuts app. For example, you could add the value of a variable to your Calendar or send the value to a text message. | ||
| + | |||
| + | ==== Firing Your Shortcuts with Siri ==== | ||
| + | Of course, you can have Siri run your shortcut by saying the name of the shortcut you want to run. To run the '' | ||
| + | |||
| + | | Siri Phrase | Action taken | | ||
| + | | "Party Time" | sets lights, temperature, | ||
| + | | " | ||
| + | | " | ||
| + | | " | ||
| + | |||
| + | {{: | ||
| + | |||
| + | ==== Ideas ==== | ||
| + | == Calendar == | ||
| + | * Create a separate calendar called " | ||
| + | * Add weather information to your Calendar. | ||
| + | |||
| + | == Clock == | ||
| + | * Create an alarm on your phone. | ||
| + | |||
| + | == Home == | ||
| + | * Use Indigo to trigger events with your HomeKit devices. | ||
| + | * Use HomeKit to trigger events with your Indigo server. | ||
| + | |||
| + | == Messages == | ||
| + | * Send messages with important information about your Indigo server. | ||
| + | * Trigger your Indigo server by texting a phrase. | ||
| + | |||
| + | ==== Tips ==== | ||
| + | These tips can help make using shortcuts to control Indigo easier: | ||
| + | |||
| + | * If you save your shortcuts to the Home Screen in iOS, be sure you're happy with the look of the icons before you add a bunch of them. Changes you make to the icons later in the Shortcuts app won't update home screen bookmarks automatically (they will change automatically in widgets). | ||
| + | * Put your most commonly used shortcuts first because widgets only display a few at a time. | ||
| + | * You can create shortcuts in the iOS app, but it is **much easier** to create them in macOS. | ||
| + | * With location-based automations, | ||
| + | * Create folders in the shortcuts app that mimic the folders in Indigo. If you find that you can't drag a shortcut to a new folder, it may help to create a " | ||
| + | * If using a local address such as '' | ||
| + | * To use your shortcuts with Apple Watch, edit your shortcut, click on the <color green> | ||
| + | * **Indigo servers running versions of macOS prior to Monterey do not have local access to the Shortcuts app.** | ||
| + | |||
| + | ==== Reference ==== | ||
| + | |||
| + | === Command Line Commands === | ||
| + | Here are a few commands you can run from the command line with the Shortcuts App that may be useful: | ||
| + | |||
| + | | Command | Result | | ||
| + | | '' | ||
| + | | '' | ||
| + | | '' | ||
| + | | '' | ||
| + | | '' | ||
| + | | '' | ||
| + | |||
| + | |||
| + | === Apple Documentation === | ||
| + | [[https:// | ||
| + | [[https:// | ||