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.