Difference between revisions of "Action Blocks"
Tags: Mobile web edit Mobile edit Advanced mobile edit |
|||
(13 intermediate revisions by 2 users not shown) | |||
Line 12: | Line 12: | ||
In some cases you may have common repeated functionality spread throughout multiple macros, for example you may set the brightness low and volume to zero at night time (using day/time trigger) in one macro. You may also wish to do the same elsewhere in another macro (for example using a location trigger when you are at the cinema). By grouping these actions into an action block you can call just a single action to invoke the action block. If you later decide to tweak these settings then you can just update the action block and avoid updating the settings in multiple places. | In some cases you may have common repeated functionality spread throughout multiple macros, for example you may set the brightness low and volume to zero at night time (using day/time trigger) in one macro. You may also wish to do the same elsewhere in another macro (for example using a location trigger when you are at the cinema). By grouping these actions into an action block you can call just a single action to invoke the action block. If you later decide to tweak these settings then you can just update the action block and avoid updating the settings in multiple places. | ||
+ | |||
+ | == Kinds of variables used == | ||
+ | |||
+ | Action blocks work with their own set of variables (plus Global ones if necessary) whose values can be passed from/to the calling macro. | ||
+ | |||
+ | Three kinds of variables can be used inside an action block: Input, Output and Working ones. Each one can be of any type (boolean, integer, decimal, string, array/dictionary). | ||
+ | |||
+ | All these variables are implicitly local and their lifetime is limited to action block execution. Their default values (see below) will be restored at the end of the execution so it is not possible to retreive previous values from a previous run (except when using Global variables). | ||
+ | |||
+ | Working variables are used to make all kinds of calculations/comparisons inside the action block, like any variable according to its type. The only difference with Input and Output ones is that they <b>do not appear</b> in the variables list when configuring the call, as they are not useful to the calling macro. | ||
+ | {|border="1" cellpadding="2" | ||
+ | |+Schematic way variables interact between Macros and Action blocks | ||
+ | !width="10"|Step # | ||
+ | !width="150"|Where from | ||
+ | !width="150"|Kind of variable | ||
+ | !width="400"|When | ||
+ | |- | ||
+ | |1 | ||
+ | |Macro | ||
+ | |rowspan="2"|Local<br/>Input | ||
+ | |rowspan="2"|Call configuration time | ||
+ | |- | ||
+ | |rowspan="3"|2 | ||
+ | |rowspan="3"|Action block | ||
+ | |- | ||
+ | |Input<br/>Working<br/>Output | ||
+ | |Action block process | ||
+ | |- | ||
+ | |rowspan="2"|Output<br/>Local | ||
+ | |rowspan="2"|Call configuration time | ||
+ | |- | ||
+ | |3 | ||
+ | |Macro | ||
+ | |} | ||
== Input and Output Parameters == | == Input and Output Parameters == | ||
Line 19: | Line 53: | ||
For example suppose you wanted to convert from Celsius to Fahrenheit from within multiple macros. You could create an action block to do this that will take in an input parameter in Celsius and return an output parameter in Fahrenheit. The input parameters are available as local variables anywhere it makes sense to read a value. For example you can access the local variable in a pop up message, or in an expression when setting another variable value. The output variables are available as local variables anywhere it makes sense to set the value. For example in the set variable action you can assign to any output parameter. | For example suppose you wanted to convert from Celsius to Fahrenheit from within multiple macros. You could create an action block to do this that will take in an input parameter in Celsius and return an output parameter in Fahrenheit. The input parameters are available as local variables anywhere it makes sense to read a value. For example you can access the local variable in a pop up message, or in an expression when setting another variable value. The output variables are available as local variables anywhere it makes sense to set the value. For example in the set variable action you can assign to any output parameter. | ||
− | Each input parameter will specify a default value and this value will be set in the case where you run a local test | + | Each input parameter will specify a default value and this value will be set in the case where you run a local test or if you do not specify an input value when calling the action block from a macro. Likewise all output parameters define a default value. In the case that the action block doesn't set an explicit value on an output parameter, it's default value will be returned. |
When calling the action block you can specify what values will be passed in as input parameters and assign variables (either local or global) to capture the returned output parameters. You can also ignore any or all return parameters if you desire. | When calling the action block you can specify what values will be passed in as input parameters and assign variables (either local or global) to capture the returned output parameters. You can also ignore any or all return parameters if you desire. | ||
+ | |||
+ | == Differences between an action block and a macro?== | ||
+ | A quick explanation might be: Macros are programs, Action blocks are functions. | ||
+ | Below is a table that better describes the main differences. | ||
+ | |||
+ | {| border="1" cellpadding="2" | ||
+ | !width="500"|Capabilities | ||
+ | !width="80"|Macros | ||
+ | !width="80"|Action blocks | ||
+ | |- | ||
+ | |Has a disabling switch | ||
+ | |Yes | ||
+ | |No | ||
+ | |- | ||
+ | |Can be categorized | ||
+ | |Yes | ||
+ | |No | ||
+ | |- | ||
+ | |Has a trigger component | ||
+ | |Yes | ||
+ | |No | ||
+ | |- | ||
+ | |Triggers can be constrained individually | ||
+ | |Yes | ||
+ | |N/A | ||
+ | |- | ||
+ | |Has an action set component | ||
+ | |Yes | ||
+ | |Yes | ||
+ | |- | ||
+ | |Actions can include “Wait For Trigger" | ||
+ | |Yes | ||
+ | |No | ||
+ | |- | ||
+ | |Actions can be grouped into condition sets | ||
+ | |Yes | ||
+ | |Yes | ||
+ | |- | ||
+ | |Actions can be constrained individually | ||
+ | |Yes | ||
+ | |Yes | ||
+ | |- | ||
+ | |Has a constraint set component applied to all actions | ||
+ | |Yes | ||
+ | |No | ||
+ | |- | ||
+ | |Can create, read & update global variables | ||
+ | |Yes | ||
+ | |Yes | ||
+ | |- | ||
+ | |Can create, read & update calling macro's local variables | ||
+ | |N/A | ||
+ | |No | ||
+ | |- | ||
+ | |Can include Input variables | ||
+ | |No | ||
+ | |Yes | ||
+ | |- | ||
+ | |Can include Working variables | ||
+ | |No | ||
+ | |Yes | ||
+ | |- | ||
+ | |Can include Output variables | ||
+ | |No | ||
+ | |Yes | ||
+ | |- | ||
+ | |} |
Latest revision as of 20:23, 29 March 2023
Introduction
Action blocks allow you to group related actions together that can then be called from elsewhere as a single action (the "Action Block" action).
The action blocks feature can be accessed from the "Action Blocks" home screen tile. Pressing this will take you to a list of currently defined action blocks (or an empty list if you haven't defined any yet). From this list you can press the + button to add a new action block.
Each action block must be given a unique name and contain at least one action. A description is optional and you can also specify input and/or output parameters if you desire.
When to Use
The main reason to use action blocks is to minimize duplicated blocks of actions throughout your macros.
In some cases you may have common repeated functionality spread throughout multiple macros, for example you may set the brightness low and volume to zero at night time (using day/time trigger) in one macro. You may also wish to do the same elsewhere in another macro (for example using a location trigger when you are at the cinema). By grouping these actions into an action block you can call just a single action to invoke the action block. If you later decide to tweak these settings then you can just update the action block and avoid updating the settings in multiple places.
Kinds of variables used
Action blocks work with their own set of variables (plus Global ones if necessary) whose values can be passed from/to the calling macro.
Three kinds of variables can be used inside an action block: Input, Output and Working ones. Each one can be of any type (boolean, integer, decimal, string, array/dictionary).
All these variables are implicitly local and their lifetime is limited to action block execution. Their default values (see below) will be restored at the end of the execution so it is not possible to retreive previous values from a previous run (except when using Global variables).
Working variables are used to make all kinds of calculations/comparisons inside the action block, like any variable according to its type. The only difference with Input and Output ones is that they do not appear in the variables list when configuring the call, as they are not useful to the calling macro.
Step # | Where from | Kind of variable | When |
---|---|---|---|
1 | Macro | Local Input |
Call configuration time |
2 | Action block | ||
Input Working Output |
Action block process | ||
Output Local |
Call configuration time | ||
3 | Macro |
Input and Output Parameters
For more advanced use cases, action blocks allow you the option to pass in input parameters and return output parameters. In this way an action block may be used in a similar way to a function in computer programming.
For example suppose you wanted to convert from Celsius to Fahrenheit from within multiple macros. You could create an action block to do this that will take in an input parameter in Celsius and return an output parameter in Fahrenheit. The input parameters are available as local variables anywhere it makes sense to read a value. For example you can access the local variable in a pop up message, or in an expression when setting another variable value. The output variables are available as local variables anywhere it makes sense to set the value. For example in the set variable action you can assign to any output parameter.
Each input parameter will specify a default value and this value will be set in the case where you run a local test or if you do not specify an input value when calling the action block from a macro. Likewise all output parameters define a default value. In the case that the action block doesn't set an explicit value on an output parameter, it's default value will be returned.
When calling the action block you can specify what values will be passed in as input parameters and assign variables (either local or global) to capture the returned output parameters. You can also ignore any or all return parameters if you desire.
Differences between an action block and a macro?
A quick explanation might be: Macros are programs, Action blocks are functions. Below is a table that better describes the main differences.
Capabilities | Macros | Action blocks |
---|---|---|
Has a disabling switch | Yes | No |
Can be categorized | Yes | No |
Has a trigger component | Yes | No |
Triggers can be constrained individually | Yes | N/A |
Has an action set component | Yes | Yes |
Actions can include “Wait For Trigger" | Yes | No |
Actions can be grouped into condition sets | Yes | Yes |
Actions can be constrained individually | Yes | Yes |
Has a constraint set component applied to all actions | Yes | No |
Can create, read & update global variables | Yes | Yes |
Can create, read & update calling macro's local variables | N/A | No |
Can include Input variables | No | Yes |
Can include Working variables | No | Yes |
Can include Output variables | No | Yes |