Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| indigo_2025.1_documentation:events_data_passing [2025/09/23 10:16] – created davel17 | indigo_2025.1_documentation:events_data_passing [2025/12/14 20:10] (current) – [How do you pass data through?] jay | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| ==== Events Data Passing ==== | ==== Events Data Passing ==== | ||
| + | Many users ask, "How do I know what caused an action to fire?" Our server architecture never passed through any source data before. But, now we do! All built-in triggers and schedules now pass through data that's specific to the event. Here are the basics. | ||
| + | |||
| + | Events now pass an //'' | ||
| + | |||
| + | < | ||
| + | { | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | The ID is the //'' | ||
| + | |||
| + | The //'' | ||
| + | |||
| + | - //'' | ||
| + | - //'' | ||
| + | - //'' | ||
| + | - //'' | ||
| + | |||
| + | Plugin supplied events (for instance, the Z-Wave Command Received event, email received event, or any event that your plugin may provide) will **add** the following plugin specific information: | ||
| + | |||
| + | < | ||
| + | { | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | Plugin events have more data that's specific to the plugin: the event id (from your Events.xml file), your plugin ID, the name. The //'' | ||
| + | |||
| + | === How do you pass data through? === | ||
| + | |||
| + | If your plugin supplies events, then you are aware that in your event handling code you eventually will call the //'' | ||
| + | |||
| + | < | ||
| + | indigo.trigger.execute(trigger_instance) | ||
| + | </ | ||
| + | |||
| + | To pass through any extra triggering data that you might want to add, just add it: | ||
| + | |||
| + | < | ||
| + | message = {" | ||
| + | indigo.trigger.execute(trigger_instance, | ||
| + | </ | ||
| + | |||
| + | `message` can be either an `indigo.Dict` or a normal python //'' | ||
| + | |||
| + | Some notes on standards for your data: | ||
| + | * You won't want to duplicate any of the above built-in names as it would get overwritten. | ||
| + | * You probably want to name your keys with something that's easily identified with your plugin. For instance, the Z-Wave plugin uses the prefix `zwavecmd-` for it's keys that describe the event data that it passes through. | ||
| + | * We tried to use dashes `-` as separators rather than underscores - we think that's a better option for string keys. | ||
| + | * Keys should follow the restrictions on `indigo.Dict` keys (alphanumeric, | ||
| + | |||
| + | FYI, you can pass arbitrary data around using the IOM and the various `.execute()` actions on Triggers, Schedules, and Action Groups. Just pass through //'' | ||
| + | |||
| + | === How will users use the data? === | ||
| + | The data is passed first to any **conditional scripts**. The data can be accessed like this: | ||
| + | |||
| + | < | ||
| + | # event_data is prepopulated with the indigo.Dict from the originating event | ||
| + | if event_data[" | ||
| + | # the triggering event came from the HTTP API, so you may want to look at something | ||
| + | # here. | ||
| + | pass | ||
| + | </ | ||
| + | |||
| + | Regardless of where the data came from (trigger, schedule, etc), the variable name will be //'' | ||
| + | |||
| + | Then once the conditions have been evaulated, the //'' | ||
| + | |||
| + | We've added a new **Insert Event Data into Variable** action which will allow the user to insert all or part of the event data into the specified variable. If they specify a path (see the **box** library description above) and the result of the path is a simple type (string, bool, int, float) then that value will be inserted into the variable. If the result of the path is a collection (dict or list) or the user doesn' | ||
| + | |||
| + | There is also a new substitution, | ||
| + | |||
| + | Embedded script actions will also receive the data in the same way that conditional scripts do. **Note**: external (linked) scripts will not get the data in this release. We will gauge demand moving forward to determine if and when to add it there. | ||
| + | |||
| + | === How will you get the data in your actions? === | ||
| + | |||
| + | You can get the data directly in your actions as well. Event data will be passed to the action method handler | ||
| + | |||
| + | < | ||
| + | def run_shortcut(self: | ||
| + | | ||
| + | dev: any, | ||
| + | | ||
| + | | ||
| + | </ | ||
| + | |||
| + | This is a complete action handler with type hints. While we don't envision a scenario where //'' | ||
| + | |||
| + | === Examples of How Events Data Can Be Used === | ||
| + | There are likely a lot of different scenarios where //'' | ||
| + | |||
| + | Create an Action: | ||
| + | * Create an Action Group called "Log Event Data" | ||
| + | * Select **Server Actions** > **Script and File Actions** > **Execute Script** | ||
| + | * Select Embedded Python and enter the following short script into the code block. Notice that we didn't do anything special to access the //'' | ||
| + | < | ||
| + | indigo.server.log(f" | ||
| + | </ | ||
| + | * Select OK | ||
| + | |||
| + | Create a Trigger to fire the action: | ||
| + | * Create a Trigger called "Log Event Data" | ||
| + | * You can link it to an event, but for this example the event type doesn' | ||
| + | * You can also set a Condition, but for this example the condition doesn' | ||
| + | * On the Actions tab, select **Server Actions** > **Execute Actions Group** | ||
| + | * Select the "Log Event Data" Action you created above | ||
| + | * Select OK | ||
| + | |||
| + | Now, from the Actions list in Indigo, highlight the "Log Event Data" Trigger and select **Execute Actions Only**. When your Trigger fires the script, something similar to the following should appear in the Events log: | ||
| + | |||
| + | < | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | </ | ||
| + | It's that simple. | ||
| + | |||
| + | === Get Creative === | ||
| + | The new //'' | ||