Project tutorial

Alexa: Are the Kids Up? © GPL3+

An Alexa app that tells you if your kids are up by using Walabot to uncreeply track them, then possibly wake them up or tell them to sleep.

  • 4,434 views
  • 1 comment
  • 12 respects

Components and supplies

Apps and online services

About this project

As a parent sometimes you want to know if your kids are asleep in their rooms from anywhere in the house. Wouldn't it be great if you could just ask Alexa?

This project uses Walabot target tracking as a non-creepy way (no cameras or microphones) to check on the kids and see if they're in bed or up and about. Connecting it up to a home automation system and throw in a custom Alexa skill and you can check on them from any room in the house. Throw in an Arduino and you can either wake them up or warn them that it's time to settle down to sleep!

Project Demonstration Video

How It Works

A custom skill connects the Echo to Node-Red while a Python TCP program in turn connects the Walabot. Node-RED can send on commands to the Arduino alarm device.

Walabot

Walabot is a programmable 3d sensor perfect for DIY electronics projects. Walabot is a new kind of 3D imaging sensor. It uses radio frequency and will reveal all kinds of things hidden in the world around you. It is handheld, programmable, and the SDK contains a variety of imaging capabilities. The Walabot API will enable you to build your own custom applications.

Node-Red

Node-Red is a browser based tool to let you quickly and easily construct your own logic of handling various IoT devices, including subscribing the TCP messages, listening to Alexa requests, reading and writing to Databases, publishing to MQTT brokers and responding to HTTP requests. It also allows you to define specific functions written in JavaScript to provide complex logic operations, while using a visual, easy to use, drag-and-drop user interface to link different components and logic together.

Node-Red is a very light weighted run time built on top of Node.js, taking full advantage of its event-driven, non-blocking model of operation.

For this application no special nodes need to be installed, out of the box Node-RED can create a HTTP end-point for creating web services.

Alexa Skills Kit

The Alexa Skills Kit (ASK) is a collection of self-service APIs, tools, documentation, and code samples that makes it fast and easy for you to add skills to Alexa. ASK enables designers, developers, and brands to build engaging skills and reach customers through tens of millions of Alexa-enabled devices. With ASK, you can leverage Amazon’s knowledge and pioneering work in the field of voice design.

Quick start steps

  • Install Node-RED
  • Install Python 3.6.X
  • Setup a MQTT broker
  • Install the Walabot SDK
  • Download and install the Python Walabot to TCP socket connector.
  • Setup Node-RED Walabot Flow
  • Setup Node-RED Alexa HTTP endpoint handler Flow
  • Setup custom Alexa skill
  • Setup Arduino end device

Step 1

Install NodeJS https://nodejs.org/en/

Step 2

Install Node-RED https://nodered.org/docs/getting-started/installation

Step 3

Install Python3 https://www.python.org/

Step 4

Install a MQTT broker of your choice, here are some suggestions.

https://www.hivemq.com/ or http://mosquitto.org/

Step 5

Install the Walabot SDK https://walabot.com/getting-started

Step 6

Download the Python connector code.

https://github.com/rondagdag/smart3DSensorForAlexa

Download and Extract the zip file. Execute the Walabot.py program from the command line, append the desired port.

python 

Step 7

Import the Node-Red Walabot Code from here.

The flow parses the XYZ corrdinate data and presents it for your aditional logic and handling. In this case we also send a timestamp when ever the location data updates.

Step 8

Import the Node-RED Alexa endpoint flow from here.

Please note, running this flow on your local machine has some challenges due to Alexa needing HTTPS and certificates. Running this on IBM Bluemix is an easy work around as Bluemix will handle the certificates and it just works.

The flow handles parsing and sorting the requests from Alexa, it returns responses and executes commands. In this case we check to see the last time the walabot registered a movement and returns the number of minutes or hours since movement was seen. If movement was < than 30 minutes the kids are declared as "up". Aditional inject nodes are used to simulate last movement timestamps.

Here are two links to help with creating alexa skills to connect do Node-RED. https://nathan.chantrell.net/20160328/amazon-echo-alexa-skills-kit-integration-with-node-red/

Here is an excelent 11 minute video on how to create a custom Alexa Skill using Node-Red on IBM Bluemix. This video is quick and shows how easy it can be to create a Node-RED Alexa skill.

Step 9

Configure the custom Alexa skill. For more information be sure to watch the video above. There are a lot of resources for learning to build your first alexa skill, you can start by reading the Alexa Skills Kit Documentation.

Intents:

{ 
 "intents": [ 
   { 
     "intent": "QueryIntent" 
   }, 
   { 
     "intent": "CommandIntent" 
   } 
 ] 
} 

Utterances:

QueryIntent for a status report 
QueryIntent for status 
QueryIntent are the kids up 
QueryIntent are the 
QueryIntent are the kids awake 
QueryIntent are they moving 
QueryIntent are the kids moving 
CommandIntent wake them up 
CommandIntent wake the kids up 
CommandIntent get the kids up 
CommandIntent get up the kids 
CommandIntent wake up the kids 
CommandIntent get them up 
CommandIntent wake them up 

Step 10

The Arduino code is a derivative of this project, watch the video and check the video description for more information.

Download the Arduino sketch found below in the project. The configuration of the sketch is all done in the configuration section.

Conclusion

That's about it! Enjoy and expand on your new custom 3D imaging enhanced Alexa skill!

Amazon skill id = 4668ee6b-cb39-4134-9f02-70b04c15c36a

Code

Arduino alarm sketchArduino
/*
//########################################################################
//#  ESP8266 MQTT client, can recieve colors to turn on an LED via MQTT          
//#  Also button press to send out a MQTT message.                            
//#  This can be used along with Node-Red and Twitter                                       
//#  Blog post, videos, and code can  be found at https://www.hackster.io/dfw-hackster/alexa-are-the-kids-up-0f0852 
//########################################################################
*/

#include <ESP8266WiFi.h>
#include <PubSubClient.h>
#include "Timer.h"


//#######Configuration Section#########
//Update these with values suitable for your network and MQTT Broker.
const char* ssid = "ssid";
const char* password = "password";
const char* mqtt_server = "192.168.137.1";
const char* mqtt_topic = "ArduinoIn";
const char* mqtt_Pub_topic = "ArduinoOut";
const char* mqtt_user = "user";
const char* mqtt_password = "password";

//#######General Variables#######
Timer t;
char buf[100];
int lf = 10;
char vInpD5 = 0;
String rx;
String tx;
int  rxLength = 0;
int  txLength = 0;
int Counter = 0;
String payload;
const char* cpayload;
WiFiClient espClient;
PubSubClient client(espClient);
long lastMsg = 0;
char msg[50];
int value = 0;
int TweetCounter = 0;


//#######Void Setup######
void setup() {
  t.every(100, timers);
  pinMode(D1, OUTPUT);
  pinMode(D0, OUTPUT);
  pinMode(D4, OUTPUT);
  pinMode(D5, INPUT_PULLUP);
  pinMode(D6, OUTPUT);
  
  //pinMode(BUILTIN_LED, OUTPUT);     // Initialize the BUILTIN_LED pin as an output
  Serial.begin(115200);
  setup_wifi();
  client.setServer(mqtt_server, 1883);
  client.setCallback(callback);
  Serial.print("Starting...");

}


//#######Setup Wifi######
void setup_wifi() {

  delay(10);
  // We start by connecting to a WiFi network
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);

  WiFi.begin(ssid, password);

  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }

  Serial.println("");
  Serial.println("WiFi connected");
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());
}


//#######Callback for MQTT Messages######
void callback(char* topic, byte* payload, unsigned int length) {\
  //Serial.print("RX: ");
  //Convert and clean up the MQTT payload messsage into a String
  rx = String((char *)payload);                    //Payload is a Byte Array, convert to char to load it into the "String" object 
  rxLength = rx.length();                          //Figure out how long the resulting String object is 
  for (int i = length; i <= rxLength; i++)         //Loop through setting extra characters to null as garbage may be there
  {
    rx.setCharAt(i, ' ');
  }
  rx.trim();                                       //Use the Trim function to finish cleaning up the string   
  Serial.print(rx);                                //Print the recieved message to serial
  Serial.println();

  digitalWrite(D1, LOW);  
  digitalWrite(D0, LOW);  
  digitalWrite(D4, LOW);  
    
  if (rx == "Red") {
    digitalWrite(D1, HIGH);  
    Serial.println("Turning on Red");
    Counter = 1;
  } 
  if (rx == "Green") {
    digitalWrite(D0, HIGH);  
    Serial.println("Turning on Green");
    Counter = 1;
  } 
  if (rx == "Blue") {
    digitalWrite(D4, HIGH);  
    Serial.println("Turning on Blue");
    Counter = 1;
  }
  if (rx == "Magenta") {
    digitalWrite(D1, HIGH);  
    digitalWrite(D4, HIGH);  
    Serial.println("Turning on Magenta");
    Counter = 1;
  }    
  if (rx == "Cyan") {
    digitalWrite(D0, HIGH);  
    digitalWrite(D4, HIGH);  
    Serial.println("Turning on Cyen");
    Counter = 1;
  } 
  if (rx == "Yellow") {
    digitalWrite(D1, HIGH);  
    digitalWrite(D0, HIGH);  
    Serial.println("Turning on Yellow");
    Counter = 1;
  } 
  if (rx == "White") {
    digitalWrite(D1, HIGH);  
    digitalWrite(D0, HIGH);  
    digitalWrite(D4, HIGH);      
    Serial.println("Turning on White");
    Counter = 1;
  }   
  if (rx == "Alarm") {
    alarm();
    delay(1000);
    alarm();
    delay(1000);
    alarm();
    delay(1000);
    alarm();
    delay(1000);           
  }        
   
}


//########MQTT Connection#####
void reconnect() {
  // Loop until we're reconnected
  while (!client.connected()) {
    Serial.print("Attempting MQTT connection...");
    // Attempt to connect
    //if (client.connect(mqtt_topic,mqtt_user,mqtt_password)) {
    if (client.connect(mqtt_topic,mqtt_user,mqtt_password)) {
      Serial.println("connected");
      // Once connected, publish an announcement...
      client.publish(mqtt_topic, "Bridge Connected");
      // ... and resubscribe
      client.subscribe(mqtt_topic);
    } else {
      Serial.print("failed, rc=");
      Serial.print(client.state());
      Serial.println(" try again in 5 seconds");
      // Wait 5 seconds before retrying
      delay(5000);
    }
  }
}


//#######Loop######
void loop() {
  if (!client.connected()) {
    reconnect();
  }

  if (digitalRead(D5) != vInpD5){
    vInpD5 = digitalRead(D5);
    if (vInpD5 == LOW){    
      client.publish(mqtt_Pub_topic, "ButtonPress");
      client.publish("Arduino/Out", "@Electronhacks Tweet from Arduino ESP8266. Hi!");
      Serial.println("ButtonPress");
      rainbow();
    }
    else{
      client.publish(mqtt_Pub_topic, "ButtonRelease");
      Serial.println("ButtonRelease");
    }
  }

  client.loop();
  t.update();
}



void timers(void){
  if (Counter > 0){
    Counter = Counter + 1;
  }
  if (Counter > 60){
    digitalWrite(D1, LOW);  
    digitalWrite(D0, LOW);  
    digitalWrite(D4, LOW);  
    Serial.println("Turning LEDs off"); 
    Counter = 0;      
  }
}

void rainbow(void){
    digitalWrite(D1, HIGH);  //Red
    delay(200);  
    digitalWrite(D0, HIGH);  //Yellow
    delay(200);
    digitalWrite(D1, LOW);   //Green
    delay(200);       
    digitalWrite(D4, HIGH);   //Cyan
    delay(200);      
    digitalWrite(D0, LOW);   //Blue
    delay(200);       
    digitalWrite(D1, HIGH);   //Magenta        
    delay(200);
    digitalWrite(D0, HIGH);
    digitalWrite(D4, HIGH);  
    delay(200);
    digitalWrite(D1, LOW);
    digitalWrite(D0, LOW);
    digitalWrite(D4, LOW);   
}


void alarm(void){
    digitalWrite(D6, HIGH);  //Red
    digitalWrite(D1, HIGH);  //Red
    delay(200);  
    digitalWrite(D0, HIGH);  //Yellow
    delay(200);
    digitalWrite(D1, LOW);   //Green
    delay(200);       
    digitalWrite(D4, HIGH);   //Cyan
    delay(200);      
    digitalWrite(D0, LOW);   //Blue
    delay(200);       
    digitalWrite(D1, HIGH);   //Magenta        
    delay(200);
    digitalWrite(D0, HIGH);
    digitalWrite(D4, HIGH);  
    delay(200);
    digitalWrite(D1, LOW);
    digitalWrite(D0, LOW);
    digitalWrite(D4, LOW);   
    digitalWrite(D6, LOW);  //Red
}

Comments

Similar projects you might like

Arduino Bluetooth Basic Tutorial

by Mayoogh Girish

  • 454,764 views
  • 42 comments
  • 238 respects

Home Automation Using Raspberry Pi 2 And Windows 10 IoT

Project tutorial by Anurag S. Vasanwala

  • 285,663 views
  • 95 comments
  • 672 respects

Security Access Using RFID Reader

by Aritro Mukherjee

  • 229,827 views
  • 38 comments
  • 239 respects

OpenCat

Project in progress by Team Petoi

  • 196,346 views
  • 154 comments
  • 1,364 respects
Add projectSign up / Login