For auto discovered things it is not possible to change the thing id. What I did not test is adding the thing manually via Paper UI. I am not sure if the same discovery feature is applied for them. But then you have the change to rename the thing id.
I know that it is easier for humans to have a meaningful thing id but the framework does not care. Rule and Item files can be change by find & replaced in a second.
Unfortunately the autodiscovered audiogroup isn’t working reliably for me.
I’ve just tried adding the autodiscovered audiogroup thing. At first, it was online, and all was good. Then I tried removing it, then re-discovered it and re-added it as a thing. I did this a few times. Then eventually I stumbled on a problem. The autodiscovered audiogroup, once added as a thing, is OFFLINE. Its ip address is pointing to the offline member indeed.
I have 4 google home devices that are all members of the “All Speakers” audiogroup: 192.168.1.200, .203, .208 and .165. The one that seems to be elected most of the time is the .208.
However, the discovered audiogroup when added as a thing, kept having the ip address of .200 and hence it is OFFLINE. I tried deleting this autodiscovered thing and re-adding, and it now kept reverting to that .200 and therefore stays OFFLINE. I have not changed its ip address manually.
I have been observing this problem with OH 2.x for quite some time. I assign a fixed IP address for my Chromecasts and the port for the audio group changes from time to time. It is not understandable for me.
Apps like BubbleUPnP, Audials or PowerAmp have no problem to work with the changed port of the Chromecast audio group. This is a very very annoying thing …
Easy guys… make a simple rule to track which channel is online and this will be the group ip address… i did this long time and its working perfectly… im abt to sleep now… ill post the rule tomorrow
hi guys, below example for two google mini, u can add as much as u want… please set fixed ip for the google mini’s from the router… google it… fixed ip per mac address
things
Thing chromecast:chromecast:Ghome_LR "Google home Livingroom" [ ipAddress="192.168.0.20", port=8009]
Thing chromecast:chromecast:Ghome_BR "Google home Bedroom" [ ipAddress="192.168.0.21", port=8009]
Thing chromecast:audiogroup:Ghome_Group1 "Audio group 1" [ ipAddress="192.168.0.20", port=42648]
Thing chromecast:audiogroup:Ghome_Group2 "Audio group 2" [ ipAddress="192.168.0.21", port=42648]
Items
Player ChromecastAudioControl_LR "Google mini livingroom Control" {channel="chromecast:chromecast:Ghome_LR:control"}
Dimmer ChromecastVolume_LR "Livingroom Volume [%d %%]" {channel="chromecast:chromecast:Ghome_LR:volume"}
Player ChromecastAudioControl_BR "Google mini Bedroom Control" {channel="chromecast:chromecast:Ghome_BR:control"}
Dimmer ChromecastVolume_BR "Bedroom Volume [%d %%]" {channel="chromecast:chromecast:Ghome_BR:volume"}
Player ChromecastAudioControl_Group1 "Google mini group Control" {channel="chromecast:audiogroup:Ghome_Group1:control"}
Dimmer ChromecastVolume_Group1 "Google mini group Volume [%d %%]" {channel="chromecast:audiogroup:Ghome_Group1:volume"}
Player ChromecastAudioControl_Group2 "Google mini group Control" {channel="chromecast:audiogroup:Ghome_Group2:control"}
Dimmer ChromecastVolume_Group2 "Google mini group Volume [%d %%]" {channel="chromecast:audiogroup:Ghome_Group2:volume"}
Number music_track "Track [%d]" <player>
Number music_control "Music control [%d]" <player>
String audio_sink "Speaker [%s]" <player>
String audio_sink_v "Speaker [%s]" <player>
Dimmer ChromecastVolume_Group_v "Group Volume [%d %%]"
rule
rule "check things online"
when
Thing "chromecast:audiogroup:Ghome_Group1" changed or
Thing "chromecast:audiogroup:Ghome_Group2" changed
then
var Ghome_Group1_status = getThingStatusInfo("chromecast:audiogroup:Ghome_Group1").getStatus()
var Ghome_Group2_status = getThingStatusInfo("chromecast:audiogroup:Ghome_Group2").getStatus()
if (audio_sink_v.state == "Ghome_G1") {
if(Ghome_Group1_status.toString() == 'ONLINE') audio_sink.postUpdate("chromecast:audiogroup:Ghome_Group1")
else if(Ghome_Group2_status.toString() == 'ONLINE') audio_sink.postUpdate("chromecast:audiogroup:Ghome_Group2")
}
end
rule "Select Active audio group"
when
Item audio_sink_v received command
then
var Ghome_Group1_status = getThingStatusInfo("chromecast:audiogroup:Ghome_Group1").getStatus()
var Ghome_Group2_status = getThingStatusInfo("chromecast:audiogroup:Ghome_Group2").getStatus()
switch(receivedCommand) {
case "Ghome_LR" : {
audio_sink.postUpdate("chromecast:chromecast:Ghome_LR")
audiocontrol=ChromecastAudioControl_LR
}
case "Ghome_BR" : {
audio_sink.postUpdate("chromecast:chromecast:Ghome_BR")
audiocontrol=ChromecastAudioControl_BR
}
case "Ghome_G1" : if(Ghome_Group1_status.toString() == 'ONLINE') {
audio_sink.postUpdate("chromecast:audiogroup:Ghome_Group1")
audiocontrol=ChromecastAudioControl_Group1
}
else if(Ghome_Group2_status.toString() == 'ONLINE') {
audio_sink.postUpdate("chromecast:audiogroup:Ghome_Group2")
audiocontrol=ChromecastAudioControl_Group2
}
}
end
rule "google home group volume"
when
Item ChromecastVolume_Group_v received command
then
if (audio_sink.state == "chromecast:audiogroup:Ghome_Group1") ChromecastVolume_Group1.sendCommand(ChromecastVolume_Group_v.state.toString)
else if (audio_sink.state == "chromecast:audiogroup:Ghome_Group2") ChromecastVolume_Group2.sendCommand(ChromecastVolume_Group_v.state.toString)
end
rule "music control"
when
Item music_control received command
then
switch(receivedCommand) {
case 0 : playStream(audio_sink.state.toString, null)
case 1 : sendCommand(audiocontrol, PAUSE)
case 2 : sendCommand(audiocontrol, PLAY)
}
music_control.postUpdate(3)
end
rule "Select music track"
when
Item music_track received command
then
switch(receivedCommand) {
case 3 : playStream(audio_sink.state.toString, "http://192.168.0.10:8080/static/media/slow_music.mp3")
case 4 : playStream(audio_sink.state.toString, "http://192.168.0.10:8080/static/media/movie.mp3")
}
end
Thank you for that - I can’t believe I didn’t think of doing that so much earlier!
I’ve modified mine for the 4 (at the moment) Google Homes around the house.
This is a smart solution, quickly tested it and it seems to work as expected (i’m on OH3). I am now going to understand how to solve my situation: I want to have a chromecast audio group as a default audio sink in openHAB, so to use say command to give alerts about specific events. Changing in the rule the default audio sink should be possible using something like:
@Mohammad_Chaaban, thanks for this solution. I have a rule that plays the radio on weekday mornings, and wanted to cast it to my audio group (instead of just the Chromecast in my bedroom). I don’t need to control the audio group from a sitemap, so I just added the status checks into my rules to ensure I cast to the elected leader.
is there a way to “lock” my audiogroup to have only 1 leader?If i manually create my audiogroup thing from a .thing file and give it the ip of the google home i want to be leader will it work?
No, because that doesn’t have any effect on the behaviour of the Chromecast devices. That just tells openHAB where to look.
I initially set up a rule to alert me when the elected leader changes and discovered that it will briefly change to one of the other two devices and then back to the original. I don’t know if this is the case for others.
There was one time when the port changed, and then I had to rediscover the audio group to get it going again, but that hasn’t happened again.
so i am still losing my chromecast group from time to time and the “quick” way to restore it is to delete the thing and readd it from inbox…Is there a way to automate this?If the group goes offline delete the thing and readd it with a rule of some kind…
I found that after setting static IP addresses for my Chromecasts, openHAB doesn’t have an issue finding them. I suspect that when the leader changes, it’s due to one Chromecast rebooting for a software update. But after that happens, it always returns to being the leader.
Hi,
I have a group with 4 speakers. All fixed IPs. This rule below monitors the group status and if it goes OFFLINE it iterates over speaker IPs until the group changes to ONLINE again:
const { triggers, things } = require('openhab');
console.loggerName = 'org.openhab.custom.rules.chromecastrules';
const ipAddresses = ['10.200.0.13', '10.200.0.9', '10.200.0.11', '10.200.0.12'];
const groupID = 'chromecast:audiogroup:Notification';
var ipIndex = 0;
rules.JSRule({
name: 'Notification Group OFFLINE',
description: 'Notification group status monitoring.',
triggers: [
triggers.ThingStatusUpdateTrigger('chromecast:audiogroup:Notification', 'OFFLINE')
],
execute: (event) => {
if (ipIndex < ipAddresses.length && things.getThing('chromecast:audiogroup:Notification').statusInfo.includes('Connection refused')) {
console.log('Nontification group offline. Changing its IP to ' + ipAddresses[ipIndex]);
var thing = things.getThing(groupID);
thing.setEnabled(false);
thing.rawThing.getConfiguration().put('ipAddress', ipAddresses[ipIndex++]);
thing.setEnabled(true);
if (ipIndex === ipAddresses.length) {
//give some time to OH before starting over
setTimeout(() => {
ipIndex = 0;
}, 10000);
}
}
},
tags: ['Notification'],
id: 'NotificationGroupStatusMonitor'
});
Hi Gabor, I like you rule, but am not quite sure how to fully integrate/incorporate the above code into openhab rules (openhab 4.0). Could you perhaps elaborate a bit on how to do this?