Chromecast / Google Home - how to detect if something is playing


(Ronny) #1

Hello guys,

does anyone of you have a working example in which he can find out if a certain Chromecast Audio device is currently playing anything?

Here is the background of my question.
I am currently turning on the Google Home device when I enter the room and start to play a stream on it.
My current logic is based on the KNX motion sensor detecting some motion.
As I don’t want to start playing the stream again and again I am looking for an option to find out if the Google Home is currently playing anything.

I do not want to make use of the switch item which turns on the Google Home as I would like to keep it turned on for longer once I turned it on initially. The reason is the long boot time of the device.

Once I have the problem solved knowing that the device is already playing something, I hope I can remotely stop the stream as well after a certain condition is met.

Whould be great if someone has solved this already.
The documentation of the binding does not give me the right clue yet.

Thanks.


(Christoph Wempe) #2

The “channel Type ID” control should be get updated to play when there is something played on your chromecast device.

I think that is what you are looking for.


(Ronny) #3

Yes thanks this is helping.
I found a way to detect if the player is actively doing something. I’ll post my example as soon as all testing is finished.

Basic function working so far. Google Home gets turned on when motion is detected.
(Booting takes really long - up to 42 seconds).
After x seconds I send a stream to the Google Home.
When new motion is detected and GH is already turned on and is playing, no new stream is send, in case it is at the state PAUSE then a stream is send.

Now I try to find a way to detect if the Google Home is fully started and then send the stream, because the boot time is varying very much (from 26 seconds to 42 seconds).


(Brian M. Pedersen) #4

I don’t think this is changed if the player is on pause, if you are playing from spotify you’ll have track changing but not if you are streaming internet radio.


(Ronny) #5

OK - a few more information just in case someone care :slight_smile:

There is a channel “idle” for which you can create a switch, unfortunately this channel does not always switch back to “idle” when the Google Home is not playing anything.

Switch Google_Home_Bad_Idle             "GH Bad Idle"                     <network> (gAssistenten) { channel="chromecast:audio:Bad:idling" }

But you can use it when you startup (switch on power) the Google Home and try to launch a stream.
In my case I do wait for like 20 seconds and then try to lauch a stream, and check the “idle” state, if it is still “idle” I do wait for 1.5 seconds and try again. This seems to be the trick.

As I said before unfortunately this channel is not always switching back to “idle” when you stop your stream either per voice or per Player control item (sending the PAUSE state).

So when you re-enter the room and the Google Home is still on Power you have to check the Player control instead of the “idle” item.

All in all this now works pretty stable.

I will write the solution in a seperate post as tutorial as I believe this may be usefull for others as well.

Here is the link to the tutorial: Chromecast / Google Home - automatic start playing a stream when motion is detected in a room