Playstation 4/PS4 custom component

Since I have python3.5, in CLI I ran:
PYTHONPATH=/usr/lib/python3.5/dist-packages:/srv/homeassistant/lib/python3.5/site-packages
but nothing changed, same error. Should I upgrade?

just tagged the latest python-ps4 module and pushed to pypi.

I can’t seem to make this component turn off the PS4, it correctly shows what’s playing on it tho.

Also, it will turn on the console, but it won’t start the game I select.

Ideas?

theres still a lot of limitations and bugs in the python ps4-waker module so only lookups are working, the rest of the features still need a lot of work.

3 Likes

Oh I see, thanks for the info!

I could use some help with this component please!

I have it all set up, I can see what games I am playing and change games, however the power button is not working to turn the ps4 to rest mode, or turn it back on with the media player. I have created a switch that has on command “sudo ps4-wake” and off command “sudo ps4-wake standby” and they both work perfectly.

Would there be any reason that the power button on the media_player wouldn’t be toggling the power? But the switch works fine. I also tried to create commands turn_on and turn_off for the media player which toggle the switch I made but that doesn’t work…

hmm

2 Likes

@hmn I tried this command and got this:

DEBUG:pyps4.ddp:send_recv_msg 192.168.31.151 [WAKEUP * HTTP/1.1
user-credential: <CREDENTIAL HERE
client-type:a
auth-type:C
device-discovery-protocol-version:00020020
]

But the configurator is erroring out:

2018-03-12 15:31:21 ERROR (SyncWorker_4) [pyps4.ddp] failed to send data using socket, timed out
2018-03-12 15:31:21 ERROR (MainThread) [homeassistant.core] Error executing service <ServiceCall configurator.configure: configure_id=1734212784-1, fields=credentials=18ddfcb>
Traceback (most recent call last):
File “/srv/homeassistant/lib/python3.6/site-packages/homeassistant/core.py”, line 1006, in _event_to_service_call
await service_handler.func(service_call)
File “/srv/homeassistant/lib/python3.6/site-packages/homeassistant/components/configurator.py”, line 224, in async_handle_service_call
call.data.get(ATTR_FIELDS, {}))
File “/usr/local/lib/python3.6/asyncio/futures.py”, line 332, in iter
yield self # This tells Task to wait for completion.
File “/usr/local/lib/python3.6/asyncio/tasks.py”, line 250, in _wakeup
future.result()
File “/usr/local/lib/python3.6/asyncio/futures.py”, line 245, in result
raise self._exception
File “/usr/local/lib/python3.6/concurrent/futures/thread.py”, line 56, in run
result = self.fn(*self.args, **self.kwargs)
File “/home/homeassistant/.homeassistant/custom_components/media_player/ps4.py”, line 117, in ps4_configuration_callback
if _check_ps4(host, credentials):
File “/home/homeassistant/.homeassistant/custom_components/media_player/ps4.py”, line 73, in _check_ps4
info = playstation.get_status()
File “/srv/homeassistant/lib/python3.6/site-packages/pyps4/ps4.py”, line 71, in get_status
return get_status(self._host)
File “/srv/homeassistant/lib/python3.6/site-packages/pyps4/ddp.py”, line 122, in get_status
ps_list = search(host=host)
File “/srv/homeassistant/lib/python3.6/site-packages/pyps4/ddp.py”, line 111, in search
data, addr = _send_recv_msg(host, broadcast, msg)
TypeError: ‘NoneType’ object is not iterable

I’m on HASSbian.

I wanted my harmony hub remote to be able to turn on and off the PS4. Turns out with this component and a couple automations on home assistant, everything works! This component is solid. Hope it is integrated with home assistant at some point.

Quick question, I’m in the process of segregating my devices from my main LAN, and putting them on an IoT network. I have this going for most things, but if I put the PS4 on the IoT network (Hass is on the main LAN), this component stops working.

The main LAN is 192.168.1.x
The IoT LAN is 192.168.200.x

Configuration file:

media_player:
     - platform: ps4
        host: http://192.168.1.15:3031
        ps4_ip: 192.168.200.17

With the PS4 on the IoT Network, this component doesn’t work. If I put the PS4 back on the main LAN, it works fine.

Just wondering if this is limitation (or something that just hasn’t be considered) of this component or if it’s an issue at my end somewhere :slight_smile:

For reference, my setup is designed so that components on the main LAN can talk to the IoT network, but the IoT network can’t initiate a connection to the main LAN itself.

the ps4 uses udp and have connections going both ways, and uses broadcast as well so I don’t think you will have any success in splitting it

Yep fair enough, maybe I won’t worry about moving the PS4 :wink:

I do have all ubiquiti equipment which has some decent options around this stuff, but it’s probably not worth digging in.

Thanks :slight_smile:

hi All,

I am using ps4-waker to successfully wake the device from sleep.
But some times due to power cuts the ps4 is switched off and when i am out of town i cant get it back to work.
Any way to boot the ps4 remotely?

the ps4 does not support wakeonlan, so the only way to control it is when it’s in standby mode

Could someone help me with this error?

Currently the component only detects if my ps4 is running or turned off. Games aren’t being detected and I also can’t start / stop the ps4.

When I start / stop the ps4, I get this error message in the log file:

2018-03-27 11:59:45 ERROR (MainThread) [homeassistant.core] Error executing service <ServiceCall media_player.turn_off: entity_id=['media_player.ps4']>
Traceback (most recent call last):
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/core.py", line 1006, in _event_to_service_call
    await service_handler.func(service_call)
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/media_player/__init__.py", line 402, in async_service_handler
    yield from getattr(player, method['method'])(**params)
  File "/usr/lib/python3.5/asyncio/futures.py", line 380, in __iter__
    yield self  # This tells Task to wait for completion.
  File "/usr/lib/python3.5/asyncio/tasks.py", line 304, in _wakeup
    future.result()
  File "/usr/lib/python3.5/asyncio/futures.py", line 293, in result
    raise self._exception
  File "/usr/lib/python3.5/concurrent/futures/thread.py", line 55, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/home/homeassistant/.homeassistant/custom_components/media_player/ps4.py", line 390, in turn_off
    self.ps4.standby()
  File "/srv/homeassistant/lib/python3.5/site-packages/pyps4/ps4.py", line 90, in standby
    self._connection.login()
  File "/srv/homeassistant/lib/python3.5/site-packages/pyps4/connection.py", line 63, in login
    self._send_login_request()
  File "/srv/homeassistant/lib/python3.5/site-packages/pyps4/connection.py", line 176, in _send_login_request
    msg = fmt.build(config)
  File "/srv/homeassistant/lib/python3.5/site-packages/construct/core.py", line 334, in build
    self.build_stream(obj, stream, **contextkw)
  File "/srv/homeassistant/lib/python3.5/site-packages/construct/core.py", line 344, in build_stream
    self._build(obj, stream, context, "(building)")
  File "/srv/homeassistant/lib/python3.5/site-packages/construct/core.py", line 2087, in _build
    buildret = sc._build(subobj, stream, context, path)
  File "/srv/homeassistant/lib/python3.5/site-packages/construct/core.py", line 2558, in _build
    return self.subcon._build(obj, stream, context, path)
  File "/srv/homeassistant/lib/python3.5/site-packages/construct/core.py", line 841, in _build
    _write_stream(stream, data, length)
  File "/srv/homeassistant/lib/python3.5/site-packages/construct/core.py", line 103, in _write_stream
    raise StreamError("bytes object of wrong length, expected %d, found %d" % (length, len(data)))
construct.core.StreamError: bytes object of wrong length, expected 64, found 120

Does someone of you know a solution to this?

Thanks :blush:

Now getting:

Failed to call info: {“status”:“Could not detect any matching PS4 device”}

After upgrading to 0.65.6

No-one else?

Restarted PS4Waker and now also get this in the logs:

Failed to call info: HTTPConnectionPool(host='192.168.1.15', port=3031): Max retries exceeded with url: /ps4/192.168.1.17/info (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x705a3770>: Failed to establish a new connection: [Errno 111] Connection refused',))

The IP’s are correct…

There is one problem with the python implementation.
I am running home assistant on a raspberry pi which has multiple network adapters.
With ps4-waker you can define the ip of the adapter that should be used with the following option
--bind <ip-adress>
Otherwise the connection can not be established.

This option is not present in the python implementation yet, resulting in the following error:
[pyps4.ddp] failed to send data using socket, timed out

Hey everyone.
Set this up as per the awesome instructions above (amazing, thanks!) and got it to turn on the PS4 as part of the instructions.
However, when I get to Hass.io it doesnt show the status of the PS4 and I can’t turn it on/off.

I just get this error in my log:
2018-04-04 00:30:26 ERROR (SyncWorker_0) [custom_components.media_player.ps4] Failed to call info: HTTPConnectionPool(host='192.168.1.x', port=3031): Max retries exceeded with url: /ps4/192.168.1.x/info (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x6fea8030>: Failed to establish a new connection: [Errno 111] Connection refused',))

Any ideas what I may have missed?

No, I’m getting the same, somethings broken in the recent updates I think.

Is there anyone around who knows how to fix this?

1 Like