Google Music in HA -- Now as a media player!

Ha I just saw your edit. No need to feel stupid. I’m clawing my through all this stuff as well. Every step of the way I’ve been learning as I go. Figure out one thing and then it’s something else.

I wish I was smart enough to somehow fix this track skipping issue inside the gmusic_player without relying on something else but at this point, that seems a long way off so relying on gmusicproxy will likely be around for awhile. Would love to see a gmusicproxy add-on for Hass io. Sure would make this much easier. Maybe we could furnish the add-on master @frenck with lavish gifts , beer and monetary bribes. I would give it a shot myself but I don’t use hass io or even docker for that matter. I’d have much to learn and not enough time for me at this point. I could on the other hand create a FreeNAS plugin for gmusicproxy if anyone wanted. I would be surprised to see how many people run HA on FreeNAS and use gmusic_player

There is a gmusicproxy hassio addon https://github.com/miikkajo/hassio_addons

1 Like

Perfect! Thanks @miikkajo I’ll add a link to the first post

What have people done with scripts or automations with this? I’m curious. I set up a small script that I call with a google home but the problem is to get it to play more than one song I have to turn on the google player on and off and on and maybe advance a few songs,and its a little buggy with a script at least that’s my experience. Whats everybody’s work around for this?

@dasbooter
If start gmusic_player just from HA gui (not using a script or anything) does it function correctly. I mean will it advance to the next track like it should?

If yes would you mind to share the script you created for you G Home

EDIT:

I’m not sure exactly what your asking… What are you trying to do?

Sure. Just trying to start up Gmusic with a voice command:

googlemusic_next_song:
  alias: Next song in G Music
  sequence:
    service: media_player.media_next_track
    entity_id: all
googlemusic_previous_song:
  alias: Previous song in G Music
  sequence:
    service: media_player.media_previous_track
    entity_id: all
googlemusic_play_some_music:
  alias: Start playing G Music
  sequence:
    service: media_player.media_play
    entity_id: all

Ive added a - delay: 00:00:03 then started the music again simulating the on off button to get it to play more than one song.

Manually it works but as somebody else mentioned you have to click the on button then turn it off and back on then usually advance to the next song then it continually plays instead of stopping after the first song. My method of doing this in the script seems akward

Man I can imagine that is very awkward. But more to the point, you should not have to do all this to begin with. I have never seen this myself or heard anyone mention this issue. Something is not right. Can we walk through this?

Just using HA – Please check these things in order

  • Check the state of both automation.gmusic_player_auto_advance and automation.gmusic_player_auto_play = on

  • Besure your media player and gmusic_player are off

  • When you press the power button on gmusic_player does the first song begin to play?

  • What is the state of sensor.gmusic_receiver while the first song is playing?

  • Now before the song ends press the next track button on gmusic_player

  • Did the track advance? If not what happened?

  • What is the state of sensor.gmusic_receiver now?

Got me curious, so I tried this myself. Turns out I didn’t need to do anything at all.

With a subscription to Nabu Casa (HA Cloud) and using Google Assistant I simple said

  • “Hey Google, sync my devices”
  • “Hey Google, turn on Google Music Player”

Other “Hey Google” things that worked without any further configuration

  • “Pause”
  • “Unpause”
  • “Play” (Use this to unpause)
  • “Stop” (This will turn-off Google Music Player as well)
  • “Set volume to 3” (Any number 0 - 100)
  • “Change volume to 10”
  • “Mute”
  • “Unmute”
  • “Turn off Google Music Player”

To skip a song I did need a script.

  • “Hey Google, turn on next track”
script:
  gmusic_player_next_track:
    alias: Next Track
    sequence:
    - service: media_player.media_next_track
      data:
        entity_id: media_player.gmusic_player
Error while setting up platform gmusic_player
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 150, in _async_setup_platform
    await asyncio.wait_for(asyncio.shield(task), SLOW_SETUP_MAX_WAIT)
  File "/usr/local/lib/python3.7/asyncio/tasks.py", line 442, in wait_for
    return fut.result()
  File "/usr/local/lib/python3.7/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/config/custom_components/gmusic_player/media_player.py", line 87, in setup_platform
    add_devices([GmusicComponent(hass, config)])
  File "/config/custom_components/gmusic_player/media_player.py", line 137, in __init__
    logged_in = self._api.login(_username, _password, _device_id, authtoken)
  File "</usr/local/lib/python3.7/site-packages/decorator.py:decorator-gen-76>", line 2, in login
  File "/usr/local/lib/python3.7/site-packages/gmusicapi/utils/utils.py", line 133, in wrapper
    return func(*args, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/gmusicapi/clients/mobileclient.py", line 214, in login
    return self._login(session_login, android_id, locale)
  File "/usr/local/lib/python3.7/site-packages/gmusicapi/clients/mobileclient.py", line 143, in _login
    self.android_id = self._validate_device_id(device_id, is_mac=is_mac)
  File "/usr/local/lib/python3.7/site-packages/gmusicapi/clients/mobileclient.py", line 80, in _validate_device_id
    raise InvalidDeviceId('Invalid device_id %s.' % device_id, device_ids)
gmusicapi.exceptions.InvalidDeviceId: Invalid device_id 584.Your valid device IDs are:
* a1b502ea63ef3681b3257c987a03f1dc12c26ecc5d0453487d02d9d12ce9029a

Hi, I tried to recover the ID, but it only gives me the long one, I can’t find the short one (android?)

this the log when i hit play:

2019-10-31 17:42:46 ERROR (SyncWorker_9) [custom_components.gmusic_player.media_player] Failed to get URL for track: (0f50f56f-8ae8-39a5-bdea-3a690823b703)

2019-10-31 17:42:47 ERROR (SyncWorker_9) [custom_components.gmusic_player.media_player] Failed to get URL for track: (2e67b6d3-aac1-3271-a33c-41047bcf18f7)

2019-10-31 17:42:47 ERROR (SyncWorker_9) [custom_components.gmusic_player.media_player] Failed to get URL for track: (09f50bab-2cbf-34ca-9b87-ee86b4327e97)

2019-10-31 17:42:47 ERROR (SyncWorker_9) [custom_components.gmusic_player.media_player] Failed to get URL for track: (36b2a8ac-8bd3-3894-ac9a-8c0ece109748)

It’s not gonna work with that long ID. It has to be the shorter android ID. Do you have an android device resisted to the same account your trying to use here? If so, install Google Music and login from the android device. This should register it’s device ID.

Also from the Google music web page, If you log in and go to setting you can see what devices are registered to your Google Music account. You must first see an android device in this list before gmusicapi will return it’s ID in the gmusic_player logs

Cool your supporting them with nabu casa. Ive set it up with the google projects never publish your project hack. Do you think maybe your just using googles music service that works with google music and not going through your google music player? Ive noticed that it starts playing not in your google music player and instead on the google home I’m standing next too. Or was that your intention. In any case ,weirdly, activating your player with voice command and script only seems to get one song to play no matter what I’m doing. I have to hit the button manually in the front end than everything works? Ill try some of the things you suggested but Im messing around in docker and I only get so much technology time…my girl says I’m addicted lol

  • Check the state of both automation.gmusic_player_auto_advance and automation.gmusic_player_auto_play = on
    yes both are on

  • Besure your media player and gmusic_player are off
    ok did that

  • When you press the power button on gmusic_player does the first song begin to play?
    yes it does

  • What is the state of sensor.gmusic_receiver while the first song is playing?
    sensor.gmusic_receiver playing

  • Now before the song ends press the next track button on gmusic_player

  • Did the track advance? If not what happened?
    yes it does advance

  • What is the state of sensor.gmusic_receiver now?
    says playing
    couldnt help myself want this to work

:thinking: So based on the questions you answered, everything should be working (At least as I intended.)

Do you think maybe your just using googles music service that works with google music and not going through your google music player?

Possibly but not exactly. I think it is sort of google though. I am suspecting that voice may only control gmusic_player with a single command. That is “Hey Google, turn on Google Music Player” ( If you have not figured, “Google Music Player” is the friendly name for gmusic_player") but from now forward, Google sees you chromecast device playing music so all voice commands are controlling cast device directly, no longer gmusic_player.

Ive noticed that it starts playing not in your google music player and instead on the google home I’m standing next too. Or was that your intention.

But I do feel that first “Hey, turn on…” command is gmusic_player because it does turn on and play the selected music on the selected speakers according to what I have set using the corresponding gmusic_player_input_select(s). To this regard you should see both media_players turn on (selected speakers and gmusic_player) gmusic_player only handles using the gmusicapi to lookup music from your google music library. when it finally gets the playback url it sends the playback command to the selected speakers (based on speakers_input_select) So in other words, if “google home I’m standing next too” is the selected option in “speakers” then that is where you should here music begin to play.

Honestly, I have not done anything by intention with regard voice commands. If any of it works, it is by no intention or design of my own. At the same time I also see no reason this should not work. I mean I still do not understand much of the dev docs but I never seen anything specific mentioned to enable voice control for a custom component.

Ill try some of the things you suggested

If you go through those questions again, except replace this third question.

  • When you press the power button on gmusic_player does the first song begin to play?
  • When you say “hey google, turn on google music player” does the first song begin to play?

Do you get the same answers for all the questions when started with voice control?

Thanks, now everything works perfectly

I seem to be having trouble getting this working…

I’ve followed the guides… installed via HACS, added packages: !include_dir_named packages, created a packages folder in config, uploaded the two yaml files. Added gmusic_username, gmusic_password, gmusic_device_id to secrets. added my media players.

but I seem to get the following error;

Log Details (ERROR)
Sun Dec 15 2019 20:05:41 GMT+0000 (Greenwich Mean Time)
Error doing job: Future exception was never retrieved
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/config/custom_components/gmusic_player/media_player.py", line 355, in _update_sources
    self._update_playlists()
  File "/config/custom_components/gmusic_player/media_player.py", line 377, in _update_playlists
    self.hass.services.call(input_select.DOMAIN, input_select.SERVICE_SET_OPTIONS, data)
  File "/usr/src/homeassistant/homeassistant/core.py", line 1173, in call
    self._hass.loop,
  File "/usr/local/lib/python3.7/concurrent/futures/_base.py", line 428, in result
    return self.__get_result()
  File "/usr/local/lib/python3.7/concurrent/futures/_base.py", line 384, in __get_result
    raise self._exception
  File "/usr/src/homeassistant/homeassistant/core.py", line 1213, in async_call
    processed_data = handler.schema(service_data)
  File "/usr/local/lib/python3.7/site-packages/voluptuous/validators.py", line 208, in __call__
    return self._exec((Schema(val) for val in self.validators), v)
  File "/usr/local/lib/python3.7/site-packages/voluptuous/validators.py", line 287, in _exec
    raise e if self.msg is None else AllInvalid(self.msg, path=path)
  File "/usr/local/lib/python3.7/site-packages/voluptuous/validators.py", line 283, in _exec
    v = func(v)
  File "/usr/local/lib/python3.7/site-packages/voluptuous/schema_builder.py", line 272, in __call__
    return self._compiled([], data)
  File "/usr/local/lib/python3.7/site-packages/voluptuous/schema_builder.py", line 817, in validate_callable
    return schema(data)
  File "/usr/local/lib/python3.7/site-packages/voluptuous/schema_builder.py", line 272, in __call__
    return self._compiled([], data)
  File "/usr/local/lib/python3.7/site-packages/voluptuous/schema_builder.py", line 594, in validate_dict
    return base_validate(path, iteritems(data), out)
  File "/usr/local/lib/python3.7/site-packages/voluptuous/schema_builder.py", line 432, in validate_mapping
    raise er.MultipleInvalid(errors)
voluptuous.error.MultipleInvalid: length of value must be at least 1 for dictionary value @ data['options']

:thinking: Do you have at least one playlist on your Google Music Library?

If not try creating a playlist. doesn’t have to much, even a single song should work

I think there needs to be at least one playlist you create. The auto-generated playlists do not show up.

Hi! First post on the forum,

So I tried installing this, and I seem to have completed everything I need to.

  • I installed off of HACS
  • Created the packages folder and added the YAML files
  • Added my login details, found the device ID and added that as well.
  • Added my media player, a Kodi box, which I tested, and does stream mp3 files.

So everything seems to be working fine. I can see my playlists and radios in the lists, and I see no errors in the log.

But for some reason, the Google Music Player just refuses to turn on.

If I click the power button, nothing happens, and nothing is reported on the log.

Any idea what this might be? I did create a Github issue as well, with some images of what I’m experiencing.

PS: Outside of the US, but I have a full access account.

@Padrone56 Welcome :slightly_smiling_face:

:thinking: I had a look at your pictures on github. I have a guess… can you try to start playback using media_player.play_media from the services page.

Based on you pictures try one or both

playlist

entity_id: media_player.gmusic_player
media_content_id: .Koreaboo
media_content_type: playlist

station

entity_id: media_player.gmusic_player
media_content_id: I'm Feeling Lucky
media_content_type: station

No luck :confused:

image

I call this, but nothing happens and the logs are clean. The player just stays turned off.

This is my first custom component install, so I feel like I might’ve botched the installation or something. Does the Music Player require anything else to be installed?

I have a Kodi media player and it works fine. Have you setup your player correctly in gmusic_config.yaml

input_select:
  gmusic_player_speakers:
    name: Speakers
    icon: mdi:speaker
    ## Add your media_players below
    options: # Example media_players
    - mibox3
    - lounge_speaker
    - kodi