Playstation 4/PS4 custom component

Tags: #<Tag:0x00007f73999b98a8>

I have been working on a ps4 custom component, and to help new people I thought it would be a good idea to create a thread with some info and documentation.

  • The component is a standard media_player
  • It uses the nodejs tool ps4-waker
  • Supports display of current game and media_image
  • Supports starting adn stopping the ps4
  • Supports switching of games using the source interface

The component is located here

@Mister-Espria and @CoalaJoe thanks for the contributions.


This is solid!! Very nice. I think I’ll submit a PR soon for the custom Port option I added for myself.

@hmn Should the customer container update at the same speed as the HA provided container?

Yes i really like this component too. It makes my script and a lot of automation unnecessary.

The thing i would like to see added is support for multiple PS4’s as i have two at home :slight_smile:
But as i understand @hmn you’re looking into converting the ps4-waker into python. So it’s probably better to await that.

I’m pretty new to python, so it might take some time :slight_smile: if I get it working and I find the time to look into it.

But I would expect that the current setup should be close to support multiple ps4’s I just don’t have 2 so I haven’t tested it out, so I don’t really know how ps4-waker is behaving.

Right now I borrowed the update interval from the webos component, so I think it is updating every 10sec. I have not tried removing the throttle, but I guess I could play around with that, at some point I probably need to look more into the asyncio commands as well

Sorry, my question wasn’t very clear. I mean will Home Assistant update within the custom Container as it does today for me using the HA provided container? Just curious if it will add any delays to getting new releases or features to HA.

The custom docker I created is running with automated builds triggered when home assistant is updating so they should only be delayed 5-10 minutes depending on the build time

1 Like

ok i think i won’t be a lot of help as i am way newer to python than you :slight_smile: I would never manage to make the custom component as you did. i will look into the multiple ps4’s. maybe i can get something working :slight_smile:

The ps4-waker tool supports multiple PS4s. Altough, it is unknown what is beign displayed in the CLI (Because I can’t test that out).
You also can try out adding 2 credential files and add 2 entries in your configuration.

@hmn I would love to help you. I am somewhat new to Python, but have 3-4 years experiance with JS, OOP PHP and other WebFramworks.


A new version of the ps4-waker tool has been released. Version 1.1.1. It contains my changes that change the output from the ps4-waker search-function. It now returns a JSON instead of a JavaScript object, which should be a lot easier and we can remove the RegEx hacks… kind of. (The only thing we need to strip from the output is everything that is not inside the {}. Because there can be some debugging-output.)

New Scrapping

Here is a demo on how the game should be scrapped for now:

In future versions of ps4-waker on the NodeJS basis, there hopefully will be a version that will completly disable debugging and only return valid JSON strings.

Yes i know ps4-waker did support it. But i was really overthinking how the component would work with 2 different credential files. But in fact it was really easy to add 2 ps4’s. The only thing i had to do is rename the second credentials file and specify it in the config like so:

  - platform: ps4
  - platform: ps4
    name: '2nd playstation 4'
    filename: '.ps4-wake.credentials_2.json'
    games_filename: 'ps4-games_2.json'

Nice you got it in the new version so quickly. I saw @hmn merged it. So i will try to update to the new version today.

EDIT1: only strange thing i encountered was this:

17-05-03 14:40:50 ERROR (Thread-1) [custom_components.media_player.ps4] Timeout for command: ps4-waker -c /home/homeassistant/.homeassistant/.ps4-wake.credentials_2.json -d -t 5000 
17-05-03 14:40:50 WARNING (MainThread) [homeassistant.helpers.entity] Update for media_player.2nd_playstation_4 is already in progress

But i think this error only happens when the ps4 is turning on or when it is initialized.

EDIT2: the games_filename could be left away, then you have one list to maintain. But then you can run into issues, because you can select a game which is not available on that ps4.

Right. It should be possible to specify a name for the config file.

You can use the option games_filename for seperate game files.

Yes i know i have it working. That’s what i tried to explain. I have now two files. But i could use just one, because both consoles run the same games. But i with edit 2 i meant for other people wanting to use two consoles that it’s probably best to have to separate files otherwise it could cause trouble :slight_smile:

This looks awesome! I’ve got a ton of work to get to this part of the automation where I want to see what the PS4 is doing, but I’m definitely going to watch this one!

I upgraded ps4-waker to 1.1.1 without too many issues. as it turns out i had it installed in the virtual env and outside :slight_smile:.

1 Like

Awesome this will create options to control my lights when viewing Netflix on the PS4.

17-05-04 11:25:43 ERROR (MainThread) [homeassistant.components.media_player] Error while setting up platform ps4
Traceback (most recent call last):
  File "/srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/homeassistant/helpers/", line 153, in _async_setup_platform
    entity_platform.schedule_add_entities, discovery_info
  File "/usr/lib/python3.4/asyncio/", line 388, in __iter__
    yield self  # This tells Task to wait for completion.
  File "/usr/lib/python3.4/asyncio/", line 286, in _wakeup
    value = future.result()
  File "/usr/lib/python3.4/asyncio/", line 277, in result
    raise self._exception
  File "/usr/lib/python3.4/concurrent/futures/", line 54, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/home/homeassistant/.homeassistant/custom_components/media_player/", line 85, in setup_platform
    ps4 = PS4Waker(host, port, credentials, games_filename)
  File "/home/homeassistant/.homeassistant/custom_components/media_player/", line 242, in __init__
  File "/home/homeassistant/.homeassistant/custom_components/media_player/", line 273, in _load_games = json.load(f)
  File "/usr/lib/python3.4/json/", line 268, in load
    parse_constant=parse_constant, object_pairs_hook=object_pairs_hook, **kw)
  File "/usr/lib/python3.4/json/", line 318, in loads
    return _default_decoder.decode(s)
  File "/usr/lib/python3.4/json/", line 343, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/lib/python3.4/json/", line 361, in raw_decode
    raise ValueError(errmsg("Expecting value", s, err.value)) from None
ValueError: Expecting value: line 1 column 1 (char 0)

Any thoughts? Have the in custom_components/media_player directory

Also have .ps4-wake.credentials.json in the default config directory along with ps4-games.json file. Is there anything that i need to alter in the ps4 file?

Note: ps4-waker has been installed and working prior to attempting this.

Thanks for any help you can provide

I updated the ps4-waker to Version 1.1.1. Be sure to run the newest version and also run the newest component file from @hmn s repository.

could be either a rights problem to the games file or because you created it manually. It looks like it it trying to read the file but getting an empty response