Hey,
I wanted to find a way to cast images or audio using Node-RED and Chromecast when something important happens in my Smart Home.
I didn’t put my Google Chromecast to a good use lately, so I decided to drastically change that.
Fortunately I manage to find how to do that and now I’m about to show it to you in details.
The same approach can be applied to Google Home devices with or without display. Apparently If your device is without display like the Google Home mini, then you can only cast audio files.
But before you say:
“Kiril, I already can stream from my phone to my TV whenever I want, why are you wasting my time?“
Imagine the following scenario: Someone ring at your door and your TV is automatically displaying a security camera image – isn’t it priceless?
Table of Contents
Node-RED and Chromecast
The possibilities for a trigger of the cast are basically endless. They are depending of your needs and available sensors in your Smart Home.
I will focus more on the Chromecast and Node-RED integration, but you can easily adapt this to your needs afterwards.
Really quick before we get into the article – I just want to say a huge thank you to our sponsor today, which it’s called: Smash That Subscribe Button if you haven’t done that already.
For real there is no sponsor, but if you just hit the Subscribe button that would be good enough for me – thank you.
So anyway if you have any of these Google devices,
Chromecast | Android TV devices | Soundbars and speakers |
---|---|---|
First generation (video) | Nexus Player | Google Home |
Second generation (video) | Nvidia Shield | Vizio |
Third generation (video) | Xiaomi MiBox | Sony |
Chromecast Audio | Vizio televisions | LG |
Chromecast Ultra | Sharp televisions | Philips |
Sony televisions | B&O Play | |
Toshiba televisions | Grundig | |
Philips televisions | Polk Audio | |
Bang & Olufsen | ||
Raumfeld | ||
Brookstone | ||
NAD | ||
Onkyo | ||
Integra | ||
Pioneer | ||
Riva Wand | ||
Grace Digital | ||
Jensen | ||
JBL |
the only additional thing that you will need is Node-RED.
Node-RED install
You need Docker client to install Node-RED, if you already have working Node-RED you can go directly to the Cast from Node-RED section.
Go to docker website and download the client for your Operating System.
For MacOS, the running Docker client is looking like this. Windows client is pretty similar. You should see the green dot.
After you install and run the Docker client you have to open a Terminal/Console and you just need to type the following command:
docker run -it -p 1880:1880 --name nodered nodered/node-red:latest
This roughly means: start a Docker container with the latest official Node-RED image and export the port 1880 to localhost.
Cast from Node-RED
Node-RED is up & running. Let’s import some flows now.
To do that go to “Manage Palette” in the Node-RED menu and search for “node-red-contrib-cast” or just “cast”
Click on the Install button in the lower right corner and wait for the process to finish.
Then you can grab one of the examples (like the one below) from the GitHub page of the project and import it in your Node-RED
[{"id":"8d9663a.05e27a","type":"cast-to-client","z":"d900d7d9.c4c498","name":"","url":null,"contentType":"","message":null,"language":"en","ip":"","port":"","volume":null,"x":590,"y":200,"wires":[["b885e401.447548"]]},{"id":"6faf449b.c11efc","type":"inject","z":"d900d7d9.c4c498","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":160,"y":200,"wires":[["23bdf480.46b85c"]]},{"id":"23bdf480.46b85c","type":"change","z":"d900d7d9.c4c498","name":"","rules":[{"t":"set","p":"ip","pt":"msg","to":"192.168.1.125","tot":"str"},{"t":"set","p":"message","pt":"msg","to":"Subscribe for Kiril's newsletter","tot":"str"},{"t":"set","p":"language","pt":"msg","to":"En-gb","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":380,"y":200,"wires":[["8d9663a.05e27a"]]},{"id":"b885e401.447548","type":"debug","z":"d900d7d9.c4c498","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":790,"y":200,"wires":[]},{"id":"9a5a2ce.5ae7ed","type":"comment","z":"d900d7d9.c4c498","name":"say a text","info":"","x":120,"y":160,"wires":[]}]
The only thing that you have to change here is the IP, you have to type the IP of your Chromecast / Google Cast device :
The last thing before you can test it, you have to hit the “Deploy” button in the upper right and then click on the inject button.
If everything is configured properly – you should hear an audio record from your Google Cast device.
You can test the other examples as well and of course you can adapt them to suit your needs.
Check the Device Status
The other thing that could be very useful for your Smart Home Automation is checking the current status of the Chromecast / Google Cast device.
You can understand the volume level, is device muted, is device currently playing any media and if yes – what exactly and so on and so on.
To accomplish this, just import the following example and change the IP with yours afterwards:
[{"id":"82e3c67a.27b218","type":"cast-to-client","z":"c4dd07cf.84ae98","name":"","url":"","contentType":"","message":"","language":"en","ip":"192.168.1.125","port":"","volume":"","x":490,"y":220,"wires":[["6bc79592.92574c"]]},{"id":"a5bddaf0.4e9578","type":"inject","z":"c4dd07cf.84ae98","name":"","topic":"","payload":"","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":110,"y":220,"wires":[["82e3c67a.27b218"]]},{"id":"6bc79592.92574c","type":"debug","z":"c4dd07cf.84ae98","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":710,"y":220,"wires":[]}]
Question?
I would love to hear what are your ideas for a good use of this Chromecast and Node-RED collaboration – let me know your answers in the comments section below.
Support my work
Any sort of engagement on this channel does really help out a lot with the YouTube algorithm, so make sure you hit the subscribe, Like and Bell buttons If you enjoy this video.
Also feel free to add me on Twitter by searching for @KPeyanski.
I really hope that you find this information useful and you now can cast video and audio from Node-RED to your Chromecast or Google Home devices .
Thank you for watching/reading, stay safe and see you next time.
What is the advantage of using the Change node and not just adding the msg’s to the Cast node?
In this simple flow there is no advantage and it is basically the same. But if you have something more complex for example: Several triggers/cameras in one Flow with different IPs, different Content Type etc, etc. In that case you may want to construct all of your variables in advance with Change nodes or Function nodes and then to pass them to only one empty Cast node, which will handle all of the variations without any issues. But at the end this is just a personal preference and the important part is to make it work 🙂 I hope I managed to answer. Thanks for you comment and have a nice day.
Is there any way to cast a web page instead of images/videos? What I’m trying to do is set up magic mirror to be able to automatically cast to one of my TVs through chromecast. so that when I wake up I get a nice overview of the day. any ideas?
I want to do the same. Create a weather view or a visualization when someone calls me and I am at home.
Unfortunately I have not yet found a way to display a website.
Is it possible to resume audio / video playback via the castable devices when playing a tts?
Example: Listen to TuneIn on Google Home and a TTS message appears. It will stop the stream, play the tts message. Resume TuneIn stream.
I following your work, sincerely is awesome. I applied the steps of your tutorial in order to stream my security camera video to a Chromecast, and at the beginning all was working very well. Now, for some reason I’m received an “Not able to load media:Load failed Not able to load the media.” error and simply doesn’t work 🙁 .
To be honest, I don’t have any idea about the problem is. Can you suggest me something about it.
Thanks.