Playstation 4/PS4 custom component

@yrune good catch. Thanks, I missed a step somewhere!

Hey, I have an issue with this component since ages. From one day to the other the media player stopped showing the image of the current game. Itā€™s quite weird and Iā€™ve tried everything to solve this issue. The media player looks like this:

1

The state of the media player lists an entity picture with a local path:

and when I open this path in my browser the image of the current game is shown in the browser:

So the path works but the component doesnā€™t load it into the media player. As I said it worked perfectly and I havenā€™t changed any config. Config is set to local storage as shown in the instructions. Any fix for that?

One thing Iā€™ve never been clear on, are we supposed to be supplying these images (as in go and find an image for every game we have and put it in a folder), or is the add on supposed to be grabbing them itself online?

If you use local option you have to get these images for yourself and place them in a folder in www.

How do you name the images?

Images need the gameā€™s ID in name. See:

gameid

i still only get small icon. its not showing in frontend.

this is my setup:

- platform: ps4
  host: http:/XXXXXX:3031
  ps4_ip: XXXXXXX
  name: PlayStation 4
  local_store: games

Is there another option other than local?

You havenā€™t read the manual. Default option is without local storage. Instead it uses an online database. Just leave out the local_store part in your config.

@hmn can you help out with the image preview issue?

Yeah I donā€™t have local config in my setup but I still donā€™t get any images. Not sure itā€™s ever worked to be honest but wasnā€™t sure if it was just me.

To me itā€™s the other way round. I have always used the local option. Sorry, I didnā€™t know that the online mapping didnā€™t work either. @7even I also only get the small icon.

I just got the component working . YEAY!
BUTā€¦ I do not use local for game images but I only get images on some of the games. The games that do work I get both small and large images, for the ones that donā€™t I donā€™t get any images. Looking into it now thou, I think I saw something about this before

I canā€™t get root , i tried with new instalatiĆ³n but nothing, when you make the authorized_keys with puttygen you save as .ppk extensiĆ³n? Ayer this delete the comment import frontera USB, put the key in the ssh addon like authorized_keys, reboot and nothing i can access with port 22 but no 22222 access refused

After I reinstalled hassbian on my Pi I can not get this component to work anymore. I can control the ps4 but the mediaplayer.ps4 does not show up. In my previous installation everything worked. I am using the latetst version of the ps4.py file.

When I boot up homeassistant I get the following error:

2018-11-25 22:43:33 ERROR (Thread-14) [homeassistant.util.package] Unable to install package https://github.com/hmn/python-ps4/archive/master.zip#pyps4==dev: Command "/srv/homeassistant/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-7g96tekd/pycryptodomex/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-c99nklns-record/install-record.txt --single-version-externally-managed --compile --install-headers /srv/homeassistant/include/site/python3.5/pycryptodomex" failed with error code 1 in /tmp/pip-build-7g96tekd/pycryptodomex/
2018-11-25 22:43:33 ERROR (MainThread) [homeassistant.requirements] Not initializing media_player.ps4 because could not install requirement https://github.com/hmn/python-ps4/archive/master.zip#pyps4==dev
2018-11-25 22:43:33 ERROR (MainThread) [homeassistant.setup] Unable to prepare setup for platform media_player.ps4: Could not install all requirements.

Any suggestions to get this component working??

Last edit: this seems to be my issue.

My problem is that when I SSH into the RPi and run ps4-waker, everything works fine. When I try to go to http://HA_IP_ADDRESS:3031/ps4/PS4_IP_ADDRESS/info, Iā€™m getting a json {ā€œstatusā€:ā€œCould not detect any matching PS4 deviceā€}.

It seems like a network issue, but I confirmed that both my RPi and my PS4 are on the same network so I donā€™t think using --bind would help.

Any thoughts?

solved the issue of no caption / media_image displayed by modifying the ps4.py
this should do it :slight_smile:

basically, what I did is telling hass.io that entity_picture = media_image_url :wink:

you should edit your ps4.py in /custom_components/media_player/

hereā€™s my ps4.py file :

2 Likes

Does anybody know if itā€™s possible to get a push update (instead of polling) when the PS4 is turned on?

Iā€™m not a big fan of polling because it takes several seconds for a change to be noticed, but of course I realize that push updates are often not available.

1 Like

Iā€™ve managed to make it all work with updated component, but have problem with images not loading from PS Store. So I tried using older version of component, images do load without problem, but it doesnā€™t seem to connect to ps4-waker. Can I have both? Maybe there is some other version or someone has solution? Thanks

Edit:
I managed to find that this piece of code in ps4.py is missing in new version, so it doesnā€™t even try to download cover art, which is weird decision by author to omit this function. Iā€™m not able to edit this component myself as Iā€™m not a python coder, maybe someone else could do that. Hereā€™s the code in older version that fetched the cover art:

    def ps_store_cover_art(self):
    """Store coverart from PS store in games map."""
    import requests
    import urllib

    cover_art = None
    try:
        url = 'https://store.playstation.com'
        url += '/valkyrie-api/en/US/19/faceted-search/'
        url += urllib.parse.quote(self._media_title.encode('utf-8'))
        url += '?query='
        url += urllib.parse.quote(self._media_title.encode('utf-8'))
        url += '&platform=ps4'
        headers = {
            'User-Agent':
                'Mozilla/5.0 '
                '(Windows NT 10.0; Win64; x64) AppleWebKit/537.36 '
                '(KHTML, like Gecko) Chrome/63.0.3239.84 Safari/537.36'
        }
        req = requests.get(url, headers=headers)
    except requests.exceptions.HTTPError as error:
        _LOGGER.error("PS cover art HTTP error, %s", error)

    except requests.exceptions.RequestException as error:
        _LOGGER.error("PS cover art request failed, %s", error)

    for item in req.json()['included']:
        if 'attributes' in item:
            game = item['attributes']
            if 'game-content-type' in game and \
               game['game-content-type'] in \
               ['App', 'Game', 'Full Game', 'PSN Game']:
                if 'thumbnail-url-base' in game:
                    _LOGGER.debug("Found cover art for %s, %s %s",
                                  self._media_content_id,
                                  game['game-content-type'],
                                  game['thumbnail-url-base'])
                    cover_art = game['thumbnail-url-base']
                    cover_art += '?w=512&h=512'
                    self._gamesmap[self._media_content_id] = cover_art
                    break

hey @YuriGlushko , take a look to my post, itā€™s 2 replies above :blush:

feel free to edit it and add your ps_store_cover_art script :wink: