Tutorial: Create a magic spell to turn on lights

This is the lede paragraph for the blog post. It should be populated with dynamic data from a WYSIWYG custom field assigned to your posts.

Written by

Kevin Elgan

Published on

BlogTutorials, Uncategorized

In this skill challenge, we’ll be learning to control smart lights with magic spells from Harry Potter. This is a great skill for all the Potterheads out there to understand how Chatterbox “listens” to speech.

We know that many of you are huge Potterheads (aka Harry Potter fans). So we thought we’d get into creating magic spells to turn on and control smart lights.

What’s a smart plug?

So far, we’ve been making skills that make Chatterbox do things or communicate with different sources of information. But to make Chatterbox control lights, you need additional hardware called “smart plugs” or “smart lightbulbs” that Chatterbox can communicate with.

The current smart plugs and lightbulbs that Chatterbox can communicate are made by TP-Link Kasa. In case you don’t currently have these smart plugs, Amazon currently has a sale for 17% off a two-pack.

We love smart plugs because they can be used to control lights, appliances or anything with a power on/off switch. The rest of this tutorial will assume that you have set up and named your smart plugs.

Enable the Smart Lights Extension

Before we can begin building the skill, we need to first enable the Smart Light Extension to give us access to the Smart Light blocks.

Enable the Smart Lights Extension from the Extension page

Once the extension is enabled, you’ll have access to all the Smart Light blocks. In this skill we are going to focus on two blocks: Turn on TP Link Smart Plug and Find TP Link Device with Name.

For this skill, you’ll need both of these blocks.

The Turn on TP LInk Smart Plug block allows Chatterbox to send a signal to turn on or turn off any smart plug while the Find TP Link Device block, makes it easy to determine which plug you want to turn on/off.

Turn on lights by connecting the blocks and entering the name of your smart plug

How to design spells with Chatterbox

If you’re a “Potterhead,” you know that the magic spell that Harry Potter used to light up his wand was “Lumos.” To turn off the light, the spell was “Nox.” We are going to teach Chatterbox how to respond to these spells.

For the purposes of this tutorial, when Chatterbox hears “Lumos,” we want Chatterbox to respond and turn on the smart plug connected light.

The speak block responds to the command while the smart plug block turns on the device

How Chatterbox Understands Speech

Unlike other smart speakers, Chatterbox only listens when you push the big yellow button. When you push the button, Chatterbox starts listening and translates what it hears into text. If the text matches one of Chatterbox’s commands, then it will speak or do whatever the skill says. If it doesn’t match, then Chatterbox will respond with “I do not know how to answer that, please teach me.”

What does this mean for making skills? Well, it means that while we try to guess how people will talk to Chatterbox, we also have to make sure that we test skills to ensure that Chatterbox will understand.

Turning ON lights with Lumos

Turning on lights using the magic spell “Lumos” is easy. Simply add it to the Listen block as pictured below. By deploying the skill and testing it, we can see that Chatterbox understands “Lumos” without a problem.

Saying “lumos” makes Chatterbox turn on lights

Turning OFF lights with Nox

Now that we can turn lights on, let’s copy the same code to turn lights off. Make sure to change the keyword to “nox,” the response to “Ok, turning off lights” and change the smart plug block to off.

Deploy the skill and try turning off the light. Did it work? NOPE! The reason is that when we say “nox,” Chatterbox hears “knox.” They sound the same but they aren’t a match and therefore Chatterbox responds with the unknown message.

Using the chat window makes it easy to debug skills

In this scenario, this isn’t much of a problem because we can simply add additional examples to the listen block to make it trigger. This was an easy fix but in the future we’ll be getting into trickier situations to make Chatterbox understand human speech.

While magic spells are wonderful for turning lights on and off, not everyone knows all the spells, so it’s always a good idea to use regular examples so anyone in your house can control lights with your Chatterbox.

Putting it all together

Let’s us know what spells and skills that you come up with!

Related Posts