Control Your Chromecast with Amazon Alexa Using a Raspberry Pi and Python
Updated guide for letting your Amazon Echo command a Google Chromecast via a Raspberry Pi running Python.
Overview
Bridging Alexa and Chromecast
Ever wondered if your Alexa can control a Chromecast? This step‑by‑step tutorial explains how to make it happen with a Raspberry Pi, MySQL, and AWS Lambda.
NOTE: For the latest scripts and project files, visit our GitHub repository.
The approach was highlighted in the “AlexaDev Tuesday: Innovative Alexa Skills Spotlight” on LoveMyEcho and showcases how developers can solve complex integration challenges.
Why a Raspberry Pi?
The Pi’s compact size, low power draw, and compatibility with Raspbian make it ideal for hosting the MySQL database, Python script, and network configuration needed for Alexa to reach the Chromecast.
How It Works
- User initiates the skill by saying, “Alexa, launch Chromecast.”
- Alexa sends the requested command (defaulting to a YouTube search) to the skill.
- The skill writes the command into a MySQL table on the Pi.
- A background Python process reads the table, translates the request into a Chromecast command, and executes it.
- After execution, the database entry is removed.
- Alexa confirms completion to the user.
Step 1: Prepare Your Raspberry Pi for Port Forwarding
Before starting, ensure your Pi is connected to the internet and note its IP address.
To find the Pi’s IP:
- Open a terminal on the Pi or another PC.
- Run
ifconfig(Linux) oripconfig(Windows) to locate the default gateway.
Access your router’s admin page via the gateway address and configure port forwarding for:
- 3306 – MySQL (default port)
- 80 – phpMyAdmin (optional)
- 22 – SSH (optional)
Security note: Exposing these ports opens your network to potential risks. Use strong passwords and consider restricting access to trusted IPs.
Step 2: Install MySQL on the Pi
Run the following command on the Pi:
sudo apt-get update && sudo apt-get install mysql-server --fix-missing
Secure the installation with sudo mysql_secure_installation and create a dedicated user for the skill.
Step 3: Install phpMyAdmin (Optional)
Follow a tutorial to set up phpMyAdmin for easier database management.
Run the supplied build.sql to create the required schema.
Step 4: Configure the Scripts
Open index.py and raspberry.py and replace the placeholders:
- RASP_PI_DNS – MySQL server hostname or IP
- MYSQL_USER – MySQL username
- MYSQL_PASS – MySQL password
- DB_NAME – Database name
- CHROMECAST_NAME – Target Chromecast’s device name
Step 5: Deploy the Skill to AWS Lambda
Zip all files except speechAssets and raspberry.py, then:
- Log into the AWS Management Console and open Lambda.
- Click “Create function”, skip blueprint, name it
alexaChromecast, choose Python 3.9 runtime. - Select “Upload a .zip file” and upload your archive.
- Set the handler to
index.lambda_handler, role to “Basic execution”, and timeout to 30 s.
Step 6: Create the Alexa Skill
- Visit Amazon Developer Console and open the Alexa Skills Kit.
- Click “Add a New Skill”, name it “Alexa Chromecast”, set invocation name to “chromecast”.
- Upload the
intentSchema.jsonandsample-utterances.txtfrom thespeechAssetsfolder. - Paste the Lambda ARN in the “Endpoint” field. Disable account linking.
Step 7: Run the Raspberry Pi Script
Transfer raspberry.py to the Pi (via USB or WinSCP). Execute it with:
python3 raspberry.py
Step 8: (Optional) Auto‑Start on Boot
Create a shell script launcher.sh containing:
#!/bin/bash sudo python3 /path/to/raspberry.py
Add a cron job to run launcher.sh at boot:
@reboot /path/to/launcher.sh
Test the skill in the Alexa Developer Console’s “Test” tab. If everything is configured correctly, you should be able to control your Chromecast with voice commands.
Video Demo: Watch here.
Manufacturing process
- Build a Professional Raspberry Pi Universal Remote with LIRC
- Converting RF to DC with a Raspberry Pi: Building and Troubleshooting an Envelope Detector
- Cycle Chaser: Transform Your Bike into a Nighttime Light Show with Raspberry Pi
- Build a Raspberry Pi‑Based Thief Detector – Step‑by‑Step Guide
- Build a Raspberry Pi Home Temperature Monitor with MCP9808, InfluxDB & Grafana
- Build a Raspberry Pi‑Powered Home Automation System for Remote Control
- Smart 3D Sensor: Voice-Activated Lamp Control for Amazon Echo
- Control LEDs with Alexa via Raspberry Pi – Easy Step‑by‑Step Guide
- Control LED Lights with Alexa via Arduino Yun – A Smart Home Tutorial
- Arduino IoT Cloud & Amazon Alexa Integration: A Step-by-Step Guide