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

Thanks for this. Unfortunately even though the script correctly sets those attributes the image and title do not show on the MiBox. I thought i would change the automation to set those values as soon as the gmusic_receiver changes its state to playing (instead of waiting 2 seconds) but it seems to set it and then immediately it gets cleared. Still busy troubleshooting

Just updated to the latest version.
but now it wont pull my playlist I guess.
.input_select] Invalid option: (possible options: )
Lets see what I find out

Trying to get gmusicproxy up and running in docker using the digitallyseamless image and I can get it running but I used portainer and am not too familiar with docker and cant seem to connect tot it.I would probably start a seperate thread for that as its related but not directly to this custom component

Latest version of HA or gmusic_player? Just curious but eithway nothing has changed related to the playlist. I’m on HA 0.100.3. I’ve started to see the same messages in my logs but I have not had it effect gmusic_player. I’ll have a look as well.

I’m trying to rework gmusic_player this so the input_select(s) can become completely optional.

For example:

  • If you do not have any stations then you should not need an input_select for them.
  • If you know the name of a playlist and would rather start playback using play_media service.

Also, while it may seem like I’m going the wrong direction (adding more stuff to the package files instead of directly to the custom_componet) I think this might be a better way to go. For example to populate the input_select I actually just calling the input_select.set_options service from inside the component. This can be done just a s easily using a script included in the package file.

Also since a script will become a services in HA, it’s easier to create a more custom service. Example in this case is being able to select the speakers using the play_media service. Unfortunately it seems I can not create a custom service for a platform.(gmusic_player is a custom platform for the media_player integration. At my understanding today gmusic_play would need to become its own separate integration (In other words is own domain). I’ve been around a few times trying to make this switch but I still don’t understand enough to get it working.

What I have been able to do though (Not released yet) is add an event listener to gmusic_player that can be triggered with a script. Then in the package file I can include a script to fire the new event.

Show script
script:
  gmusic_play_media:
    alias: gmusic_player.play_media
    description: 'Fire event: gmusic_play_media'
    fields:
      speakers:
        description: Name of the speakers to play music on.
        example: bedroom_stereo
      source:
        description: Media Source. Should be 'station' or 'playlist'
        example: station
      name:
        description: Name of the station or playlist.
        example: I'm Feeling Lucky
    sequence:
      - event: gmusic_player.play_media
        event_data_template:
          speakers: "{{ speakers }}"
          source: "{{ source }}"
          name: "{{ name }}"

So this is what I end up with
image

This has also made it easier to start playback of a specific station or playlist.

Show script
script:
  gmusic_play_something:
    alias: Play "Some Nights"
    sequence:
      - event: 'gmusic_player.play_media'
        event_data:
          speakers: bedroom_stereo
          source: playlist
          name: "Some Nights"

image

Have to restart a couple of times to get the input_select populated right. my hassio is already a little to big and got his performance issues.
The update for the oauth login Threw me up a little - I used one of the alpha versions until just now. :rofl:

The fields function is sexy as F.
And an optional input_select is ok as long as it isnt away for good - you need an way to get your stupid assinged playlist names somehow :stuck_out_tongue:

Does on your side the automation for the next track also triggers often in the middle of an song?

No it will not go away but to better explain, I’m thinking of moving the actual commands that populates the input_select out of the gmusic_player component and into separate scripts for each source Each script would fire a custom event similar to example above. Then we could use an automation to trigger the script to fire when HA starts. In the end this would give the same function provided now. Additionally for example, let’s say you do not use stations - you could just turn-off the automation that fires the script to “set_options for the input_select containing stations” – Even more you would be able to completely remove the input_select for stations and even the script and automation as well. Since the event to populate that input_select would never be fired gmusic_player would no longer crap out if you don’t have it or if the list is empty or whatever.

This might seem silly with only two sources but I’ve been playing around and more is on the way.
I cherry picked these changes already and will be included in gmusic_player shortly.

As it stands now @miikkajo’s fork has removed the playlist functionality. So this has got me thinking maybe some people don’t want every source so rather than have to remove it completely, you could just disable it’s related automation. I think this could effectively allow you to enable or disable different sources right from the HA gui by turning off or on the related automation.

Yes this happens but I can’t control it. gmusic_player itself is not actually playing music. (which is why the “speakers” are required) The songs get cut off because the playback url return by gmusicapi is only valid for a minute. Under certain situations the connection can be reset but since the link is no longer valid playback the song can not continue streaming so it just cuts off. The automation see the “default media receiver” go to an idle state so it triggers the next song. I have always noticed this happen once in a while (like maybe one or two song a month), even back using the original gmusic_switch. I’m not sure why it has gotten so much worse. Since late August it has become so bad that only a few songs ever make it to the end. The quick and easiest workaround to use gmusicproxy. (Needs installed separately) but then you can just set the url in gmusic_config.yaml and gmusic_player will get playback url from gmusicproxy that does not expire.

Ive set up gmusic_proxy using the docker image.
In packages I have gmusic_config.yaml with:

media_player:
  - platform: gmusic_player
    username: !secret gmusic_username
    password: !secret gmusic_password
    device_id: !secret gmusic_device_id
    gmusicproxy: 192.168.1.73:9999

0.0.0.0:9999 seems to be the ip:port that gmusicproxy is listening on but I cant see anything in the gmusicproxy log when I try to play anything. If I use vlc on a different machine with:

vlc 'http://192.168.1.73:9999/get_by_search?type=album&artist=Rolling%20Stones&title=tattoo&exact=no'

I can see in gmusicproxy log that it gets a track id for that album

192.168.1.43 - - [25/Oct/2019 19:02:28] "GET /get_by_search?type=album&artist=Rolling%20Stones&title=tattoo&exact=no HTTP/1.1" 200 -


Searching for album with query: Rolling Stones tattoo


Selected album: The Rolling Stones - Tattoo You (Buzub7yrmswkll7t7d7kancjtle)


Getting the tracks of the album with id 'Buzub7yrmswkll7t7d7kancjtle': Tattoo You - The Rolling Stones

edit I feel stupid I needed this in my gmusic_config.yaml instead

    gmusicproxy: http:192.168.1.73:9999

You need to http:// to the url in your config.

    gmusicproxy: 192.168.1.73:9999

should be.

    gmusicproxy: http://192.168.1.73:9999

Ya my edit tells the story :confounded::hammer: learning docker too lol .I wonder why the docker image page wants to map out port 80 when the built image actually listens on 9999

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