A few years back, I visited Vietnam and bought a nice table lamp. Till now it was not used at all. I thought it will be nice to have a table lamp which you can turn on and off using Echo.
Setup a Raspberry PiYou will need a Raspberry Pi board which can be any model: A, A+, B, or B+. Download the Pi image from this download site.
Write the image to a SD card. I am using a Windows 10 machine, so I downloaded the Win32DiskImager utility and wrote the Pi image to a SD card.
For other platforms, you can follow this installation guide.
Find out the IP AddressConnect your Pi to the USB power cable, and also connect the Ethernet cable to your router if you are using Ethernet. Follow the following guide to find out the IP address of Pi:
https://www.raspberrypi.org/documentation/remote-access/ip-address.md
Using PuttyWith that IP address, you can connect thru SSH to the Pi using PuTTY.
Download PuTTY if you have not done so. For details, refer to this document.
.
Install Node.js and other SoftwareYou need to install the latest version of Node.js. To do that, follow the following guide:
http://weworkweplay.com/play/raspberry-pi-nodejs/
Then you need to install some software to access the pins of Raspberry Pi. In a terminal, type:
git clone git://github.com/quick2wire/quick2wire-gpio-admin.git
Then type:
cd quick2wire-gpio-admin
Then:
make
After that type:
sudo make install
Finally, type:
sudo adduser $USER gpio
Finally, you can download the pi-aREST example from our GitHub repository:
https://github.com/marcoschwartz/pi-aREST-example
Hardware configurationWe will start with LED. Connect the LED in series with the resistor, with the longest pin of the LED connected to the resistor. Then, connect the remaining pin of the resistor to pin marked as 18 of the Raspberry Pi (this corresponds to the GPIO pin 12), and the remaining pin of the LED to the GND pin.
Using the pi-aRESTNow go over to the folder where you placed the pi-aREST that you downloaded before and type in a terminal:
sudo npm install pi-arest express
After that, type:
sudo node app.js
You should see the following message in your terminal:
Listening on port 3000
You can now go to any web browser, and type:
http://<your IP address>:3000/
This should return the default ID & name of the Pi, and the available variables in JSON format:
{"id":”34f5eQ”,”name”:”my_new_Pi”,”hardware”:”rpi”,”variables”:{“temperature”:24,”humidity”:40},”connected”:true}
Then, you can light up the LED by typing:
http://<your IP address>:3000/digital/12/1
You will be greeted by this message:
{“id”:”34f5eQ”,”name”:”my_new_Pi”,”hardware”:”rpi”,”connected”:true,”message”:”Pin 12 set to 1″}
And switch it off again with:
http://<your IP address>:3000/digital/12/0
We are going to use IFTTT Alexa channel to turn on and off the PIN. Before we can setup the web request of the Alexa channel, we need to expose the local environment publicly. To accomplish that, we will use the localtunnel.
Install localtunnel
by typing
npm install -g localtunnel
To start a custom subdomain, just type:
lt -s myrasppi -p 3000
You need to create two recipes. One for turning on the light and the other one turning off. You start off with creating the "turn on light" recipe.
Sign in to IFTTT, then click "Create" to create a New Recipe.
Click "this".
Select "Amazon Alexa". Click "Says a specific phrase".
Key in "the light on" at What phrase? Then click "Create Trigger".
Click "that".
Select "Maker".
Click "Make a web request".
Enter URL with value "http://myrasppi.localtunnel.me:3000/digital/12/1", select "GET" method and click "Create Action".
Click "Create Recipe".
You will repeat the above steps to create the "turn off light" recipe. The changes are:
- Key in "the light off" at What phrase?
- Enter URL with value "http://myrasppi.localtunnel.me:3000/digital/12/0"
.
Finishing TouchFollow this guide to add a relay and the table lamp to the hardware configuration. I am wiring a Normally Closed (NC) configuration.
I modified a power extension by adding the relay to it.
This is the relay.
Adding a relay to the power extension.
Front and back of the modified power extension.
Comments