Alexa, tell Chromecast to turn on TV
Connecting Alexa to Chromecast (Google Home)? Yeah, you can do that! And best of all, for free - using Custom Alexa Skill, AWS Lambda, PubNub and running a small backend server on Synology at home, talking to your Chromecast. No need to punch holes through your firewall either!
1. Setup Google Assistant REST interface
Well there is no official one. But, you can use https://github.com/greghesp/assistant-relay to actually setup a relay server which will be exposed as a small Express App. It requires you to setup a Custom Google Assistant Skill, which is all very well documented in the repo.
Once done, you should be able to hit the assistant-relay REST interface with a simple command such as "turn off tv".
Bonus: run on Synology as a Docker container
I could not get the Node repo running on my Synology due to compilation issues with Protobuf, but luckily there is a great Docker image https://hub.docker.com/r/kmlucy/docker-assistant-relay/ which you can run locally with complete isolation from your system's Node. You will however need the JSON credential file and configs from the previous step.
2. Setup custom Alexa Skill
You'd need AWS Developer account to create a custom Alexa skill (register at https://developer.amazon.com). Choose an easy utterance, like "Alexa, tell TV to turn on". This will be the command that will trigger your AWS Lambda function.
3. Register at PubNub
We will be using PubNub to communicate between our Lambda function and backend server. Register for a free account, generate a publisher and subscriber key and note them.
4. Add the AWS Lambda function
When you configure the Alexa skill, you will be asked for a Lambda function to trigger. Choose region close to you, like Ireland if you are in Europe. Also, AWS Lambda is part of free tier for certain number of executions, so no costs there :)
Check the source code at https://bitbucket.org/freshlytyped/tvcontrol and build it locally before uploading to AWS. Use the publisher/subscriber key as variables for your function.
5. Configure your backend server
Because Lambda runs in AWS, it has no way of reaching your locally running Assistant-Relay. In order to do that, you will be running a small Node app subscribed to the same channel as your Lambda function and listening for commands on your local network. I'm running it on my Synology box, but you can run it on Raspberry Pi or wherever, as long as it can reach the host running Assistant-Relay.
Again, check the source code at https://bitbucket.org/freshlytyped/tvcontrol on how to run the backend app, probably using forever
.
Test it
It should all work, but I admit, this write up is slightly technical... You can add log statements if you get lost and wanna debug.