Native PlayStation 4 Component Discussion

PS4 Component is available now in the 0.89 release.

This is based off of the node.js package PS4-Waker and the Python module pyps4. The dependency for this component is a modified fork of pyps4.

This component is structured very differently than the custom components posted on here. No dealing with ps4-waker, more reliable art-work fetching, no configuration.yaml, no constant exceptions (hopefully).

Features:

  • Integration configuration for fetching credentials and initial setup
  • Turn off and on
  • Shows states
  • Select app/game
  • Service to emulate button presses
  • Auto-management and fetching of games and cover art

Instructions:
Please read the docs linked below before starting.

For more info see docs.

12 Likes

Iā€™ll have a look tonight!

This looks great! I hope it will be in a stable release soon.
I wish I could test it, but Iā€™m running HassOS. :frowning:

I woul like to try it, but i cant find this file

Iā€™m on hass.io on ubuntu 18.04

yea, I canā€™t find it either. Im not sure we can using a docker.

Hi. Have you managed to make it work?

No, Iā€™ve only reviewed the code

@Ktnrg45 i have added all files and change the config_entries.py, the PlayStation 4 integration is available in dashboard but when i click it, only what i see is ā€œcolorā€ circle spinning.
I have HA in docker (Synology NAS).
Any suggestion?
OK, i have error log:
2019-02-12 19:33:26 ERROR (MainThread) [aiohttp.server] Error handling request
Traceback (most recent call last):
File ā€œ/config/deps/lib/python3.6/site-packages/pyps4_homeassistant/helpers.pyā€, line 51, in port_bind
sock.bind((ā€˜0.0.0.0ā€™, port))
OSError: [Errno 98] Address already in use

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/aiohttp/web_protocol.py", line 418, in start
    resp = await task
  File "/usr/local/lib/python3.6/site-packages/aiohttp/web_app.py", line 458, in _handle
    resp = await handler(request)
  File "/usr/local/lib/python3.6/site-packages/aiohttp/web_middlewares.py", line 119, in impl
    return await handler(request)
  File "/usr/src/app/homeassistant/components/http/real_ip.py", line 34, in real_ip_middleware
    return await handler(request)
  File "/usr/src/app/homeassistant/components/http/ban.py", line 67, in ban_middleware
    return await handler(request)
  File "/usr/src/app/homeassistant/components/http/auth.py", line 99, in auth_middleware
    return await handler(request)
  File "/usr/src/app/homeassistant/components/http/view.py", line 118, in handle
    result = await result
  File "/usr/src/app/homeassistant/components/config/config_entries.py", line 111, in post
    return await super().post(request)
  File "/usr/src/app/homeassistant/components/http/data_validator.py", line 47, in wrapper
    result = await method(view, request, *args, **kwargs)
  File "/usr/src/app/homeassistant/helpers/data_entry_flow.py", line 57, in post
    handler, context={'source': config_entries.SOURCE_USER})
  File "/usr/src/app/homeassistant/data_entry_flow.py", line 64, in async_init
    return await self._async_handle_step(flow, flow.init_step, data)
  File "/usr/src/app/homeassistant/data_entry_flow.py", line 98, in _async_handle_step
    result = await getattr(flow, method)(user_input)  # type: Dict
  File "/usr/src/app/homeassistant/components/ps4/config_flow.py", line 41, in async_step_user
    failed = await self.hass.async_add_executor_job(helper.port_bind)
  File "/usr/local/lib/python3.6/concurrent/futures/thread.py", line 56, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/config/deps/lib/python3.6/site-packages/pyps4_homeassistant/helpers.py", line 54, in port_bind
    raise pyps4.errors.PortBindError
pyps4_homeassistant.errors.PortBindError

I tried this component on HA 0.88b0 and it works great (I didnā€™t change the media_player.py file name to ps4.py).
image

I just get the grey box with spinning circle when clicking configure.

Traceback (most recent call last):
  File "/srv/homeassistant/lib/python3.6/site-packages/aiohttp/web_protocol.py", line 418, in start
    resp = await task
  File "/srv/homeassistant/lib/python3.6/site-packages/aiohttp/web_app.py", line 458, in _handle
    resp = await handler(request)
  File "/srv/homeassistant/lib/python3.6/site-packages/aiohttp/web_middlewares.py", line 119, in impl
    return await handler(request)
  File "/srv/homeassistant/lib/python3.6/site-packages/homeassistant/components/http/real_ip.py", line 34, in real_ip_middleware
    return await handler(request)
  File "/srv/homeassistant/lib/python3.6/site-packages/homeassistant/components/http/ban.py", line 67, in ban_middleware
    return await handler(request)
  File "/srv/homeassistant/lib/python3.6/site-packages/homeassistant/components/http/auth.py", line 99, in auth_middleware
    return await handler(request)
  File "/srv/homeassistant/lib/python3.6/site-packages/homeassistant/components/http/view.py", line 118, in handle
    result = await result
  File "/srv/homeassistant/lib/python3.6/site-packages/homeassistant/components/config/config_entries.py", line 111, in post
    return await super().post(request)
  File "/srv/homeassistant/lib/python3.6/site-packages/homeassistant/components/http/data_validator.py", line 47, in wrapper
    result = await method(view, request, *args, **kwargs)
  File "/srv/homeassistant/lib/python3.6/site-packages/homeassistant/helpers/data_entry_flow.py", line 57, in post
    handler, context={'source': config_entries.SOURCE_USER})
  File "/srv/homeassistant/lib/python3.6/site-packages/homeassistant/data_entry_flow.py", line 64, in async_init
    return await self._async_handle_step(flow, flow.init_step, data)
  File "/srv/homeassistant/lib/python3.6/site-packages/homeassistant/data_entry_flow.py", line 98, in _async_handle_step
    result = await getattr(flow, method)(user_input)  # type: Dict
  File "/srv/homeassistant/lib/python3.6/site-packages/homeassistant/components/ps4/config_flow.py", line 47, in async_step_user
    helper.port_bind, ports)
  File "/usr/lib/python3.6/concurrent/futures/thread.py", line 56, in run
    result = self.fn(*self.args, **self.kwargs)
TypeError: port_bind() takes 1 positional argument but 2 were given

@Bartem this is sth similar to my error.

Sorry about the wait. The PR is approved. So should be releasing soon. For those who were experiencing errors it was because there was changes requested to the library.

Your NAS may be using ports 987 and/or 997. The component requires these 2 ports. You can try rebooting your NAS and check again.

I tried updating with your changesā€¦ maybe I messed something elseā€¦ but I was able to connect a pair second screenā€¦ but now get this.

019-02-15 21:19:06 ERROR (MainThread) [homeassistant.loader] Error loading homeassistant.components.media_player.ps4. Make sure all dependencies are installed
Traceback (most recent call last):
  File "/srv/homeassistant/lib/python3.6/site-packages/homeassistant/loader.py", line 117, in _load_file
    module = importlib.import_module(path)
  File "/usr/lib/python3.6/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 994, in _gcd_import
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 678, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/srv/homeassistant/lib/python3.6/site-packages/homeassistant/components/media_player/ps4.py", line 17, in <module>
    from homeassistant.components.media_player.const import (
ModuleNotFoundError: No module named 'homeassistant.components.media_player.const'
2019-02-15 21:19:06 ERROR (MainThread) [homeassistant.loader] Unable to find platform ps4
2019-02-15 21:19:06 ERROR (MainThread) [homeassistant.setup] Unable to prepare setup for platform media_player.ps4: Platform not found.

Hey @ktnrg45, this appears to be working fine (Iā€™m on 0.89.0b1), however the only thing that doesnā€™t quite seem to be working is turning the PS4 back on from rest mode. The card in HA shows the state as Unknown, and clicking start doesnā€™t seem to do anything. If I turn on the PS4 manually, everything else with the component works as expected.

Actually just noticed some errors in HA:

Error doing job: Task exception was never retrieved Traceback (most recent call last): File "/usr/local/lib/python3.7/site-packages/homeassistant/helpers/service.py", line 289, in _handle_service_platform_call await getattr(entity, func)(**data) File "/usr/local/lib/python3.7/concurrent/futures/thread.py", line 57, in run result = self.fn(*self.args, **self.kwargs) File "/usr/local/lib/python3.7/site-packages/homeassistant/components/ps4/media_player.py", line 345, in turn_off self._ps4.standby() File "/usr/local/lib/python3.7/site-packages/pyps4_homeassistant/ps4.py", line 93, in standby self.open() File "/usr/local/lib/python3.7/site-packages/pyps4_homeassistant/ps4.py", line 52, in open if self.is_standby(): File "/usr/local/lib/python3.7/site-packages/pyps4_homeassistant/ps4.py", line 185, in is_standby return True if self.get_host_status() == self.STATUS_STANDBY else False File "/usr/local/lib/python3.7/site-packages/pyps4_homeassistant/ps4.py", line 171, in get_host_status return self.get_status()['status_code'] File "/usr/local/lib/python3.7/site-packages/pyps4_homeassistant/ps4.py", line 72, in get_status return get_status(self._host) File "/usr/local/lib/python3.7/site-packages/pyps4_homeassistant/ddp.py", line 111, in get_status ps_list = search(host=host) File "/usr/local/lib/python3.7/site-packages/pyps4_homeassistant/ddp.py", line 100, in search data, addr = _send_recv_msg(host, broadcast, msg) File "/usr/local/lib/python3.7/site-packages/pyps4_homeassistant/ddp.py", line 89, in _send_recv_msg return sock.recvfrom(1024) socket.timeout: timed out

Log Details (WARNING) Mon Mar 04 2019 13:35:56 GMT+1100 (Australian Eastern Daylight Time) PS4 could not be reached

@Hansel Hmm, can you turn on PS4 normally from the 2nd Screen App? Theres a setting on the PS4 that you have to enable to be able to turn on from standby.

Hi @Ktnrg45, Iā€™ve commented on the github issue, but Iā€™ll double check this when I get home. Maybe it just set up funny initially? Is it easy enough to forget the current config and redo the integration?

Yes you can remove and redo integrations.

This is/was an issue at my end. Basically my PS4 loses network connection when its in rest mode. Iā€™ve switched it to a dynamic IP and weirdly that appears to have fixed it for now.

This has been the component Iā€™ve been looking forward to the most. Thank you for putting in the time and effort into creating this for us to use.

Edit: stuck with ā€œcould not bind port 987ā€ when trying ton configure the integration. Running Debian, have issued the setcap command as root:

sudo setcap 'cap_net_bind_service=+ep' /usr/bin/python3.7

Netstat shows I donā€™t have anything bound to port 987. PS4 is online and in the same subnet as the homeassistant instance.

Debug logs show the following:

'component.ps4.config.abort.no_devices_found': 'No PlayStion 4 devices found on the network.', 'component.ps4.config.abort.port_987_bind_error': 'Could not bind to port 987.', 'component.ps4.config.abort.port_997_bind_error': 'Could not bind to port 997.', 'component.ps4.config.error.login_failed': 'Failed to pair to PlayStation 4. Verify PIN is correct.', 'component.ps4.config.error.not_ready': 'PlayStation 4 is not on or connected to network.', 'component.ps4.config.step.creds.description': "Credentials needed. Press 'Submit' and then in the PS4 2nd Screen App, refresh devices and select the 'Home 'Home-Assistant' device to continue.", 'component.ps4.config.step.creds.title': 'PlayStation 4', 'component.ps4.config.step.link.data.code': 'PIN', 'component.ps4.config.step.link.data.ip_address': 'IP Address', 'component.ps4.config.step.link.data.name': 'Name', 'component.ps4.config.step.link.data.region': 'Region', 'component.ps4.config.step.link.description': "Enter your PlayStation 4 information. For 'PIN', navigate to 'Settings' on your PlayStation 4 console. Then navigate to 'Mobile App Connection Settings' and select 'Add Device'. Enter the PIN that is displayed.", 'component.ps4.config.step.link.title': 'PlayStation 4', 'component.ps4.config.title': 'PlayStation 4',

Further info: running in python 3.7.2 venv located at /srv/homeassistant on Debian Buster. HomeAssistant is fronted by Nginx.