This project shows you how to setup your node-red setup to allow Alexa to control smart wifi connected devices without the need to invoke a SKILL. Yes that's right you dont need a skill. Lets dig into the nitty gritty
Hue devices and the protocol:
The Philips Hue is one of the APIs that Alexa can directly control after a successful service discovery and provisioning into your Amazon account. Its nicely documented here: https://www.developers.meethue.com/documentation/core-concepts
Since Alexa can directly discover Hue devices, we need to find out how node-red can provide a means to emulate such devices. Fortunately an awesome node exists for this very purpose and is the reason for this tutorial. The awesome people at Originally US have created a wonderful node-red node called Alexa-Local here: https://github.com/originallyus/node-red-contrib-alexa-local
We will go into more depth on how to set things up. But before lets get the setup done and out of our way.
Hardware setup:On the hardware side, you need a Raspberry pi and a 8gb micro sd, along with a wifi controlled switch. In my example, I will use a Electrodragon wifi switch available here: http://www.electrodragon.com/product/wifi-iot-relay-board-based-esp8266/
On how to setup the above switch and get the Tasmota firmware, you can switch over to the tutorial here:
The Raspberry Pi will run our node-red installation: A very elaborate getting started guide is present over at: https://nodered.org/docs/hardware/raspberrypi
We also need a RAK Wireless Wiscore Alexa board, though this tutorial will also work with a regular Alexa modules like the Echo dot, Echo, Tap etc. I suggest the Wiscore module as it is open source and is a development board based on the mt7628 mediatek chipset running openwrt. This opens up possibilities to work on the firmware directly and extend the functions n the Alexa Device SDK.
The WisCore repository can be found at:
https://github.com/RAKWireless/WisCore/wiki/WisCore
Once these two components are setup. Lets move one to the Alexa integration.
Setup your RAK Wiscore board:Setup your RAK wiscore board to connect to the Alexa voice service. A detailed setip procedure is present here: https://www.hackster.io/naresh-krish/home-automation-using-wiscore-and-openhab-1ec6e4
Node-red setup:Once you have your Raspberry Pi setup with Node-Red. Fire up a browser on your desktop and go to:
http://<ip of rpi>:1880
You will be presented with a Node-red blank slate with some nodes already reloaded and ready to be used in your palette.
Note: not everyone would be running their node-red on port 1880. if you have changed the port, please do change the port in the above URL as well.
Now we need to install a cool little node called the ALexa-Local node by the folks at OriginallyUS. What it does is to emulate your node as a hue endpoint. Alexa would in turn discover this service broadcast and add the device into its inventory.
Manually installed nodejs and node-redWe can try and install node-red manually by the following steps:
Install nodejs:
wget http://node-arm.herokuapp.com/node_latest_armhf.deb
sudo dpkg -i node_latest_armhf.deb
Install node-red
sudo npm install -g --unsafe-perm node-red
You can also try to get a node-red setup running by running it as a docker container.
After installing Docker for windows/linux:
1) Open Powershell and execute the following commands:
docker run --network=host -it -p 1880:1880 --name mynodered nodered/node-red-docker
Click on the top right settings icon and proceed to the palette menu:
Search for alexa-local and click on install for the node. You should see a collection of Alexa node in the scrollable left side section like so:
Drag and drop an instance of this node to stage as shown, Also drag a debug node into the stage and connect the same as shown below:
The debug node is just for letting us know thing are working when the Alexa node is triggered. Double click the Alexa local node in the stage and it will bring up a menu like so:
Now name this node as one of the things you want to control. In my case i call it Lab Fan. leave input trigger off for now as you dont want this node to be triggered by another nodes output for this tutorial.
Click done and you should be able to click on the Deploy button on the top right of the node-red screen. Once deployed, On your RAK wiscore device say
Alexa, Discover devices.
Alexa will take some time (usually less than 20 seconds) to discover active devices that are broadcasting or available from a skill. Since ours is a local devices discovery should complete really quickly and you should get a feedback that Alexa found one/more devices. NEATTTTT!
Now its a good time to check if the devices are registered to your Alexa account. Open you Alexa pp on Android and iOS and go to the Smart home section. You should be able to see a device with the same name you gave to your Node.
Note: If your node doesn't show up, make sure after deploying that the node shows as connected like so:
Now, your trigger node is active. Lets connect this to a wifi device in the house. In my case I am using a Electrodragon relay powered by the Sonoff Tasmota firmware for ESP8266. This is a versatile firmware with the support for OTA updates, HTTP/MQTT based web API.
We will concern ourselves with the HTTP API.
To toggle a switch you can call the esp8266 switch with this URL:
http://sonoff/cm?cmnd=Power%20TOGGLE
http://sonoff/cm?cmnd=Power%20On
http://sonoff/cm?cmnd=Power%20off
http://sonoff/cm?user=admin&password=joker&cmnd=Power%20Toggle
where Sonoff can be replaced by the IP of your switch.
Lets add this feature to our node red workflow: Add a HTTP request node like so and connect it with the Alexa node. Attach a HTTP response node to the end of the HTTPrequest node so that we can act on the output of this request (like failure, success etc).
Double click the HTTP request node:
Since this is a simple HTTP request switch off the SSL and authentication header ticks. Enter the URL of the switch we just dicussed above along with the action. Ideally if we say
Note: Here to replace the "sonoff" in the URL to the IP of the sonoff/electrodragon switch.Lets Play!
On your Wiscore board say:
"Alexa, toggle Lab Fan"
Alexa will send the TOGGLE command to the Alexa local node, the local node would then in turn trigger the HTTP request which will pass the request to the sonoff/electrodragon switch and turn it on/off.
Its a good time to also see that this particular switch also shows the updated state in the Alexa App as well.
You can even do other crazy stuff like tweet the action, or send a mail to yourself when someone switches off the lights. The possibilities are endless!
Comments
Please log in or sign up to comment.