Using Parameters with Ask Alexa and webCoRE

The Unofficial SmartThings Blog
Jump to navigation Jump to search

Advanced options with Ask Alexa and webCoRE

Its now possible to get Alexa to execute webCoRE pistons and pass through parameters (xParam). It's incredibly powerful and opens a whole host of possibilities.

The addition allows a single Ask Alexa macro to execute a Piston and pass through any parameter that is defined in the skill. The Piston can then act upon the parameter.

Usage of this functionality will be demonstrated using an implementation of a Infrared red remote control server running on an ESP8266 development board. Full details, including the hardware and software configuration for the IR controller, can be found here.


The flow from Alexa to webCoRE is as follows:

  1. Alexa/Echo sends commands to Ask Alexa via the Skill and the Lambda code (e.g. 'Alexa, Ask the 'Kitchen TV' to change the 'channel' to 'BBC ONE) - note 'Kitchen TV' is the skill invocation name, 'channel' is the macro name, and 'BBC ONE' is the parameter (LIST_OF_WCP).
  2. Ask Alexa executes the defined webCoRE Piston through the Macro and passes the parameter to the Piston (the Lambda code calls the Ask Alexa 'Channel' macro and passes the 'BBC ONE' LIST_OF_WCP xParam parameter)

The basics of the flow are shown below

Alexa to webCoRE.png


Configuration

First steps are to get Ask Alexa and webCoRE up and running, follow the detailed instructions in the two links below

Make sure you are using the latest versions of these apps.

To ensure this all works as expected it is recommended working backwards from the webCoRE piston. Create your Piston as needed, making sure you capture the xParam parameter that will be passed. The xParam will be as defined in the skill in the LIST_OF_WCP An example Piston is shown below showing how the parameter is received and can be referenced in the rest of the Piston. The working of this piston is irrelevant in the scope of this article.

Cutdownpistonview.png

However you are using the parameters being passed it is recommended to test it works before configuring Ask Alexa and the skill.

Ask Alexa Macro

With the Piston saved and humming, create an Ask Alexa Macro to link to and execute the Piston, in this case this is the 'Channel selection 'piston.

Extensions.png

  • Open the Ask Alexa SmartApp from the SmartThings mobile app and under Ask Alexa Extensions, select Macros from the Installed extensions section.
  • Select ‘Create a New Macro’ and give it a name. The name here is important as it is what you will ask Alexa. For this example the Macro name is 'Channel' (Alexa, Ask the 'Kitchen TV' to change the 'Channel' to 'BBC ONE'). This needs to be unique.
  • Specify the Macro Type as webCoRE, and select the Piston you just created.

Acck.png

The Advanced features configuration section allows you to manage acknowledgement messages and if you require the additional parameter.

  • If you are specifying a custom acknowledgement you can include '%xParam%' (as written here) within the text and Ask Alexa will add in the additional parameter it received as part of the acknowledgement message.
  • Selecting 'Require Additional Parameter to Run Macro' will stop the macros executing its action if the additional parameter (xParam) is not received from Alexa.
  • If you have specified you require the additional parameter you can also supply a custom acknowledgement message when the parameter is not received from Alexa.
Update Alexa skill

The final step is to tell Alexa about the Macro.


  • Open the Skill in the Amazon developer tool, and under Interaction Model edit the ‘LIST_OF_MACROS’

Alexalistofmacros.png

  • Click Edit (as highlighted above), add in the name of the Macro as you created in the Ask Alexa config.

Macrovalues.png

  • Finally edit the LIST_OF_WCP and add in the parameters (in this example the TV channel names)

Alexalistofxparam.png

XParams.png

   Please Note:
   As of version 2.3.7 of Ask Alexa, you can maintain your xParam 
   list via the main application. Simply go to <<Settings>>
   <<xParams For WebCoRE Macros>> to add these:
   AASettings-1.png
  • Make sure you click Update on both sections when you have updated, finally scroll down to the bottom of the page and click Save.
   The steps above will allow you to quickly add in the Macro to the Alexa Skill, for full details and the recommended method 
   of keeping the Skill updated with custom slot information please refer to 
   Ask Alexa - Custom Slot Information and Ask Alexa - Setup Variables.

You should now be able to say... ‘Alexa, ask the Kitchen TV to change the channel to BBC one’.