PS5-MQTT: Control PlayStation 5 devices using MQTT

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
10 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

New install of what?

Reinstalled the plugin, then Config copied again. Before and after the reinstallation, this error occurs since the update to 1.1.0

Please create an issue on github. Please don’t skimp out on any of the requested information. The more details you can provide, the easier it will be to get help.

ok, when i‘m back from work :+1:

when I just came home from work, an update for HomeAssistant was available, I did the update and now everything works again. So it was up to HomeAssitant and not PS5-mqtt.

1 Like

Hi Guys
I’ve just installed this and have linked my PS5 yet can’t seem to get it to tell me what game I’m playing. I’m showing as ONLINE and my game activity is set to anyone.

I’ve not set up the NPSSO as I really don’t understand how it works.

Could someone please help

Did you read the docs?

Yes
As stated in my post I don’t understand how the NPSSO works and I’m asking for help
I can get the NPSSO but then it talks about exchanging ect