TL;DR: I’ve created a DTH that allows you to talk to your Chromecasts
/ Google Homes. It’s ready for testing if you’re familiar with using
the SmartThings IDE / Github integration and can deal with the
(inevitable) bugs that will show up. There’s only very basic
documentation (this post) at this point.
Components
The Chromecast integration consists of three components:
- Chromecast Manager, the service manager smartapp
- Chromecast DTH
- an intermediary app that runs in the cloud, receiving commands from
the DTH and passing them on to your Chromecast / Google home.
The cloud intermediary
While the rest of the code here is relatively standard, using a cloud
intermediary adds complexity. In particular, it comes with two issues:
- You need create an app running in the cloud.
- That cloud app needs to be able to talk to your Chromecast(s), so
you have to forward outside connections to your Chromecast(s) by using
port forwarding.
Running the cloud app
That app is a node.js webservice that you can find at
https://github.com/germasch/smartthings-cast. I’ve been using
heroku.com to run it at the free tier, but it should run on pretty
much any cloud provider that provides node.js integration.
You can also just use my instance of the app for now, it’s at
https://pure-atoll-25146.herokuapp.com/ . This comes with the
following constraints:
-
It’s using the free tier, so there’s a limit in the number of
requests it can handle, if I run out, this will stop working. Also,
the free tier suspends apps that have seen no activity in the last 30
mins, which causes an additional couple of seconds of delay when
accessing your Chromecast device. -
I can (and do) look at the debug logs, which means I can see your
activity. No passwords or anything are sent to / through the app, but
I can see the IPs / ports of your Chromecasts, and what you’re
playing. In theory, I could tell your Chromecast to stream some
horrible music at max volume at 3am…
The two issues above can be resolved by you running your own
instance.
One further security / privacy issue can’t be easily resolved: The
cloud app needs to talk to your Chromecast(s). In order to do that,
you need to add port forwarding rules to your Router, and those rules
allow the external internet to talk to your Chromecasts. You may be
able to restrict the forwarding to the heroku’s IP pool, which would
greatly help in preventing having the Chromecasts too far out in the open.
Alternatively, in the future I’m hoping to support running the cloud
app locally on your network. That requires some kind of computer to do
so (raspberry pi or pc, or potentially an Android device), and would
avoid the cloud complexity and security concerns.
There will have to be some kind of intermediary for the foreseeable
future, because talking to the Chromecast requires establishing a
websocket, while the local HubAction does not even provide https at
this point. For proper discovery, M-DNS would be needed as well, but
that’s easier to work around.
Service Manager / DTH
Installing the service manager / dth should be fairly straight forward
if you’re familiar with the github integration – the repo is at
https://github.com/germasch/SmartThingsKG , and you need
devicetypes/germasch/chromecast.src/chromecast.groovy
and
smartapps/germasch/chromecast-manager.src/chromecast-manager.groovy
.
Install/publish the DTH, then the smartapp. When you add the smartapp,
it’ll scan your local network for Chromecasts. That uses SSDP, which
is actually the old protocol to discover Chromecasts, but it still
works, though it doesn’t find Chromecast groups (a to-do item).
You can then pick which devices to represent a : s SmartThings devices,
and continue to configuration. First of all, you have to enter the URL
to reach your cloud app, and then for each Chromecast device you have
to provide information on how to access it from your cloud app. In
general, that means to create a port forward to :8009 from : on your
Router. You then enter the and
in the configuration for the respective Chromecast.
Hit done, and that should be it.
What works / doesn’t work
The Chromecast DTH implements “Music Player” and "Speech Synthesis"
capabilities, at least mostly. There’s currently no send/resume, and
it seems that other devices like Sonos implement additional commands
that apps may rely on. Let’s consider that a to-do.
The “speak” command works, but it’ll interrupt whatever is currently
playing on the Chromecast, and it can’t resume. In general, proper
resume will be difficult to implement, since Chromecast doesn’t really
support it.
You can control play/pause, stop, volume, mute, nextTrack / previous
Track, and some information about the currently playing Track may be
displayed.
The DTH does not poll or refresh automatically. That’s a to-do item
which can be much improved, but it’ll require work. (It’d be easier to
just poll every 5 seconds, but I don’t like that out of principle, and
it’d also make it much more likely to hit the free cloud app limits).
General
The cloud app uses https://github.com/thibauts/node-castv2-client to
actually talk to the Chromecast, so credit for implementing the
protocol goes there for the most part.
There are a bunch of features to be implemented, bugs to fix, etc. I’d
be more than happy to find a couple of people who want to help to make
this project production-ready and easier to use, including people who
test, make improvement suggestions, write documentation, etc.