Hass + Gass is awesome! But can't start and stop media player?

Hello friends!

I have set up Google Assistant on Home Assistant (0.82.1). I can turn the volume of my Bluesound Node media player up and down with “OK Google” commands on my phone, but when I say “OK Google” … “turn on/off mediaplayer” it says it will do so, but doesn’t, and only shows the brightness level for turning up and down the volume.

I understand that Google Assistant doesn’t actually support media players, and that it sees the media player as a light bulb. I therefore suspect that the problem is that the commands actually sent to the player is something like “turnon” and “turnoff” whereas they need to be “pause”/“play”. I suspect this to be the problem.

It this true? If so, shouldn’t Home Assistant know to convert whatever commands Google sends, to the commands necessary for carrying out the intended task for the specific media player, in this case to the “pause” or “play” commands?

If this is not done, how do I fix it? And am I even on the right track?

Thank you so much for all the help!
Hans Frederik

1 Like

PS: When I have fixed this problem, I am done setting up my home automation, and I will not need any more help in the foreseeable future. So, please help me solve this very last issue!

Guys!

The file that needs manipulation is definitely ...PYTHON_FOLDER/site-packages/homeassistant/components/google_assistant/trait.py, so, I copied that file to .../homeassistant/custom_components/google_assistant and under

class OnOffTrait(_Trait):
    """Trait to offer basic on and off functionality.

    https://developers.google.com/actions/smarthome/traits/onoff
    """

    name = TRAIT_ONOFF
    commands = [
        COMMAND_ONOFF
    ]

    @staticmethod
    def supported(domain, features):
        """Test if state is supported."""
        return domain in (
            group.DOMAIN,
            input_boolean.DOMAIN,
            switch.DOMAIN,
            fan.DOMAIN,
            light.DOMAIN,
            cover.DOMAIN,
            media_player.DOMAIN,
        )

    def sync_attributes(self):
        """Return OnOff attributes for a sync request."""
        return {}

    def query_attributes(self):
        """Return OnOff query attributes."""
        if self.state.domain == cover.DOMAIN:
            return {'on': self.state.state != cover.STATE_CLOSED}
        return {'on': self.state.state != STATE_OFF}

    async def execute(self, command, params):
        """Execute an OnOff command."""
        domain = self.state.domain

        if domain == cover.DOMAIN:
            service_domain = domain
            if params['on']:
                service = cover.SERVICE_OPEN_COVER
            else:
                service = cover.SERVICE_CLOSE_COVER

        elif domain == group.DOMAIN:
            service_domain = HA_DOMAIN
            service = SERVICE_TURN_ON if params['on'] else SERVICE_TURN_OFF

I added the following:

        elif domain == media_player.DOMAIN:
            service_domain = domain
            service = media_player.SERVICE_MEDIA_PLAY if params['on'] else media_player.SERVICE_MEDIA_PAUSE

Without any result, I played around a bit, like trying service_domain = HA_DOMAIN, but nothing worked. I am purely guessing here, have no idea what I am actually doing, so please, someone that knows this, help me with this last issue.

The media_player.bluesound component does not support the on/off service in HA, therefore that feature is also not exposed out to GA.

That makes sense to me, since you would not want to turn your media player on/off, you would want to make it play/pause. Surely there must be a way to turn the GA command “turn on/off media player” into the HA service call “media_player.media_play/media_player.media_pause”.

Thank you

That would have to be a global change for all media players, I’m not sure if that’s something we want to do. AVRs would find on/off to be more useful.
We might be able to reverse engineer what GA does for chromecasts to see if we can enable play/pause

Would it then be able to support a command like “set media player to play” and “set media player to pause”, or how should I understand this?

Not via the current modes (or toggles) trait. There is a predefined list of options we would have to use and that isn’t available.
Looks like we might be able to tap the Start/Stop trait for this. Still might be worth looking at what Chromecasts do though

1 Like

I am a strong supporter of whatever you say would make it possible! I just feel a bit sad that I can’t help in any way, since I have no technical skills. But “start media player” and “stop media player” would work perfect for me!

I think the StartStop trait looks very promising, since it also talks about devices capable of pausing. I just have no idea how to ever turn the instructions on that page into something relevant.

1 Like

Any updates on improving Google Assistant integration for hassio?

I looked and I would think play/pause would be available if MediaState was exposed?

There must be other conversations about this limitation I haven’t yet found