Playstation 4/PS4 custom component

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:

Official PS4 component? https://github.com/home-assistant/home-assistant/pull/19469

3 Likes

Nice :+1:t2: :+1:t2:

1 Like

So Iā€™m trying to get this working with two PS4ā€™s on my network. Noticed that the docker image (the ps4-waker wrapper docker image) I have was updated today and now I canā€™t get anything running if I select commands. The ps4-waker seems to pull whatā€™s going on with my ps4s so far but starting and stopping them Iā€™m getting errors;

2018-12-24 21:28:53 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
File ā€œ/usr/local/lib/python3.6/site-packages/homeassistant/helpers/service.pyā€, line 277, in _handle_service_platform_call
await getattr(entity, func)(**data)
File ā€œ/usr/local/lib/python3.6/concurrent/futures/thread.pyā€, line 56, in run
result = self.fn(*self.args, **self.kwargs)
File ā€œ/config/custom_components/media_player/ps4.pyā€, line 372, in turn_on
self._ps4.wakeup()
File ā€œ/config/deps/lib/python3.6/site-packages/ps4_python3/ps4.pyā€, line 79, in wakeup
wakeup(self._host, self._credential)
File ā€œ/config/deps/lib/python3.6/site-packages/ps4_python3/ddp.pyā€, line 109, in wakeup
_send_msg(host, broadcast, msg)
File ā€œ/config/deps/lib/python3.6/site-packages/ps4_python3/ddp.pyā€, line 85, in _send_msg
_send_recv_msg(host, broadcast, msg, receive=False)
File ā€œ/config/deps/lib/python3.6/site-packages/ps4_python3/ddp.pyā€, line 77, in _send_recv_msg
sock.sendto(msg.encode(ā€˜utf-8ā€™), (host, DDP_PORT))
socket.gaierror: [Errno -2] Name does not resolve

Any ideas?

OK,

further to the problem above. If I remove one of the PS4s from my setup, I am still getting the playing information from the one I removed. I am still unable to wake up or put in standby from HA interface. However, I can log onto the docker instance and run the ps4-waker manually and it works fine.

Another reportā€¦seems the configuration has changed likely to get things in place for the official addition for this component. Flying a little blind with trial and error here. MIght start from scratch and see what happens. i get to the point where HASS restarts, logs show that there is no configuration for my PS4s so I try to configure them using the HASS interface. However, it never finds the PS4s.

So I did a reinstall from scratch, removed the PS4-waker from the PS4s and started all over again. This time I only added a single PS4. I see activity in HA (what games are being played etc) from my one system I added. But if the second system is on, I get the activity from it. It looks like the component is not using the IP address correctly when it queries whatā€™s going on. Digging into what ps4-waker does, it looks like if you donā€™t include the device IP, itā€™ll just find the first PS4 on your network. I canā€™t validate that 100% but it sure seems like thatā€™s whatā€™s going on.

Iā€™m also stuck with the images not showing up, neither the small one or the main one.

Iā€™m running on HASSIO 0.84.6.

In my config is:

- platform: ps4
  host: !secret ps4_host 
  ps4_ip: !secret ps4_ip_address
  name: PlayStation4
  local_store: games

Iā€™ve tried putting the image files in config/www/games/ as suggested and Iā€™ve also tried config/games/

What am I missing?

EDIT: I updated the custom component to include some additional logging and it shows the filename as

ps4 file name, /local/games/CUSA00127.jpg

so Iā€™m assuming /local is the problem?

@abdel.elbel That seems to have resolved my issues with images not showing up. Great work and thank you!

1 Like

Maybe nit picking here because for me itā€™s all working but I got this error in the logs (Could not detect any matching PS4 device)
and when starting or making the ps4 go to sleep via Google home it returns ā€œsomething went wrongā€ but Itā€™s all working.

Any idea where to start troubleshooting to solve this? Thanks!

Thank you for this. I was struggling to get this working before but your tutorial helped a lot.

Also the fact that home assistant as added the cloud management part has made integrating with google home even easier.

One question though, what is the importance of the (client type ā€œiā€) specifically the ā€œiā€. Mine showed an ā€œaā€ and it worked fine but I did changed it to an ā€œiā€.

Also I do get an error from google home saying there was an error with the PlayStation 4 when waking it up but it still wakes up. The error in the logs for PS4 Bridge Say ā€œLogin connect refused; retrying soonā€

Everything works just more annoying and curious (perfectionism)

Thank You!!!

So excited for pyps4 and the new component!!!