Allows Amazon Alexa to control Google Chromecast
This skill supports controlling a single Chromecast or multiple Chromecasts in different rooms. Each Alexa device can be set to control a different room. This is done by matching the room name to your Chromecast device's name. E.g. If your Chromecast is named: "Master Bedroom TV", then set the Alexa room to control to "Master Bedroom"
The following will then pause the Chromecast in the Master Bedroom:
Alexa, ask Chromecast to pause
You can control another room by saying something like:
Alexa, ask the Chromecast to pause in the Media Room
To change the room a particular Alexa device controls you can say:
Alexa, ask the Chromecast to set the room
Here are some example voice commands:
Alexa, tell Chromecast to play
Alexa, tell Chromecast to play songs by Macklemore
Alexa, tell Chromecast to play maroon 5 playlist
Alexa, tell Chromecast to play The Matrix trailer
Alexa, tell Chromecast to set the volume to 5
Alexa, tell Chromecast to stop
Or:
Alexa, ask the Chromecast in the Media Room to stop
Alexa, ask the Chromecast to play in the Media Room
Alexa skills run in the cloud, but this skill needs to be on your local network to control the Chromecast. This skill implements a hybrid approach: the command is handled by Alexa on AWS, which sends a notification to your local server.
The Lambda component is in src/lambda
, and the local component is in src/local
.
Both the Chromecast and the Raspberry Pi (or whatever the local notification handler will run on) MUST be on the same network in order for the Chromecast to be discoverable.
Installation requires a UNIX environment with:
aws configure
, so have an key id and access key ready)
config/interaction_model.json
into the editor, then click "Save Model"sudo pip3 install -r ./src/local/requirements.txt
./start.sh
to start the listener, or ./docker-start.sh
to run in an interactive docker session. Or ./docker-start.sh -d
to run as a service.
The service attempts to AWS SNS using UPNP. If UPNP is disabled in your network you can specify a port. ./start.sh -p 30000
To see other options run ./start.sh -h
or ./docker-start.sh -h
.When run you should see something like the following:
2020-07-12 11:10:40,688 - root - INFO - Starting Alexa Chromecast listener...
2020-07-12 11:10:40,688 - local.ChromecastSkill - INFO - Finding Chromecasts...
2020-07-12 11:10:45,696 - pychromecast - INFO - Querying device status
2020-07-12 11:10:45,727 - pychromecast - INFO - Querying device status
2020-07-12 11:10:45,767 - local.ChromecastSkill - INFO - Found Media Room TV
2020-07-12 11:10:45,768 - local.ChromecastSkill - INFO - Found Living Room TV
2020-07-12 11:10:45,769 - local.ChromecastSkill - INFO - 2 Chromecasts found
2020-07-12 11:10:45,809 - botocore.credentials - INFO - Found credentials in environment variables.
2020-07-12 11:10:46,967 - local.SkillSubscriber - INFO - Listening on http://123.123.123.123:30000
2020-07-12 11:10:46,968 - local.SkillSubscriber - INFO - Subscribing for Alexa commands...
2020-07-12 11:10:47,344 - local.SkillSubscriber - INFO - Received subscription confirmation...
2020-07-12 11:10:47,431 - local.SkillSubscriber - INFO - Subscribed.
./start.sh
The skill subscriber can be run with docker:
./docker-start.sh
- for an interactive session
./docker-start.sh -d
- to run as a service
The skill subscriber (local) uses these environment variables:
.env
file after running aws-setup.sh
)If you have run aws configure
, you will not need to set AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, or AWS_DEFAULT_REGION.
Sets up an AWS environment for the Alexa Skill:
Creates a lambda-bundle.zip, which can be uploaded to an AWS Lambda function.
Runs build-lambda-bundle and automatically uploads the bundle to AWS Lambda.
When the local service starts it searches for Chromecasts on the network. If there are no ChromeCasts found, it will exit.
To fix this, you must confirm that the Chromecast is on and working, make sure you can access it from your phone, and make sure that everything is on the same network.
To debug, a tool to search and list found ChomeCasts is provided at ./search-chromecasts
(make sure to make it executable with chmod +x ./search-chromecasts
).
If the local listener fails to subscribe (no subscribe messages or an error) then the Chromecasts won't receive commands from Alexa By default the local listener uses UPNP and a dynamic port to establish an external connection, you can override this if required.
./start.sh -p 30000
or ./docker-start.sh -p 30000
./aws-update-lambda.sh
docker logs alexa_chromecast --since=30m
, which shows the logs for the last 30 minutes