Educational resource providing code and project materials for building voice-controlled home automation skills with Alexa and Raspberry Pi.
git clone https://github.com/leeassam/alexa-rpi-skills.gitThis skill repository contains practical code examples and project resources from the online course on building Alexa skills for home automation using Raspberry Pi. It's designed for developers learning to integrate voice control with IoT devices through AWS Alexa and Raspberry Pi hardware. The materials cover real-world projects that teach how to connect smart home components to Alexa-enabled systems, making it ideal for those building their first voice-controlled automation solutions.
[{"step":"Define Your Project Scope","action":"Identify the devices you want to control (e.g., lights, fans, thermostats) and the voice commands you’ll support (e.g., 'Turn on the light'). Customize the [PROJECT_NAME], [ALEXA_SKILL_NAME], [API_ENDPOINT], and sample commands in the prompt template.","tip":"Start with 2-3 devices to keep the project manageable. Use a relay module for high-power devices and GPIO for low-power ones."},{"step":"Set Up Raspberry Pi Hardware","action":"Follow the hardware setup section in the prompt template to assemble the Raspberry Pi, microphone, speaker, and relay module. Ensure all components are powered and connected correctly.","tip":"Use a multimeter to verify GPIO pin voltages before connecting relays. Label wires to avoid confusion during setup."},{"step":"Develop the Alexa Skill","action":"Use the Alexa Developer Console to create a custom skill named [ALEXA_SKILL_NAME]. Define intents, slots, and sample utterances based on your project scope. Configure the endpoint to point to your Raspberry Pi’s public URL (e.g., via ngrok).","tip":"Test the skill’s interaction model in the Alexa Simulator before deploying. Use the 'Build Model' feature to ensure Alexa understands your custom commands."},{"step":"Integrate Alexa with Raspberry Pi","action":"Deploy the Flask server code from the prompt template on your Raspberry Pi. Expose the server to the internet using ngrok, then update the Alexa skill’s endpoint URL. Test voice commands to verify the integration.","tip":"Use `ngrok http 5000` to create a tunnel. For persistent access, set up a dynamic DNS service (e.g., DuckDNS) and configure port forwarding on your router."},{"step":"Expand and Troubleshoot","action":"Add more devices or features to your skill by extending the code. Use the troubleshooting section in the prompt template to resolve common issues like microphone detection or relay failures.","tip":"Log GPIO and Alexa responses to a file for debugging. Example: `python3 app.py > app.log 2>&1`"}]
Learning Alexa skill development with Raspberry Pi integration
Building voice-controlled smart home projects
Implementing IoT automation with AWS Alexa
Following structured course material for home automation
No install command available. Check the GitHub repository for manual installation instructions.
git clone https://github.com/leeassam/alexa-rpi-skillsCopy the install command above and run it in your terminal.
Launch Claude Code, Cursor, or your preferred AI coding agent.
Use the prompt template or examples below to test the skill.
Adapt the skill to your specific use case and workflow.
Create a step-by-step guide for building a voice-controlled home automation skill using Alexa and Raspberry Pi with the provided [PROJECT_NAME]. Include the following sections: 1) Hardware setup for Raspberry Pi, 2) Alexa skill development with [ALEXA_SKILL_NAME], 3) Integration steps between Alexa and Raspberry Pi using [API_ENDPOINT], 4) Testing the skill with sample voice commands like '[SAMPLE_COMMAND_1]' and '[SAMPLE_COMMAND_2]', and 5) Troubleshooting common issues like [ISSUE_1] and [ISSUE_2]. Provide the exact code snippets for each section.
### **Voice-Controlled Home Automation Skill: "Smart Living Assistant"**
#### **1. Hardware Setup for Raspberry Pi**
**Components Required:**
- Raspberry Pi 4 (4GB RAM recommended)
- MicroSD card (32GB, Class 10)
- USB microphone (e.g., Fifine K669B)
- Speaker (e.g., 3.5mm audio jack or HDMI)
- Relay module (e.g., 5V 2-channel relay for lights/fans)
- Jumper wires
- 5V power supply
**Steps:**
1. **Flash Raspberry Pi OS:** Download Raspberry Pi Imager and flash the latest 64-bit OS (e.g., Raspberry Pi OS Lite) to the MicroSD card.
2. **Enable Interfaces:** Run `sudo raspi-config`, navigate to **Interface Options**, and enable **I2C**, **SPI**, and **Serial**. Reboot.
3. **Install Dependencies:**
```bash
sudo apt update && sudo apt upgrade -y
sudo apt install -y python3 python3-pip python3-venv portaudio19-dev
```
4. **Set Up Microphone & Speaker:**
- Plug in the USB microphone and speaker.
- Test audio input/output with:
```bash
arecord -d 5 -r 48000 -f S16_LE -c 1 test.wav
aplay test.wav
```
5. **Connect Relay Module:**
- Wire the relay module to GPIO pins (e.g., GPIO17 for a light, GPIO18 for a fan).
- Install the RPi.GPIO library:
```bash
pip3 install RPi.GPIO
```
#### **2. Alexa Skill Development ("Smart Living Assistant")**
**Steps:**
1. **Create Alexa Skill:**
- Go to [Alexa Developer Console](https://developer.amazon.com/alexa/console/ask) and click **Create Skill**.
- Name it "Smart Living Assistant" and choose **Custom** model with **Provision your own** backend.
2. **Define Invocation Name:** Set the invocation name to **"smart living"**.
3. **Add Intents:**
- **LightControlIntent:** Handles commands like "Turn on the light" or "Turn off the light."
- **FanControlIntent:** Handles commands like "Set the fan to 50%."
- **StatusIntent:** Handles "What’s the status of the lights?"
4. **Configure Interaction Model:**
- Add sample utterances:
- `Turn {action} the {device}`
- `Set the {device} to {percentage}%`
- Add slots for `{action}` (on/off), `{device}` (light/fan), and `{percentage}` (0-100).
5. **Set Up Endpoint:**
- Choose **HTTPS** as the endpoint type.
- Enter the public URL of your Raspberry Pi (e.g., `https://your-domain.duckdns.org/alexa`).
#### **3. Integration Between Alexa and Raspberry Pi**
**Steps:**
1. **Set Up Flask Server on Raspberry Pi:**
```bash
pip3 install flask flask-ask-sdk requests
```
Create `app.py`:
```python
from flask import Flask
from flask_ask_sdk.skill_adapter import SkillAdapter
from ask_sdk_core.skill_builder import SkillBuilder
from ask_sdk_core.dispatch_components import AbstractRequestHandler
import RPi.GPIO as GPIO
app = Flask(__name__)
skill_builder = SkillBuilder()
class LightControlHandler(AbstractRequestHandler):
def can_handle(self, handler_input):
return handler_input.request_envelope.request.type == "IntentRequest" and handler_input.request_envelope.request.intent.name == "LightControlIntent"
def handle(self, handler_input):
slots = handler_input.request_envelope.request.intent.slots
action = slots["action"].value
device = slots["device"].value
if device == "light":
GPIO.output(17, action == "on")
elif device == "fan":
GPIO.output(18, action == "on")
speech_text = f"Turning the {device} {action}."
return handler_input.response_builder.speak(speech_text).response
skill_adapter = SkillAdapter(
skill_builder=skill_builder,
skill_id="YOUR_SKILL_ID",
app=app
)
skill_adapter.register(app=app, route="/")
if __name__ == "__main__":
GPIO.setmode(GPIO.BCM)
GPIO.setup(17, GPIO.OUT)
GPIO.setup(18, GPIO.OUT)
app.run(host="0.0.0.0", port=5000)
```
2. **Expose Raspberry Pi to the Internet:**
- Use **ngrok** to create a public URL:
```bash
ngrok http 5000
```
- Copy the HTTPS URL (e.g., `https://abc123.ngrok.io`) and paste it into the Alexa skill endpoint.
3. **Test the Skill:**
- Use the Alexa Simulator in the Developer Console to test commands like:
- "Alexa, ask smart living to turn on the light."
- "Alexa, ask smart living to set the fan to 50%."
#### **4. Testing the Skill**
**Sample Voice Commands:**
1. **Turn on the light:**
- Alexa: "Turning the light on."
- Raspberry Pi: GPIO17 set to HIGH (light turns on).
2. **Set the fan to 50%:**
- Alexa: "Setting the fan to 50%."
- Raspberry Pi: GPIO18 set to PWM 50% (fan speed adjusts).
3. **What’s the status of the lights?:**
- Alexa: "The light is currently on."
#### **5. Troubleshooting Common Issues**
1. **Microphone Not Detected:**
- Run `arecord -l` to list audio devices. If missing, check USB connections or install drivers.
- Solution: Reboot Raspberry Pi or try a different USB port.
2. **Alexa Skill Fails to Respond:**
- Check the Flask server logs on Raspberry Pi (`python3 app.py`).
- Ensure the ngrok URL is accessible and the endpoint is correctly configured in the Alexa Developer Console.
- Solution: Restart the Flask server and verify the ngrok tunnel is active.
3. **Relay Module Not Working:**
- Check wiring and GPIO pin assignments in `app.py`.
- Test GPIO control manually:
```python
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setup(17, GPIO.OUT)
GPIO.output(17, GPIO.HIGH)
```
- Solution: Reconnect wires or replace the relay module.
**Final Notes:**
- For production, secure the Flask server with HTTPS (e.g., using Let’s Encrypt) and implement authentication.
- Expand the skill by adding more devices (e.g., thermostat, garage door) or integrating with home automation platforms like Home Assistant.AI-powered recruiting for top talent
Automate your browser workflows effortlessly
Get more done every day with Microsoft Teams – powered by AI
Automate your spreadsheet tasks with AI power
Agentic AI Workflow platform
Connected workspace for docs, wikis, and projects
Take a free 3-minute scan and get personalized AI skill recommendations.
Take free scan