Openhab and Chromecast: anybody find it useful?

Hello,

I was wondering if anybody has connected Chromecast to Openhab and find it really useful…

I am debating if this would be a good gadget to get :)… I like the idea, but I would preferif via Openhab I could not only control Chromcast once is active, but I was wondering if I could "turn on TV, initiate Chromcast and streem Spotify (for example)… is it feasible? if not what devise should I be focused on?

Cheers

Ivan

I haven’t found any use for the Chromecast yet. But I do use the Google Home speaker and Google Home mini. You can use them as a cheap wifi speaker. They make a perfect integration device for text-to-speech or programmatically playing music.

I use chrome cast audio everyday. I have my wake rule turn on 2 1950’s valve radios, and use chrome cast audios to play internet radio through them, along with lights and stuff if it is dark.

I also use 3 Chromecast audio’s and one Chromecast. Depending on the app which I use to send data to the Chromecast, specific devices are turned on etc.

I’d be keen to see the rule for play xyz on the chromecast (the turn on stereo and lights, I’m happy with)

I dont use my chromecast devices in openhab much. But I do use my Google Home devices abit.
I have used openhab to send stream of sounds to my Google Home devices. (I used a GH device at Halloween playing scary sounds at the frontdoor, controled by openhab).

My plan is to use these devices alot more to send more specific notifications (by speech) from openhab til GH devices at special events or rules.
Fx let openhab send a text to speech, if someone is walking around the outside of house in the middle of the night. If the garagedoor is open, when it´s suppose to be closed, and I forgot to check and went to bed, turning off the light will check and send the message, if its not closed. If the frontdoor isnt locked when I go to bed… etc. Simple stuff like that is in my opinion usefull. I will be using Google Home devices for stuff like that, not chromecasts devices, as I wont have the speech respons, untill it´s connected to a speaker. And since I probably will ask Google to close the garagedoor in case I forgot, a chromecast device wont do much good.

The basic control for chromecast is

Items

Number Radio_Station "Radio Station [%d]" String Play_radio "Radio URI [%s]" {channel="chromecast:audiogroup:0e548657-769b-43e3-87db-7f1c75a2a915:playuri"} String Play_on_office_speaker "office speaker URI [%s]" {channel="chromecast:chromecast:42138b4fe1c262a4988221de8d4d610d:playuri"} Switch Stop_Home_group "Stop Home group" (Chillingworth) {channel="chromecast:audiogroup:0e548657-769b-43e3-87db-7f1c75a2a915:stop", expire="5s, command=OFF"}

Rule

rule "Select Radio Station" when Item Radio_Station received command then switch(receivedCommand) { case 0 : Stop_Home_group.sendCommand(ON) case 1 : Play_radio.sendCommand("http://bbcmedia.ic.llnwd.net/stream/bbcmedia_radio2_mf_p") case 2 : Play_radio.sendCommand("http://bbcmedia.ic.llnwd.net/stream/bbcmedia_lrshrops_mf_p") case 3 : Play_radio.sendCommand("http://bbcmedia.ic.llnwd.net/stream/bbcmedia_radio5live_mf_p") case 4 : Play_radio.sendCommand("http://bbcwssc.ic.llnwd.net/stream/bbcwssc_mp1_ws-einws") case 5 : Play_radio.sendCommand("http://bbcmedia.ic.llnwd.net/stream/bbcmedia_radio4fm_mf_p") case 6 : Play_radio.sendCommand("http://bbcmedia.ic.llnwd.net/stream/bbcmedia_lrmersey_mf_p") case 7 : Play_on_office_speaker.sendCommand("http://bbcmedia.ic.llnwd.net/stream/bbcmedia_lrshrops_mf_p") case 8 : Play_radio.sendCommand("http://bbcmedia.ic.llnwd.net/stream/bbcmedia_walesmw_mf_p")
}

end

Sitemap

Text label="Radio" icon="receiver" { Selection item=Radio_Station mappings=[0="off", 1="Radio 2", 2="Radio shropshire", 3="Radio 5 live", 4="BBC world servcie news", 5="Radio 4", 6="Radio Merseyside", 7="Radio Shropshire on office speaker", 8="Radio Wales"]

Then it is a simple mater of creating a dummy switch and linking everything in a new rule for that switch

I am no coder so this may not be the best solution but it works for me.

Please use code fences!

1 Like

But I did use “code” etc did I do it wrong? If so the instructions are very poor. I can’t write it here as it dissapears.

rule "Do action when Chromecast Living AppId is triggered"
when
    Item ChromecastLiving_AppId changed
then
	logInfo("RULE.CHROMECAST", "Chromecast id changed!")
	
	var appId = ChromecastLiving_AppId.state

	// YouTube + VRT NU Caster + Stievie + Google Photos + Chrome Mirroring + VTM GO + VRT Caster + Screen Mirroring
	if ((appId == "233637DE") || (appId == "B862F431") || (appId == "A0C06B7B") || (appId == "96084372") || (appId == "0F5096E8") || (appId == "3FA7C488") || (appId == "24017A2E") || (appId == "674A0243")) {
		logInfo("RULE.CHROMECAST", appId + " (" + (ChromecastLiving_AppName.state) + ")")
		Harmony_Activity.sendCommand("Chromecast")
	}
	
end

rule "Do action when Chromecast Audio Living AppId is triggered"
when
    Item ChromecastAudioLiving_AppId changed
then
	logInfo("RULE.CHROMECASTAUDIO", "Chromecast id changed!")
	
	var appId = ChromecastAudioLiving_AppId.state

	// Hi-Fi Cast + BubbleUPnP + Spotify + Google Play Music
	if ((appId == "3927FA74") || (appId == "472D2B73") || (appId == "CC32E753") || (appId == "2872939A")) {
		logInfo("RULE.CHROMECASTAUDIO", appId + " (" + (ChromecastAudioLiving_AppName.state) + ")")
		Harmony_Activity.sendCommand("Chromecast Audio")
	}
	
end

rule "Chromecast Audio Living Switch Radio"
when   
    Item ChromecastAudioLivingRadioStream changed
then
	logInfo("Chromecast living", "radio active")
	var streamNameLiving = ChromecastAudioLivingRadioStream.state

	if ( streamNameLiving == "Stream_Stop" ) {
		ChromecastAudioLiving_PlayUri.sendCommand("")
		ChromecastAudioLiving_Control.sendCommand(STOP)
		ChromecastAudioLivingRadioLogo.sendCommand("http://openhab.home:8080/icon/No_image_available.jpg")
	}
	else {
		switch(streamNameLiving) {
			case "Stream_MNM": {
				ChromecastAudioLiving_PlayUri.sendCommand("http://icecast.vrtcdn.be/mnm-high.mp3")
				ChromecastAudioLivingRadioLogo.sendCommand("http://openhab.home:8080/icon/mnm.png")
				ChromecastAudioLivingRadioStation.sendCommand("MNM")
			}
			case "Stream_Topradio": {
				ChromecastAudioLiving_PlayUri.sendCommand("http://lb.topradio.be/topradio.mp3")
				ChromecastAudioLivingRadioLogo.sendCommand("http://openhab.home:8080/icon/topradio.jpg")
				ChromecastAudioLivingRadioStation.sendCommand("TOPradio")
			}
			case "Stream_StuBru": {
				ChromecastAudioLiving_PlayUri.sendCommand("http://icecast.vrtcdn.be/stubru-high.mp3")
				ChromecastAudioLivingRadioStation.sendCommand("Studio Brussel")
			}
			case "Stream_MNMHits": {
				ChromecastAudioLiving_PlayUri.sendCommand("http://icecast.vrtcdn.be/mnm_hits-high.mp3")
				ChromecastAudioLivingRadioStation.sendCommand("MNM Hits")
			}

		}
		ChromecastAudioLiving_Control.sendCommand(PLAY)
	}
end

#wars
Hi, I want to use your rule example but I don’t know what to use in items end sitemap. Can you give me an example for items and sitemap.

this rule is only using the AppId and PlayUri channel of my Chromecasts and a channel to switch activities on my Harmony

String	ChromecastLiving_AppId				"App ID"						{channel="chromecast:chromecast:chromecastLiving:appId"}
String  ChromecastLiving_PlayUri			"Play URI"						{channel="chromecast:chromecast:chromecastLiving:playuri"}

String  Harmony_Activity         "Current Activity"          { channel="harmonyhub:hub:myharmony:currentActivity" }

The line in my Sitemap for switching Radio:

Switch item=ChromecastAudioLivingRadioStream label="Radio" mappings=[ Stream_MNM="MNM", Stream_Topradio="TOPradio", Stream_StuBru="Studio Brussel", Stream_MNMHits="MNM Hits" ]

I use the idle channel to determine if a Chromecast is streaming, and the appID channel to set volume for specific apps.

Switch Chromecast_Stop "Chromecast[]" { channel="chromecast:XXXX:stop", autoupdate="false" }
Dimmer Chromecast_Volume "Volume [%d%%]" { channel="chromecast:chromecast:XXXX:volume" }
Switch Chromecast_Idle "Chromecast []" { channel="chromecast:XXXX:idling", autoupdate="false" }
String Chromecast_App "Chromecast App" { channel="chromecast:chromecast:XXXX:appName" }


rule "Turn on Harmony Hub when casting"
when
    Item Chromecast_Idle changed to OFF
then
    HarmonyLivingRoomActivity.sendCommand("Chromecast")
    //lower the volume if app is TuneIn Free
    if (Chromecast_App.state == "TuneIn Free") { Chromecast_Volume.sendCommand(35) }
    else { Chromecast_Volume.sendCommand(60) }
end

rule "Turn off Harmony Hub five minutes after Chromecast goes to idle"
when
    Item Chromecast_Idle changed to ON
then
    createTimer(now.plusMinutes(5))
    [
        if (Chromecast_Barney_Idle.state == ON && HarmonyLivingRoomActivity.state == "Geneva XL") { HarmonyLivingRoomActivity.sendCommand("PowerOff") }
    ]
end

With the stop channel, you can stop casting with Chromecast_Stop.sendCommand(ON). You can build this into a rule that detects if the Harmony Hub activity changes, so that you won’t keep casting to a device that’s not turned on. I use it in my “Away Mode” rule, which turns everything off when I leave the house.

The stop channel immediately returns to OFF, so there’s no need to send a follow-up OFF command.

1 Like

Hello everyone,

Sorry to bump an old thread, but I’m hoping one of you can point me in the right direction.

In the UK, the BBC aren’t playing nicely with TuneIN and are insisting that their own BBC Sounds app is used.

How should I go about starting this app from openHAB and setting the desired radio or podcast?

Do they have a web-based app to play the stream you want without logging in? If so, you should be able to find the stream by starting the web-based player in Chrome and then using the inspection tools to look for it.

Alternatively, if you can say “hey Google, play ____ on BBC Sounds”, then you can use an OH item to trigger a Google Assistant routine and run that command. There will be a slight delay since GA doesn’t get item updates immediately.

@rpwong
Two excellent suggestions there !

Thanks Russ, I’ll let you know how I get on.

1 Like

@rpwong

Well here’s a thing.

The ChromeCast Audio I have I’m my bathroom, doesn’t have a “send command” type channel.

But…

If I were to break the bank and get a Google Home device, it’s possible I could send an utterance like " Hey Google, stream BBC Radio 6 Music, to the bathroom " (just like I can from my Android phone)

Or…
Do you mean using Google Action method? (which I thought was for Google to openHAB???)
Is there a way to sent a command to Google FROM openHAB?

Which is probably just as easy / difficult / costly as setting up some kind of in-house streaming / transcoder.

(I have a couple of DVB-T2 dongles, that I had been thinking of using as DVB-T2 radio to internal IP stream things, but that’s an effort in itself)

It’ll be the playURI channel.

image

I have the ability to create a routine in the Google Home app on my phone and start it “when a device does something”. Do you have that? It’s possible that it’s regional and hasn’t deployed to the UK yet.

If you can do this, then you can expose a switch item with Google Assistant and send an ON command to trigger the routine and carry out any command you would normally give by voice.

Oh…

Interesting approach…

I’ll have to look closely at that.

I think I’ve seen something like it in the UK Google Home app.

Maybe a task for this weekend or next week?

Thanks buddy.

Note that I haven’t actually tried this, because the playURI works for my purposes. I was thinking about experimenting with it just to see how much lag there is between the OH item changing and GA triggering the routine.