PS5-MQTT: Control PlayStation 5 devices using MQTT

Just checked it out and you’re right the PSN api I used apparently doesn’t show activity outside games.

Since these API’s are undocumented I’m not sure how to fix it, or if there’s even a way to “fix” it at all. :cry:

That’s right, but… The PS5 its called PS5-387 but if I replace the “PS5” in “PS5-387” I get this error.

Invalid entity ID at position 0: switch.PS5-387_power
type: entities
entities:

  • switch.PS5-387_power

The names are normalized. Easiest way to figure out what the entity names are is by searching “PS5-387” in the devices overview.

Screenshot_20220907-175825

Screenshot_20220907-175836

Screenshot_20220907-175838

If i search for the device i see this :frowning:

Cant find the device info (as your second img)

Okay, best thing you can do is join the discord and share your logs (add-on) there. If you don’t know how to find the add-on logs please refer to the HA docs.

For those of us who dont use mqtt discovery, how do i manually configure the sensor and switch ?

the sensor appears relatively easy but not sure of the state and command topics for the switch.

does anyone have an example of a Custom Button Card? I just can’t get any further here… I get the status displayed, I can turn the PS5 on and off but what is currently being played I just can’t get into the Custom Card …

Ok I’ll try my best - hope I don’t make too many mistakes

First check if you see the correct attributes - it should look similar to this

Now you’ll need to add a template ( Mine is in the configuration.yaml )

sensor:
 - platform: template
   sensors:
    psn_image:
     value_template: >
      {% if states("sensor.ps5_808_activity") == "playing" %}
       {{state_attr('sensor.ps5_808_activity', 'title_image') }}
      {% else %}
        https://www.nicepng.com/png/full/10-104138_blue-playstation-logo-png-playstation-logo-no-background.png
      {% endif %} 

Keep in mind that the PS5 sensor will be a different one for you …

after reloading the template module (or restarting HA) you should have a sensor psn_image with the corresponding image

As you see I have this also set up as a generic camera

With the camera set up you - you can add it as an entity:

Or with mushroom cards:

hope that helped a little bit

5 Likes

You can also achieve a similar result without the extra entity template with mushroom cards. :blush:

image

type: custom:mushroom-template-card
primary: PlayStation 5
secondary: |-
  {% if is_state('switch.ps5_power', 'on') %}
    {{ state_attr('sensor.ps5_activity', 'title_name')
      or states('sensor.ps5_activity')
    }}
  {%- else -%}
    {{ states('switch.ps5_power') }}
  {%- endif -%}
icon: si:playstation
entity: switch.ps5_power
picture: '{{state_attr(''sensor.ps5_activity'', ''title_image'')}}'
badge_icon: |-
  {% if is_state('sensor.ps5_activity', 'playing') %}
    mdi:controller
  {%- elif is_state('sensor.ps5_activity', 'idle') -%}
    mdi:sleep
  {%- endif -%}
tap_action:
  action: more-info
hold_action:
  action: toggle
11 Likes

That’s so much easier ….

And great Add on

1 Like

Thanks! :pray:

And thank you for helping out your fellow users! :two_hearts:

1 Like

That’s fantastic, thank you very much. Just had to customise a few little things.

:smiling_face_with_three_hearts:

I’ve added this nice looking addon but stumbled on this bug:

I’ve added two PS5’s and my sons PS5 is offline, but it’s showing the same icon (Rocket League) as mine.

image

The PSN API unfortunately doesn’t expose which device the activity is being conducted on. As such the add-on does a best effort match (as described in the documentation) to match activity to a device.
This means that it is unable to distinguish activity between multiple devices of the same type.

Bug
However… the intended behaviour was to match the activity to one device and not multiple. So that does seem to be a bug. Would you be so kind to create an issue on the Github repo so we can better track this issue? :blush:

Missing Feature?
Additionally… even if the above issue is fixed this would mean that whenever you or your son are playing a game the add-on will match both your accounts to the same device. So I would propose the following new feature:

Adding “preferred” devices

Config

We could add two additional properties to each psn_account configuration:

psn_accounts:     
  - username: MyPsnUser
    npsso: '!secret my_npsso'
    preferred_ps5: 00C000C009B0  # match PS5 activity to this device if it is "on"
    preferred_ps4: 00D0D0B0A1C0  # match PS4 ...

We prefer using device ID’s over names because ID’s can never change.

Behaviour

When activity is detected the add on will first try to match the activity as follows:

  • If the preferred device is “on” activity will be matched to that device.
  • Otherwise, activity will be matched to the first available device that matches the activity’s platform (PS5 / PS4)

Known limitations

  • Only one preferred device can be registered per platform. However unlikely, this could be a “problem” for people who own three PS4’s or PS5’s. ¯\(ツ)
  • This “strategy” of matching activity is still not fool-proof. But I think, considering the limitations of the PSN API, that it is acceptable.

Please let me know if this behaviour would be sufficient for your use-case. Afterwards we can create a feature request on Github. :blush:

1 Like

Worth sharing with your fellow users? :grin:

Of course, here please

type: custom:mushroom-template-card
primary: PlayStation 5
secondary: |-
{% if is_state(‘switch.playstation_5_power’, ‘on’) %}
{{ state_attr(‘sensor.playstation_5_activity’, ‘title_name’)
or states(‘sensor.playstation_5_activity’)
}}
{%- else -%}
{{ states(‘switch.playstation_5_power’) }}
{%- endif -%}
icon: mdi:sony-playstation
entity: switch.ps5_power
picture: ‘{{state_attr(’‘sensor.playstation_5_activity’’, ‘‘title_image’’)}}’
badge_icon: |-
{% if is_state(‘sensor.playstation_5_activity’, ‘playing’) %}
mdi:controller
{%- elif is_state(‘sensor.playstation_5_activity’, ‘idle’) -%}
mdi:sleep

1 Like

Tnx for the proposed solution! Don’t put too much time in it however, it’s only a small “bug” :smiley:

1 Like

Does anyone have any problems since the update to 1.1.0? The addon switches off again and again directly, it does not stay on

Have you checked supervisor logs?

parse error: Expected string key before ‘:’ at line 1, column 4
[08:07:05] ERROR: Unknown HTTP error occured
parse error: Expected string key before ‘:’ at line 1, column 4
[08:07:05] ERROR: Unknown HTTP error occured
parse error: Expected string key before ‘:’ at line 1, column 4
[08:07:05] ERROR: Unknown HTTP error occured
Starting PS5-MQTT…

[08:47:51] ERROR: Got unexpected response from the API: Service not enabled
Starting PS5-MQTT…
node:internal/process/promises:279
triggerUncaughtException(err, true /* fromPromise */);
^
Error: getaddrinfo ENOTFOUND null
at GetAddrInfoReqWrap.onlookup [as oncomplete] (node:dns:71:26) {
errno: -3008,
code: ‘ENOTFOUND’,
syscall: ‘getaddrinfo’,
hostname: ‘null’
}

New install i have done yesterday, but it stay not on. Directly offline