Google music in HA

The Hassio addon has a limitation that any cast commands are ignored, however this docker container works great: Google Assistant Webserver in a Docker container

1 Like

I made it work in 0.90. Your folder setting is correct. But you should also update the switch.py

Great news! Iā€™m way behind on my updates, but I like the new Stream update (would like to see unifi though), but I canā€™t lose my precious google music!

@MomoB Could you show me your relevant config?

My switch.py: https://hastebin.com/osadalejuq.py
My media_players.yaml: https://hastebin.com/oxejikerev.cs

I am still getting an error in home assistant:

Unable to find platform gmusic.

Thank you for the hint.

Got it working and it behaves perfect for this usecase.
I can successfully call my playlists.

Now I need to think about how I want do the mapping between the RFID cards and the playlist.

I could simply use the same service and just do a curl to the specific playlist.

Will hopefully have time tomorrow for testing.

Your files are similar to mine, only difference is that i did not put my credidential in !secret .

But did you also copied the __pycache__ file that was in the previous custom_components/media_player folder ?

Iā€™m my homeassistant/custom_components/gmusic i have

__pycache__
__init__.py
switch.py

Confusing.

The pycache folder should not be important in that case. There is only python bytecode which is created after the first start normally.

Is your configuration available at github or something?
I need to commit my latest changes and would like to have a look to a working config.

@claytonjn Thanks again for the hint.
I think I will go this route:

I have setup Google Assistant Webserver in a Docker container.

I then can create my notify service:

notify:
  - name: ga_broadcast
    platform: rest
    resource: !secret google_assistant_webserver_broadcast_message
  - name: ga_command
    platform: rest
    resource: !secret google_assistant_webserver_command

Now I can create automation to use these commands:
The reset playlist automation will always get the input_text to back to ā€œBootValueā€.

For every playlist I would have an automation.

input_text:
  playlist:
    name: playlist
    initial: BootValue

automations:
- alias: Reset playlist value
  initial_state: True
  trigger:
  - entity_id: input_text.playlist
    from: BootValue
    platform: state
  action:
    - service: input_text.set_value
      data_template:
        entity_id: input_text.playlist
        value: "BootValue"

- alias: Play linkin park
  initial_state: True
  trigger:
    - platform: state
      entity_id: input_text.playlist
      to: '0011205436'
  action:
    - service: notify.ga_command
      data:
        message: "Play the playlist LinkinParkMeteora on uberall"

- alias: Play Motivation
  initial_state: True
  trigger:
    - platform: state
      entity_id: input_text.playlist
      to: '0016042153'
  action:
    - service: notify.ga_command
      data:
        message: "Play the playlist Motivation on uberall"

This works so war via the home assistant webinterface.

Now I try to figure out how to pass only the RFIF Card ID to the home assistant input_text.

I know how to do this via curl, but I do not know how I get the RFID Card ID from the reader right now.

Hopefully I can figure that out.

Great work!

You can use my code to grab the RFID cards from the reader to do the curl command.

Iā€™m trying to reset mine back up after all the HA updates and sifting through this thread.

I got mine playing again, but they are always playing shuffled. lol

I figured it outā€¦ smhā€¦

I have 2 components, one is gmusic and one is gmusic_shuffle. By default the gmusic.py listed in the original post shuffles the songs. I renamed that to gmusic_shuffle and then commented out a line to play track after track in a duplicated gmusic. At the bottom of gmusic.py (now switch.py) I commented out this line.

# random.shuffle(self._tracks)

Now my albums play straight through.

Phew!

Actually i was using your setup before 0.89.0 thanks a lot for the inspiration!

I wanted to just remove the parts I do not need anymore, like the cardList.csv.
So that the logic is only in home assistant and the rasperry pi is only sending the tag to home assistant.

Great Idea! Please post back if you get that working. Iā€™d love to check that out and possibly make the switch as well!

I am just struggeling to understand how I would get the card ID.

I can get some basic ipython3 terminal running and I can listen in a loop to get some card information:

Import librarys and setting up the reader:

import evdev
devices = [evdev.InputDevice(path) for path in evdev.list_devices()]
for device in devices:
...    print(device.path, device.name, device.phys)
device = evdev.InputDevice('/dev/input/event0')

Looping until the card will be near the RFID reader:

for event in device.read_loop():
    ...: ...     if event.type == evdev.ecodes.EV_KEY:
    ...: ...         print(evdev.categorize(event))
    ...: ... # pressing 'a' and holding 'space'

Result when card is near the reader:

key event at 1553636173.066585, 11 (KEY_0), down
key event at 1553636173.074576, 11 (KEY_0), up
key event at 1553636173.082591, 11 (KEY_0), down
key event at 1553636173.090593, 11 (KEY_0), up
key event at 1553636173.090593, 2 (KEY_1), down
key event at 1553636173.098581, 2 (KEY_1), up
key event at 1553636173.106586, 2 (KEY_1), down
key event at 1553636173.114597, 2 (KEY_1), up
key event at 1553636173.114597, 4 (KEY_3), down
key event at 1553636173.122592, 4 (KEY_3), up
key event at 1553636173.122592, 5 (KEY_4), down
key event at 1553636173.130603, 5 (KEY_4), up
key event at 1553636173.130603, 4 (KEY_3), down
key event at 1553636173.138604, 4 (KEY_3), up
key event at 1553636173.138604, 11 (KEY_0), down
key event at 1553636173.146608, 11 (KEY_0), up
key event at 1553636173.146608, 7 (KEY_6), down
key event at 1553636173.154604, 7 (KEY_6), up
key event at 1553636173.154604, 4 (KEY_3), down
key event at 1553636173.162608, 4 (KEY_3), up
key event at 1553636173.162608, 28 (KEY_ENTER), down
key event at 1553636173.170609, 28 (KEY_ENTER), up

I am not sure how to convert that into the card ID.
I think I still do not understand the code in your repository.

EDIT:

Got it working.
Need to document this the next days!

Ok, it kind of works.

So the problem is, when you crate a voice command to a google assistant you can not play a palylist.
There is no official way of that doing that right now.

You can for sure play an album are some genre music, but not a playlist:
https://support.google.com/googlehome/answer/7211943?hl=en

That means this could be quite difficult to solve.

Thank you for all useful informations in this thread. Got mine working fine and am compiling all those entities in a simpler card (see screenshot below). Iā€™m then asking myself if thereā€™s any way to get GMusic song metadatas as I got it working with radio streams, any idea?

1 Like

Iā€™m able to use voice commands to play a playlist (e.g. ā€œShuffle my Thumbs Up playlist on All Speakersā€) however I do have Google Play Music/YouTube Premium.

I do have a google play music subscription too.

Could you create a playlist with random songs and just try to say ā€œok google, play playlist WHATEVERā€?

In my case this does not work reliable.
If there is some way of doing that reliable it would be awesome!

Interesting, your right - it only works with Thumbs Up. Thatā€™s the only playlist I every play so Iā€™ve never tried anything else.

Does your Thumbs Up playlist work for you? Iā€™m my case the only thing unique about that playlist is that itā€™s downloaded to my phone. I canā€™t imagine that would make a difference though, it using Google Assistant to play it works from Assistant speakers and gawebserver, completely independent from my phone.

@claytonjn could you post the switch.py and _init.py? Iā€™m not sure what needs to be done to make the component work again

Sorry for the confusion, Iā€™m not using this component because I only care about playing my auto-generated ā€œthumbs upā€ playlist which I could never get working. Iā€™m using the gawebserver docker container to accomplish this.