PS5-MQTT: Control PlayStation 5 devices using MQTT

Why do you want to change this?

Hi I copied your code and it looks like this, the PS5 is in sleep mode rn so is that why?

Here is my code:

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

Because i‘m from germany and i just had like german commands :man_shrugging:t2:

I’m lost, is your question about the actual entity or a card?

I created a manual map and inserted various things. This also works perfectly, I see when the PS5 is on, it can turn it off and on and see what I’m playing. Everything is perfect … Only I would like to see something else instead of ‘idle’ and if the PS5 from us should be something else instead of ‘unvailable’. Now I would like to know where I can customise these commands.

Okay, I’m still not 100% sure what you mean so I’m going to guess…

There is no option to change the behaviour of the entities.

You can however use template entities to “change” the composition of the entities in HA itself. As demonstrated here.

Do you mean something like this?

type: custom:mushroom-template-card
primary: PlayStation 5
secondary: |-
  {% if is_state('switch.ps5_808_power', 'on') %}
    {{ state_attr('sensor.ps5_808_activity', 'title_name') or states('sensor.ps5_808_activity')    }}
  {%- elif is_state('switch.ps5_808_power', 'unavailable') -%}
    Powered off
  {%- else -%}
    {{ states('switch.ps5_808_power') }}
  {%- endif -%}
icon: mdi:sony-playstation
entity: switch.ps5_808_power
picture: '{{state_attr(''sensor.ps5_808_activity'', ''title_image'')}}'
badge_icon: |-
  {% if is_state('sensor.ps5_808_activity', 'playing') %}
    mdi:controller
  {%- elif is_state('sensor.ps5_808_activity', 'idle') -%}
    mdi:sleep
  {%- elif is_state('sensor.ps5_808_activity', 'unavailable') -%}
    mdi:power-plug-off
  {%- endif -%}

I would look something like this

grafik

1 Like

Yes, thats what j mean.
Unvailable change in Power off for example or something else

Your hyphens were the wrong ones use ' insted of ’ — You type the correct ones on a german keyboard with Shift + #

Correct code here

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

type: custom:mushroom-template-card
primary: PlayStation 5
secondary: |2-
{% if is_state(‘switch.playstation_5_power’, ‘on’) %}
{{ state_attr(‘sensor.playstation_5_activity’, ‘title_name’)
or states(‘sensor.playstation_5_activity’) }}
{%- elif is_state(‘switch.playstation_5_power’, ‘unavailable’)-%}
ausgeschaltet
{%- else -%}
{{ states(‘switch.playstation_5_power’) }}
{%- endif -%}
icon: mdi:sony-playstation
entity: cover.playstation_5_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
{%- elif is_state(‘sensor.playstation_5_activity’, ‘unavailable’) -%}
mdi:power-plug-off
{%- endif -%}
tap_action:
action: toggle
hold_action:
action: more-info
fill_container: false
multiline_secondary: false
icon_color: |-
{% if is_state(‘switch.playstation_5_power’, ‘on’) %}
cyan
{% endif %}
badge_color: red

This is my current code. I have now managed to replace ‘unvailable’, now I want to replace ‘idle’ and everything is perfect. Somewhere I have a mistake in thinking and can’t do it, can someone help me here?

I’ve modified the mushroom template a little bit:

Before:

After:

I’ve added a “check” in the picture part to see if the PS5’s activity is “playing”.
Only if both PS5s are online, the image won’t be correct due to the API.

type: vertical-stack
cards:
  - type: custom:mushroom-template-card
    primary: PlayStation 5 Sammy
    secondary: |-
      {% if is_state('switch.ps5_sammy_power', 'on') %}
        {{ state_attr('sensor.ps5_sammy_activity', 'title_name')
          or states('sensor.ps5_sammy_activity')
        }}
      {%- else -%}
        {{ states('switch.ps5_sammy_power') }}
      {%- endif -%}
    icon: mdi:sony-playstation
    entity: switch.ps5_sammy_power
    picture: |-
      {% if state_attr('sensor.ps5_sammy_activity', 'activity') == "playing" %}
      {{state_attr('sensor.ps5_sammy_activity', 'title_image')}}
      {% else %}
      {% endif %}
    badge_icon: |-
      {% if is_state('sensor.ps5_sammy_activity', 'playing') %}
        mdi:controller
      {%- elif is_state('sensor.ps5_sammy_activity', 'idle') -%}
        mdi:sleep
      {%- endif -%}
    tap_action:
      action: more-info
    hold_action:
      action: toggle
  - type: custom:mushroom-template-card
    primary: PlayStation 5 Vic
    secondary: |-
      {% if is_state('switch.ps5_vic_power', 'on') %}
        {{ state_attr('sensor.ps5_vic_activity', 'title_name')
          or states('sensor.ps5_vic_activity')
        }}
      {%- else -%}
        {{ states('switch.ps5_vic_power') }}
      {%- endif -%}
    icon: mdi:sony-playstation
    entity: switch.ps5_vic_power
    picture: |-
      {% if state_attr('sensor.ps5_vic_activity', 'activity') == "playing" %}
      {{state_attr('sensor.ps5_vic_activity', 'title_image')}}
      {% else %}
      {% endif %}
    badge_icon: |-
      {% if is_state('sensor.ps5_vic_activity', 'playing') %}
        mdi:controller
      {%- elif is_state('sensor.ps5_vic_activity', 'idle') -%}
        mdi:sleep
      {%- endif -%}
    tap_action:
      action: more-info
    hold_action:
      action: toggle

code:

3 Likes

Change the complete secondary part to

secondary: |-
  {% if is_state('sensor.ps5_808_activity', 'playing') %}
    {{ state_attr('sensor.ps5_808_activity', 'title_name') }}
  {%- elif is_state('sensor.ps5_808_activity', 'idle') -%}
    An tut aber nix
  {%- elif is_state('sensor.ps5_808_activity', 'none') -%}
    Schläft
  {%- elif is_state('sensor.ps5_808_activity', 'unavailable') -%}
    Ausgeschaltet
  {%- endif -%}

This should give you the possbility to change every possible state of the sensor and rename it however you seem fit

Obviously you need to change the sensor to the correct name …

That’s it, thank you very much. Somewhere I probably had a mistake in thinking and when I look at the code now, I also know where … Thanks :slight_smile:

Thanks it worked!

@FunkeyFlo, thanks for the great addon!

I’ve got a suggestion and a question.

Suggestion: maybe make it clearer that activity info is dependent on PSN account configuration in the addon. I say this because since the Activity sensor is there by default, I was initially confused why all I got was “Idle” as a state instead of all the rest of the info (game name, picture, etc).

Question: although everything seems to be working OK (sensor, switch) I regularly get this message in the addon logs:

2022-09-26T12:00:59.896Z @ha:ps5:error SyntaxError: Unexpected end of JSON input
    at JSON.parse (<anonymous>)
    at /app/server/dist/redux/sagas/check-devices-state.js:75:38
    at step (/app/server/dist/redux/sagas/check-devices-state.js:35:23)
    at Object.next (/app/server/dist/redux/sagas/check-devices-state.js:16:53)
    at next (/app/node_modules/@redux-saga/core/dist/redux-saga-core.dev.cjs.js:1161:27)
    at currCb (/app/node_modules/@redux-saga/core/dist/redux-saga-core.dev.cjs.js:1255:7)
    at runSelectEffect (/app/node_modules/@redux-saga/core/dist/redux-saga-core.dev.cjs.js:735:5)
    at runEffect (/app/node_modules/@redux-saga/core/dist/redux-saga-core.dev.cjs.js:1208:7)
    at digestEffect (/app/node_modules/@redux-saga/core/dist/redux-saga-core.dev.cjs.js:1275:5)
    at next (/app/node_modules/@redux-saga/core/dist/redux-saga-core.dev.cjs.js:1165:9)

Is something amiss?

Thanks,

Ricardo

suggestion

What would you suggest to make it less confusing?

error

Has been asked and answered multiple times.

TL;DR: Not a problem

@FunkeyFlo

suggestion

Maybe an explicit callout, something like “for information on usage status (idle/playing), game title, cover, etc, PSN account configuration is strictly required”.

error

Understood. It’s basically my whole log file, hence me asking.

1 Like

I don’t use HASSOS, I run my service on Docker. Are you able to port this to a HACS Addon? That way anyone can add it to the instance of HA however they run it.

There is no such thing as a HACS addon. And if you mean a HACS integration the answer is no…

Also there is an option to run this add-on within docker and the repo includes documentation on this. If you are unfamiliar with docker and docker compose I suggest to first read up on them before continuing.

Anyone got a link to the discord?

Do you need the psn stuff to be in the config to see if the PS5 is on or off? I don’t use my PS5 super often so I don’t want to have to be inputting the api code basically every time I use it.