Native PlayStation 4 Component Discussion

Thanks, just wondered what the format was and how it was determined.

Hey, can you share a code how you achieve information of time played a game?

1 Like

Check out @SeanM’s post in this thread:

Native PlayStation 4 Component Discussion

Yes, i saw it, but this only show how much time your PS4 was ON.
Not how many time you played a game: Apex Legends.

Hi! When you put PS4 in sleep mode… What is the time before it changes state from “playing” to “off”?

That’s something I want to look into myself, then I can work out how long my son has played Minecraft :rofl:

@Ktnrg45 Will there be a fix on the slow state change from “playing” to “off”?

@Ktnrg45 Hi, adding a second PS4 worked now in 0.90.2. Had to change the name though to “Playstation 4-2” for it to work. Thanks for the fix!

succes

I’m still getting issue! :sleepy:

This is the error I get in log

2019-03-28 12:31:30 ERROR (MainThread) [aiohttp.server] Error handling request
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/aiohttp/web_protocol.py", line 418, in start
    resp = await task
  File "/usr/local/lib/python3.7/site-packages/aiohttp/web_app.py", line 458, in _handle
    resp = await handler(request)
  File "/usr/local/lib/python3.7/site-packages/aiohttp/web_middlewares.py", line 119, in impl
    return await handler(request)
  File "/usr/local/lib/python3.7/site-packages/homeassistant/components/http/real_ip.py", line 33, in real_ip_middleware
    return await handler(request)
  File "/usr/local/lib/python3.7/site-packages/homeassistant/components/http/auth.py", line 206, in auth_middleware
    return await handler(request)
  File "/usr/local/lib/python3.7/site-packages/homeassistant/components/http/view.py", line 112, in handle
    result = await result
  File "/usr/local/lib/python3.7/site-packages/homeassistant/components/config/config_entries.py", line 154, in post
    return await super().post(request, flow_id)
  File "/usr/local/lib/python3.7/site-packages/homeassistant/components/http/data_validator.py", line 46, in wrapper
    result = await method(view, request, *args, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/homeassistant/helpers/data_entry_flow.py", line 86, in post
    result = await self._flow_mgr.async_configure(flow_id, data)
  File "/usr/local/lib/python3.7/site-packages/homeassistant/data_entry_flow.py", line 80, in async_configure
    flow, step_id, user_input)
  File "/usr/local/lib/python3.7/site-packages/homeassistant/data_entry_flow.py", line 98, in _async_handle_step
    result = await getattr(flow, method)(user_input)  # type: Dict
  File "/usr/local/lib/python3.7/site-packages/homeassistant/components/ps4/config_flow.py", line 109, in async_step_link
    self.helper.link, self.host, self.creds, self.pin)
  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/pyps4_homeassistant/helpers.py", line 33, in link
    ps4.login(pin)
  File "/usr/local/lib/python3.7/site-packages/pyps4_homeassistant/ps4.py", line 138, in login
    self.open()
  File "/usr/local/lib/python3.7/site-packages/pyps4_homeassistant/ps4.py", line 98, in open
    self._connection.connect()
  File "/usr/local/lib/python3.7/site-packages/pyps4_homeassistant/connection.py", line 49, in connect
    self._socket.connect((self._host, self._port))
ConnectionRefusedError: [Errno 111] Connection refused

On the PC screen I get the red error, while on the PS4 I get the new device.
But then in HA nothing happens…

I have only one PS4 and I’m on 0.90.2

What can I try more?

Thanks

Hi, I try to configure my PS4, but after selecting Home-Assistant from the Second Screen app it fails and tells me “No PlayStation 4 devices found on the network.”

Any idea what could be causing this?

My Docker container also has the 987 and 997 setup

@AlexKalopsia Does your actual PS4 show up in the Second Screen app also?

Are you using the same PSN account for the Second Screen App and logged in to that same account when you are adding the device in the PS4?

Thanks for the help, it turns out I incorrectly set up Hass (I set the connection as Bridge rather than Host)!

Thanks @Ktnrg45

That was the issue.

I was using my daughter user, but on the app I was using mine.

Now it has paired.

Hi

sorry to bother you again.

Now that’s paired I get (only) this as media-control and mini-media-player in lovelace

I have other games showing on the PS4 when entering with same account that I’ve paired, but in HA it’s showing only Fortnite.

I saw some screenshot at the beginning of this thread showing also a lot of other info from PS4.

Then, I can turn off from HA, but I can’t turn on.

This is the code I’m using in lovelace

      - type: custom:mini-media-player
        entity: media_player.playstation_4
        icon: 'mdi:playstation'
        icon_state: true
        max_volume: 70

      - type: media-control
        entity: media_player.playstation_4

And this is what I see from States panel

21

I’m also getting those two errors

timed out
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/homeassistant/components/websocket_api/commands.py", line 122, in handle_call_service
    connection.context(msg))
  File "/usr/local/lib/python3.7/site-packages/homeassistant/core.py", line 1138, in async_call
    self._execute_service(handler, service_call))
  File "/usr/local/lib/python3.7/site-packages/homeassistant/core.py", line 1160, in _execute_service
    await handler.func(service_call)
  File "/usr/local/lib/python3.7/site-packages/homeassistant/helpers/entity_component.py", line 188, in handle_service
    self._platforms.values(), func, call, service_name
  File "/usr/local/lib/python3.7/site-packages/homeassistant/helpers/service.py", line 314, in entity_service_call
    future.result()  # pop exception if have
  File "/usr/local/lib/python3.7/site-packages/homeassistant/helpers/service.py", line 328, 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 371, in media_pause
    self.send_remote_control('ps')
  File "/usr/local/lib/python3.7/site-packages/homeassistant/components/ps4/media_player.py", line 394, in send_remote_control
    self._ps4.remote_control(command)
  File "/usr/local/lib/python3.7/site-packages/pyps4_homeassistant/ps4.py", line 184, in remote_control
    self.open()
  File "/usr/local/lib/python3.7/site-packages/pyps4_homeassistant/ps4.py", line 91, in open
    if self.is_standby():
  File "/usr/local/lib/python3.7/site-packages/pyps4_homeassistant/ps4.py", line 235, 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 221, in get_host_status
    return self.get_status()['status_code']
  File "/usr/local/lib/python3.7/site-packages/pyps4_homeassistant/ps4.py", line 126, in get_status
    return get_status(self._host)
  File "/usr/local/lib/python3.7/site-packages/pyps4_homeassistant/ddp.py", line 113, in get_status
    ps_list = search(host=host)
  File "/usr/local/lib/python3.7/site-packages/pyps4_homeassistant/ddp.py", line 102, in search
    data, addr = _send_recv_msg(host, broadcast, msg)
  File "/usr/local/lib/python3.7/site-packages/pyps4_homeassistant/ddp.py", line 91, in _send_recv_msg
    return sock.recvfrom(1024)
socket.timeout: timed out

and also this

Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/homeassistant/components/websocket_api/commands.py", line 122, in handle_call_service
    connection.context(msg))
  File "/usr/local/lib/python3.7/site-packages/homeassistant/core.py", line 1138, in async_call
    self._execute_service(handler, service_call))
  File "/usr/local/lib/python3.7/site-packages/homeassistant/core.py", line 1160, in _execute_service
    await handler.func(service_call)
  File "/usr/local/lib/python3.7/site-packages/homeassistant/helpers/entity_component.py", line 188, in handle_service
    self._platforms.values(), func, call, service_name
  File "/usr/local/lib/python3.7/site-packages/homeassistant/helpers/service.py", line 314, in entity_service_call
    future.result()  # pop exception if have
  File "/usr/local/lib/python3.7/site-packages/homeassistant/helpers/service.py", line 328, 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 371, in media_pause
    self.send_remote_control('ps')
  File "/usr/local/lib/python3.7/site-packages/homeassistant/components/ps4/media_player.py", line 394, in send_remote_control
    self._ps4.remote_control(command)
  File "/usr/local/lib/python3.7/site-packages/pyps4_homeassistant/ps4.py", line 184, in remote_control
    self.open()
  File "/usr/local/lib/python3.7/site-packages/pyps4_homeassistant/ps4.py", line 92, in open
    raise NotReady
pyps4_homeassistant.errors.NotReady

I don’t know what they are related to…

Both errors seem to be coming from the send_command service or using the media play/pause service. Are you using an automation for this?

No, just clicking on the lovelace cards

Try a wired connection instead of wifi if youre not already. Your ps4 is taking too long to respond to update requests.

No, it’s a wired connection. Really strange!

I am unable to integrate either. Using hassio on Raspberry pi. Following is the error log:

2019-04-02 01:16:27 ERROR (MainThread) [aiohttp.server] Error handling request
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/aiohttp/web_protocol.py", line 418, in start
resp = await task
  File "/usr/local/lib/python3.7/site-packages/aiohttp/web_app.py", line 458, in _handle
resp = await handler(request)
  File "/usr/local/lib/python3.7/site-packages/aiohttp/web_middlewares.py", line 119, in impl
return await handler(request)
  File "/usr/local/lib/python3.7/site-packages/homeassistant/components/http/real_ip.py", line 33, in real_ip_middleware
return await handler(request)
  File "/usr/local/lib/python3.7/site-packages/homeassistant/components/http/ban.py", line 68, in ban_middleware
return await handler(request)
  File "/usr/local/lib/python3.7/site-packages/homeassistant/components/http/auth.py", line 206, in auth_middleware
return await handler(request)
  File "/usr/local/lib/python3.7/site-packages/homeassistant/components/http/view.py", line 112, in handle
result = await result
  File "/usr/local/lib/python3.7/site-packages/homeassistant/components/config/config_entries.py", line 154, in post
return await super().post(request, flow_id)
  File "/usr/local/lib/python3.7/site-packages/homeassistant/components/http/data_validator.py", line 46, in wrapper
result = await method(view, request, *args, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/homeassistant/helpers/data_entry_flow.py", line 86, in post
result = await self._flow_mgr.async_configure(flow_id, data)
  File "/usr/local/lib/python3.7/site-packages/homeassistant/data_entry_flow.py", line 80, in async_configure
flow, step_id, user_input)
  File "/usr/local/lib/python3.7/site-packages/homeassistant/data_entry_flow.py", line 98, in _async_handle_step
result = await getattr(flow, method)(user_input)  # type: Dict
  File "/usr/local/lib/python3.7/site-packages/homeassistant/components/ps4/config_flow.py", line 56, in async_step_creds
self.helper.get_creds)
  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/pyps4_homeassistant/helpers.py", line 43, in get_creds
return credentials.listen()
  File "/usr/local/lib/python3.7/site-packages/pyps4_homeassistant/ps4.py", line 452, in listen
data = response[0]
UnboundLocalError: local variable 'response' referenced before assignment

My PS4 second screen app is getting connected to the PS4. I am logged into both with the same user account.

Is there something that I may be missing?