element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Raspberry Pi
  • Products
  • More
Raspberry Pi
Blog Home Automation with Raspberry Pi 4 and Amazon Echo Dot (Alexa)
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Raspberry Pi to participate - click to join for free!
Featured Articles
Announcing Pi
Technical Specifications
Raspberry Pi FAQs
Win a Pi
GPIO Pinout
Raspberry Pi Wishlist
Comparison Chart
Quiz
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: deepakgupta
  • Date Created: 12 Mar 2020 6:54 AM Date Created
  • Views 11677 views
  • Likes 5 likes
  • Comments 7 comments
Related
Recommended
  • home automation
  • raspberry pi
  • Alexa
  • amazon echo dot

Home Automation with Raspberry Pi 4 and Amazon Echo Dot (Alexa)

deepakgupta
deepakgupta
12 Mar 2020

Automate your Home using Raspberry Pi and Amazon Echo Dot

 

Overview:

This project uses an Amazon Echo Dot which is used for natural language processing (NPL) and a Raspberry Pi 4 Board.  We can give a voice command to Alexa device and switch ON/OFF any home appliance like Light, Fan, AC, TV, etc. through a relay connected with the raspberry board using Node-Red.

image

Requirements:

I. Raspberry Pi 4 Model BRaspberry Pi 4 Model B

II. Raspberry Pi 4 Power SupplyRaspberry Pi 4 Power Supply

III. Relay Board Relay Board

 

Raspberry Pi 4 Pin Configuration:

 

image

 

Relay Board Pin Configuration:

image

 

 

 

Procedure for installing Node-Red and Alexa Skill Library:

  1. Insert SD card with Buster OS in the raspberry pi 4. Connect HDMI monitor, keyboard and mouse and power up the board.
  2. Run the following command. It will download and run the script.

bash <(curl -sL https://raw.githubusercontent.com/node-red/linux-installers/master/deb/update-nodejs-and-nodered)

 

This script will:

  • remove the pre-packaged version of Node-RED and Node.js if they are present
  • install the current Node.js LTS release using the NodeSource. If it detects Node.js is already installed from NodeSource, it will ensure it is at least Node 8, but otherwise, leave it alone
  • install the latest version of Node-RED using npm
  • optionally install a collection of useful Pi-specific nodes
  • setup Node-RED to run as a service and provide a set of commands to work with the service

 

“Node-RED has also been packaged for the Raspbian repositories and appears in their list of 'Recommended Software'. This allows it to be installed using apt-get install node-red and includes the Raspbian-packaged version of Node.js, but does not include npm.”

 

    3. The following commands are provided to work with the service:

  • node-red-start - this starts the Node-RED service and displays its log output.
  • node-red-stop - this stops the Node-RED service
  • node-red-restart - this stops and restarts the Node-RED service
  • node-red-log - this displays the log output of the service

You can also start the Node-RED service on the Raspbian Desktop by selecting the Menu -> Programming -> Node-RED menu option.

 

Autostart on boot:

  If you want Node-RED to run when the Pi is turned on, or re-booted, you can enable the service to autostart by running the command:

sudo systemctl enable nodered.service

 

To disable the service, run the command:

sudo systemctl disable nodered.service

 

Once installed as a global module you can use the node-red command to start Node-RED in your terminal and the message will be as bellow.

 

$ node-red


Welcome to Node-RED
===================


11 Oct 23:43:39 - [info] Node-RED version: v1.0.2
11 Oct 23:43:39 - [info] Node.js  version: v10.16.3
11 Oct 23:43:39 - [info] Darwin 18.7.0 x64 LE
11 Oct 23:43:39 - [info] Loading palette nodes
11 Oct 23:43:44 - [warn] rpi-gpio : Raspberry Pi specific node set inactive
11 Oct 23:43:44 - [info] Settings file  : /Users/nol/.node-red/settings.js
11 Oct 23:43:44 - [info] HTTP Static    : /Users/nol/node-red/web
11 Oct 23:43:44 - [info] Context store  : 'default' [module=localfilesystem]
11 Oct 23:43:44 - [info] User directory : /Users/nol/.node-red
11 Oct 23:43:44 - [warn] Projects disabled : set editorTheme.projects.enabled=true to enable
11 Oct 23:43:44 - [info] Creating new flows file : flows_noltop.json
11 Oct 23:43:44 - [info] Starting flows
11 Oct 23:43:44 - [info] Started flows
11 Oct 23:43:44 - [info] Server now running at http://127.0.0.1:1880/red/

 

You can then access the Node-RED editor by pointing your browser at http://localhost:1880 . or http://(your_RPI4_IP_Address):1880.

 

 

 

4. Install node-red-node-pi-gpio library to interact with Raspberry Pi GPIO. It is preconfigured in some of the distribution like Raspbian Buster.

 

5. Install node-red-contrib-alexa-home-skill library in Node-Red. It provides the end point node to bring your commands into Node-RED.

 

cd ~/.node-red npm install node-red-contrib-alexa-home-skill

 

6. Make an account on https://alexa-node-red.bm.hardill.me.uk/docs  and. And add devices as given in the below picture.

 

image

The name you give to the device will be how you access it from Alexa and should be unique, be careful with names like "Livingroom" that may be interpreted as "Livingroom" or "Living room".

 

7. Now start coding on Node-Red editor.

Configuring Nodes in Node-Red editor:

You can find the Alexa Home Skill nodes in the Alexa section of the Node-RED Palette.

image

Dragged an Alexa Home node on to the canvas and configure it as given below.

  • Click      on the pencil at the end of the Accounts line to add a new account
  • Enter your username and password of the account created on https://alexa-node-red.bm.hardill.me.uk/docs

 

image

  • Click OK to return to the node config.
  • The devices dropdown should now be populated with the devices you defined earlier, if not hit the refresh button at the end.

image

You should only create the new config account node once, when adding new device nodes, use the drop-down list to select the existing config node. If you create more than one with the same username and password the service will not work properly.

To start with leave the Auto Acknowledge checked, this tells Alexa that the command has succeeded as soon as it is received by Node-RED.

 

Building Flows:

image

The Switch node works out with below command:

image

In function Node, set massage payload as “0 “and “1” for TurnOff Request and TurnOnRequest respectively as given below.

For TurnOnRequest: Function 1

{

msg.payload = “1”;

return msg;

}

For TurnOffRequest: Function 2

{

msg.payload =”0”;

return msg;

}

 

 

After configuring all node, deploy the code. A green dot will be indicated near the device node which shows that it is connected to end-device and ready to accept the command from amazon echo dot.

 

8. Now make an account on Amazon Alexa and configure your amazon echo dot using Alexa App through your mobile phone and go to “skill and games”. Search for Node-Red skill which has a logo as below.

image

Enable this skill using username and password which you set on  https://alexa-node-red.bm.hardill.me.uk/docs .

 

Now your system is ready to work.

 

9. Give the command to your echo dot as “Alexa, discover devices”. It will discover all your set devices and appear in the mobile Alexa App.

 

10. Now give the command “Alexa, turn on kitchen light”. It will activate the relay connected to the respective GPIO pin of raspberry pi and switch on the light.

 

11. To turn off the light, give the command “Alexa, turn off kitchen light”.

1.     

  • Sign in to reply

Top Comments

  • dubbie
    dubbie over 5 years ago +1
    This is the sort of thing that I wish I could do and understand. Maybe one day I'll take the time to work through all these different steps, but probably not - there are still too many mobile robots still…
  • clem57
    clem57 over 5 years ago +1
    I like this project t:; deepakgupta
  • smartiedust
    smartiedust over 5 years ago +1
    Wait, the relay board spec'd has 5A contacts, but the drawing and article show connecting to household AC, and load devices that could be powered by a regular household circuit, with wiring at 15 to 20…
  • dkgupta
    dkgupta over 5 years ago in reply to paulm330

    Hi Paul,

    Thank you for showing interest in this project.

    Yes, you can use RPi 3B.

    The program code is on node-red. I will check for the momentary output through node-red and compile a new program code.

    I consider your next project. I will try to make this project and post.

     

    Thank you again

     

    - Dipak Gupta

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • paulm330
    paulm330 over 5 years ago

    This is exactly the type of project that many people like me are interested in.  A few questions:

     

    - Can I use a RPi 3B instead of RPi 4B?

    - Can you provide program code for momentary contact rather than SPST?  I have a Sainsmart 16-relay board already hooked up to my RPi 3B. I use python script to actuate the relays on a momentary contact basis, with those relays connected to my home's 24v latching relay system (Touchplate) that controls all the lights in the house.

     

    If you can come up with a RPi 3B project that, in addition to the Alexa control, also provides a simple web server setup accessed through NGROK with a web page with simple buttons/titles to actuate the 16-relay board, that would be great!

     

    Thank you for posting this project.  Cheers!

     

    - Paul

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • michaelklos
    michaelklos over 5 years ago

    Can the PI have Alexa say something?

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • shabaz
    shabaz over 5 years ago

    Hi Dipak,

     

    I think you should mention as a warning in your blog that users should follow their country-specific regulations when constructing this and when connecting to the mains supply and mains-powered equipment, and that only a qualified engineer in that country should install it.

    It's going to be very hard for you to comprehensively detail electrical and assembly requirements so the warning is needed I think. You should also mention that the light-bulb and plug is just shown for illustration, and isn't intended to reflect precisely how the relay is to be wired during electrical installation, and doesn't (for example) show wire type, enclosure requirements, earthing requirements (if needed), connections, any fuses and so on that may be required.

    You may wish to mention that if someone is not qualified but wishes to experiment with this project, then they should use the relays to only switch low voltages.

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • smartiedust
    smartiedust over 5 years ago

    Wait, the relay board spec'd has 5A contacts, but the drawing and article show connecting to household AC, and load devices that could be powered by a regular household circuit, with wiring at 15 to 20 amps - based on wiring gauge & circuit breaker size in the panel.  Unless I'm mistaken, NEC won't allow this unless the circuit breaker were de-rated to the ampacity of the smallest device - that relay.  And the relay must be mounted in an approved, accessible enclosure.

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
>
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube