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

@mason @troy

I am running dockerized hassio on an Ubuntu box here. I will throw gmusicproxy on a system tonight to test. Even though it is one more piece, it is a pretty simple workaround to get music working again.

@smccoy @mason

I think I can just add an option so you can switch between direct gmusicapi url or gmusicproxy url.

Sorry I can’t just fix this properly yet, this is just my first attempt at learning both python and how to make custom components. I really wish I was just a bit smarter, it’s slow going for me trying to learn python from the internet :rofl: ( and I took the summer off ) - I have a lot of ideas for this and at the same time sooo many questions even regarding just the basics of python programming. I haven’t had that “Oh, I get it!” moment where it it all starts to just make sense.

@mason @troy

Well, Gmusicproxy fixed the problem! For anybody running Docker, there is a Gmusicproxy Docker package available here: https://hub.docker.com/r/digitallyseamless/gmusicproxy that works great. Just create a config file, change the compose to point to your config and go. I did have to use the IP of my host instead of localhost to get it connected, but it is working great.

An option would be handy, but it is not a big deal to manually edit the file, either. I just commented out the original line so I can switch back without too much hassle.

No need to apologize! I’m still trying to ‘get’ Python, too. I’m just excited to have music working again and I can’t wait to see what else you will dream up!

@troy @smccoy thanks for the input, I’ll have a look when I find the time. still have a lot other stuff t setup and restructure. and as said, every little bit is welcome, no need to apologize.

edit: okay i was to curious and just added another container, looking good so far :slight_smile:
Now, if I only could find a way to scrobble the music to last.fm this would be the cherry on top. Or a like dislike button for your player if you need some more challenges learning python :wink:

thanks guys

Update – 09/23/2019

To help with future updates I have made some changes.

  • Moved user config to a separate package file
  • Now you can install and update using HACS

hacs_badge
In HACS Settings → Custom Repositories, add the following:

https://github.com/tprelog/homeassistant-gmusic_player

Use Category: Integration

Press Install or reinstall
You will still need to add both new package files

Manual upgrade

Download and replace custom_components/gmusic_player/media_player.py
You will still need to add both new package files



Change for oauth related login options

  • This still requires an existing oauth_credentials file

I have eliminated the login_type and oauth_cred setting.
These are now set using username and password options.

Key Type Required Description
username string YES Username must be set to oauth
password string YES Path to existing oauth_credentials
device_id string YES Set your valid device_id here.
token_path none NO Not used by oauth!

Example oauth

    username: "oauth"
    password: "/home/hass/homeassistant/oauth.file"

@smccoy @mason and I have noticed songs cutting off before they should end. You can use gmusicproxy as a workaround until this is fixed more correctly. If set gmusic_player can stream from your local gmusicproxy server. Enable this by entering the proxy url as shown the below.

Example url

    gmusicproxy: "http://192.168.1.100:9999"
4 Likes

Would love to see this set as the default option or to be able to toggle from the front end.

Hi @troy, thanks for the welcome! While it’d be nice if there was a simple copy/paste solution, I wasn’t expecting there to be. :slight_smile: I only just got this up and running, and haven’t had time to dig into the internals too much due to life being life. I was hoping you’d at least be able to point me in a direction to look, which you have, so thank you! I will look into setting up an automation that writes the data from the gmusic_player when it’s active to the default media receiver instance. Even if it’s not easily possible, thanks for work on this plugin. It’s super handy (and fun to watch people’s reactions when you say “Alexa, it’s time to chill” and the mood lighting sets while some background music starts automatically)

I have the same issue. Did you manage to find a solution? It seems that the media player component Is the problem. Set image in media player

@troy

I updated last night and so far, everything is working great. Thank you for your hard work!

1 Like

Cannot get legacy app password login to work. Tried with deviceid 00 to get a list of valid ones. Reconfigured with valid id but then I get this permission error. Installed using HACS.

ERROR (MainThread) [homeassistant.components.media_player] Error while setting up platform gmusic_player
Traceback (most recent call last):
  File "/srv/homeassistant/lib/python3.6/site-packages/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.6/asyncio/tasks.py", line 358, in wait_for
    return fut.result()
  File "/usr/local/lib/python3.6/concurrent/futures/thread.py", line 56, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/home/homeassistant/.homeassistant/custom_components/gmusic_player/media_player.py", line 87, in setup_platform
    add_devices([GmusicComponent(hass, config)])
  File "/home/homeassistant/.homeassistant/custom_components/gmusic_player/media_player.py", line 141, in __init__
    with open(_authtoken, 'wb') as f:
PermissionError: [Errno 13] Permission denied: './.gmusic_authtoken'

EDIT: specifying a token_path fixed this

Looks like it is trying to use the token and the directory permissions are incorrect. Make sure it is RW

I’ll add an option to set this in the config. I think from that you can use an input_boolean to trigger an automation that changes the setting.

There is a way to do this but it’s a bit of a hack. I’ll try to get together a working example but it’s not perfect. Basically you set up some kind of automation to sync the gmusic_player attributes to the Default Media Receiver.

1 Like

Hi, I have set up everything, the card shows what it should ok, but when I try to play anything, anywhere it gives me an error:
Failed to get URL for track: (Tn2r6kg5wvhfbfdtiuis47hcbua)
Any ideas? tks

By chance, do you have gmusicproxy anywhere in your gmusic_config.yaml?

Hi, tks for the answer, no I don’t have that.

@Tere_Ruiz

I’m not exactly sure then :thinking:

Is everything broke? I mean, have you tried playlist and stations?

May I see your gmusic_config.yaml as you have it configured.

Can you try this:

Tks here goes my config, I replaced my user and pwd obviously:

## Google Music Media Player
## Use this 'package.yaml' file to configure "gmusic_player"
media_player:
  - platform: gmusic_player
    username: "myuser"
    password: "mypwd"
    device_id: "c06474b3ae52d68191e3fbe08a559a6b8898b56f647a38200556cd89be29f647"

input_select:
  gmusic_player_speakers:
    name: Speakers
    icon: mdi:speaker
    ## Add your media_players below
    options: # Example media_players
    - Grupo_Toda_la_casa
    - Grupo_Sin_Cuarto
    - Grupo_Sala_y_pérgola
    - Grupo_Jardín_y_Pérgola
    - Bocina_de_la_sala
    - Bocina_de_Samsung
    - Video_pérgola

I’ll try the reinstall later on and let you know.

Do you have a different device id to try.

    device_id: "c06474b3ae52d68191e3fbe08a559a6b8898b56f647a38200556cd89be29f647"

This might need android device id. It should be something shorter like this.

    device_id: "21150e2000000456"

Quick question which feels a little stupid. What media players are valid targets

Here is my config:

## Google Music Media Player
## Use this 'package.yaml' file to configure "gmusic_player"
media_player:
  - platform: gmusic_player
    username: !secret gmusic_username
    password: !secret gmusic_password
    device_id: !secret gmusic_device_id 

input_select:
  gmusic_player_speakers:
    name: Speakers
    icon: mdi:speaker
    ## Add your media_players below
    options: # Example media_players
    - media_player.dining_room_speaker

I’m getting this from my google home target using the entity id above

Log Details (ERROR)
Wed Oct 09 2019 15:02:13 GMT-0500 (Central Daylight Time)
(media_player.dining_room_speaker) is not a valid media player.

edit: by the way nice job on this
edit2: NVM figured it out remove media_player. from the entity id

That was it!!! Thank you very much!!!

Hello, I a hoping that someone can help me out here. I have installed the component through hacs, followed all the instructions and the component is failing to load. There are a couple of entries in the log:

Fri Oct 11 2019 21:10:26 GMT-0600 (Mountain Daylight 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 1171, 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 1211, in async_call
processed_data = handler.schema(service_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’]

And

Fri Oct 11 2019 21:10:13 GMT-0600 (Mountain Daylight Time)

Setup failed for gmusic_player: No setup function defined.

Anyone have any ideas?
Currently running the latest version 0.100

maybe try installing it manually by downloading from git put the appropriate files in custom_components and packages and make sure you edit the files with the proper email and password. I actually went this route after i used hacs. I had issues initially but i don’t think it was bc i used hacs rather i didnt configure it properly