JackJPowell / hass-psn

Home Assistant integration for the Playstation Network
https://www.home-assistant.io
MIT License
26 stars 0 forks source link

Improving PS5 Integration: Attribute List or Auto-Entity Creation #13

Open Levtos opened 2 weeks ago

Levtos commented 2 weeks ago

Is your feature request related to a problem? Please describe.

As a Home Assistant beginner, I’m always frustrated when I can’t fully utilize all the attributes of the PS5 integration. I can see the game covers and trophy information, but it’s tough for me to access and integrate all the extra details through the helper.

Describe the solution you'd like

I’d love to have a comprehensive list of all available attributes, maybe even grouped by which entity provides which info. Alternatively, it would be awesome if the integration could automatically create all entities in Home Assistant, so I don’t have to hunt for them.

Describe alternatives you've considered

I’ve considered looking through documentation and existing issues, but it’s quite overwhelming, especially as I’m just getting started. Manual integration of each attribute also seems tedious and time-consuming.

Additional context

I’m really excited about using this integration, as it’s something I’ve been looking for for years! If you need help translating the integration into German, feel free to reach out!

xXREDXIIIIXx commented 2 weeks ago

Below you can find the current Entity IDs and the attributes associated with them, I sympathise with you about being a new user and everything can be overwhelming, you should find the HA community to be very welcoming with answering questions or pointing you to relevant documentation

Manual integration of each attribute also seems tedious and time-consuming

Jack has done a lot of work to bring us this, you should be prepared to learn how to use it. there is a issue post from another user asking how to get the attributes #9, I have a post in there detailing how to do this.

media_player.ps5_console - Shows the title of the game you are playing or other information such as "Browsing the menu"

sensor.psn_status - Shows your online state - Online, Offline, Playing The below information is only available when a game is open on the console. left is the attribute name and right is the example output

sensor.playstation_trophy_level Shows Current trophy Level - 651

I hope this helps you out, but feel free to ask, I don't normally check here often but I should get notified of any replies.

Levtos commented 2 weeks ago

Hey xXREDXIIIIXx,

Thanks for your reply and the helpful information! I tried to implement what you suggested this morning because I saw the code in issue #9, but I'm running into some errors. I added the following code to my configuration.yaml:

# PSN
template:
  - sensor:
      - name: "PSN Trophäen Level"
        unique_id: "psn_trophy_level"
        icon: "mdi:trophy"
        state: "{{ state_attr('sensor.psn_data', 'trophy_summary').trophy_level }}"
        attributes:
          platinum: "{{ state_attr('sensor.psn_data', 'trophy_summary').earned_trophies['platinum'] }}"
          gold: "{{ state_attr('sensor.psn_data', 'trophy_summary').earned_trophies['gold'] }}"
          silver: "{{ state_attr('sensor.psn_data', 'trophy_summary').earned_trophies['silver'] }}"
          bronze: "{{ state_attr('sensor.psn_data', 'trophy_summary').earned_trophies['bronze'] }}"
          next_level_progress: "{{ state_attr('sensor.psn_data', 'trophy_summary').progress }}"

      - name: "PSN Status"
        unique_id: "psn_status"
        icon: "mdi:account-circle-outline"
        state: "{{ state_attr('sensor.psn_data', 'status') }}"
        attributes:
          name: "{{ state_attr('sensor.psn_data', 'status')['name'] }}"
          description: "{{ state_attr('sensor.psn_data', 'status')['description'] }}"
          platform: "{{ state_attr('sensor.psn_data', 'status')['platform'] }}"
          content_rating: "{{ state_attr('sensor.psn_data', 'status')['content_rating'] }}"
          play_count: "{{ state_attr('sensor.psn_data', 'status')['play_count'] }}"
          play_duration: "{{ state_attr('sensor.psn_data', 'status')['play_duration'] }}"
          platinum_trophies: "{{ state_attr('sensor.psn_data', 'status')['trophies']['platinum'] }}"
          gold_trophies: "{{ state_attr('sensor.psn_data', 'status')['trophies']['gold'] }}"
          silver_trophies: "{{ state_attr('sensor.psn_data', 'status')['trophies']['silver'] }}"
          bronze_trophies: "{{ state_attr('sensor.psn_data', 'status')['trophies']['bronze'] }}"
          earned_platinum_trophies: "{{ state_attr('sensor.psn_data', 'status')['earned_trophies']['platinum'] }}"
          earned_gold_trophies: "{{ state_attr('sensor.psn_data', 'status')['earned_trophies']['gold'] }}"
          earned_silver_trophies: "{{ state_attr('sensor.psn_data', 'status')['earned_trophies']['silver'] }}"
          earned_bronze_trophies: "{{ state_attr('sensor.psn_data', 'status')['earned_trophies']['bronze'] }}"
          trophy_progress: "{{ state_attr('sensor.psn_data', 'status')['trophy_progress'] }}"

Unfortunately, I'm encountering some errors. If you could provide any insights or suggestions, that would be awesome! Example Error:

`Logger: homeassistant.helpers.event
Quelle: helpers/template.py:621
Erstmals aufgetreten: 21:21:21 (12 Vorkommnisse)
Zuletzt protokolliert: 21:21:21

Error while processing template: Template<template=({{ state_attr('sensor.psn_data', 'status')['trophies']['bronze'] }}) renders=2>
Error while processing template: Template<template=({{ state_attr('sensor.psn_data', 'status')['earned_trophies']['platinum'] }}) renders=2>
Error while processing template: Template<template=({{ state_attr('sensor.psn_data', 'status')['earned_trophies']['gold'] }}) renders=2>
Error while processing template: Template<template=({{ state_attr('sensor.psn_data', 'status')['earned_trophies']['silver'] }}) renders=2>
Error while processing template: Template<template=({{ state_attr('sensor.psn_data', 'status')['earned_trophies']['bronze'] }}) renders=2>
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 619, in async_render
    render_result = _render_with_context(self.template, compiled, **kwargs)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 2654, in _render_with_context
    return template.render(**kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/jinja2/environment.py", line 1304, in render
    self.environment.handle_exception()
  File "/usr/local/lib/python3.12/site-packages/jinja2/environment.py", line 939, in handle_exception
    raise rewrite_traceback_stack(source=source)
  File "<template>", line 1, in top-level template code
  File "/usr/local/lib/python3.12/site-packages/jinja2/sandbox.py", line 304, in getitem
    return obj[argument]
           ~~~^^^^^^^^^^
jinja2.exceptions.UndefinedError: 'None' has no attribute 'earned_trophies'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 731, in async_render_to_info
    render_info._result = self.async_render(  # noqa: SLF001
                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 621, in async_render
    raise TemplateError(err) from err
homeassistant.exceptions.TemplateError: UndefinedError: 'None' has no attribute 'earned_trophies'`

Even when I manually add the helper under Settings -> Devices & Integrations -> Helpers, I still get the similiar error messages. Could it be possible that there's an issue with the translations since I'm logged in via de-DE?

Thanks again for your help!

Best, Levtos

xXREDXIIIIXx commented 2 weeks ago

Hey xXREDXIIIIXx,

Thanks for your reply and the helpful information! I tried to implement what you suggested this morning because I saw the code in issue #9, but I'm running into some errors. I added the following code to my configuration.yaml:

# PSN
template:
  - sensor:
      - name: "PSN Trophäen Level"
        unique_id: "psn_trophy_level"
        icon: "mdi:trophy"
        state: "{{ state_attr('sensor.psn_data', 'trophy_summary').trophy_level }}"
        attributes:
          platinum: "{{ state_attr('sensor.psn_data', 'trophy_summary').earned_trophies['platinum'] }}"
          gold: "{{ state_attr('sensor.psn_data', 'trophy_summary').earned_trophies['gold'] }}"
          silver: "{{ state_attr('sensor.psn_data', 'trophy_summary').earned_trophies['silver'] }}"
          bronze: "{{ state_attr('sensor.psn_data', 'trophy_summary').earned_trophies['bronze'] }}"
          next_level_progress: "{{ state_attr('sensor.psn_data', 'trophy_summary').progress }}"

      - name: "PSN Status"
        unique_id: "psn_status"
        icon: "mdi:account-circle-outline"
        state: "{{ state_attr('sensor.psn_data', 'status') }}"
        attributes:
          name: "{{ state_attr('sensor.psn_data', 'status')['name'] }}"
          description: "{{ state_attr('sensor.psn_data', 'status')['description'] }}"
          platform: "{{ state_attr('sensor.psn_data', 'status')['platform'] }}"
          content_rating: "{{ state_attr('sensor.psn_data', 'status')['content_rating'] }}"
          play_count: "{{ state_attr('sensor.psn_data', 'status')['play_count'] }}"
          play_duration: "{{ state_attr('sensor.psn_data', 'status')['play_duration'] }}"
          platinum_trophies: "{{ state_attr('sensor.psn_data', 'status')['trophies']['platinum'] }}"
          gold_trophies: "{{ state_attr('sensor.psn_data', 'status')['trophies']['gold'] }}"
          silver_trophies: "{{ state_attr('sensor.psn_data', 'status')['trophies']['silver'] }}"
          bronze_trophies: "{{ state_attr('sensor.psn_data', 'status')['trophies']['bronze'] }}"
          earned_platinum_trophies: "{{ state_attr('sensor.psn_data', 'status')['earned_trophies']['platinum'] }}"
          earned_gold_trophies: "{{ state_attr('sensor.psn_data', 'status')['earned_trophies']['gold'] }}"
          earned_silver_trophies: "{{ state_attr('sensor.psn_data', 'status')['earned_trophies']['silver'] }}"
          earned_bronze_trophies: "{{ state_attr('sensor.psn_data', 'status')['earned_trophies']['bronze'] }}"
          trophy_progress: "{{ state_attr('sensor.psn_data', 'status')['trophy_progress'] }}"

Unfortunately, I'm encountering some errors. If you could provide any insights or suggestions, that would be awesome! Example Error:

`Logger: homeassistant.helpers.event
Quelle: helpers/template.py:621
Erstmals aufgetreten: 21:21:21 (12 Vorkommnisse)
Zuletzt protokolliert: 21:21:21

Error while processing template: Template<template=({{ state_attr('sensor.psn_data', 'status')['trophies']['bronze'] }}) renders=2>
Error while processing template: Template<template=({{ state_attr('sensor.psn_data', 'status')['earned_trophies']['platinum'] }}) renders=2>
Error while processing template: Template<template=({{ state_attr('sensor.psn_data', 'status')['earned_trophies']['gold'] }}) renders=2>
Error while processing template: Template<template=({{ state_attr('sensor.psn_data', 'status')['earned_trophies']['silver'] }}) renders=2>
Error while processing template: Template<template=({{ state_attr('sensor.psn_data', 'status')['earned_trophies']['bronze'] }}) renders=2>
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 619, in async_render
    render_result = _render_with_context(self.template, compiled, **kwargs)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 2654, in _render_with_context
    return template.render(**kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/jinja2/environment.py", line 1304, in render
    self.environment.handle_exception()
  File "/usr/local/lib/python3.12/site-packages/jinja2/environment.py", line 939, in handle_exception
    raise rewrite_traceback_stack(source=source)
  File "<template>", line 1, in top-level template code
  File "/usr/local/lib/python3.12/site-packages/jinja2/sandbox.py", line 304, in getitem
    return obj[argument]
           ~~~^^^^^^^^^^
jinja2.exceptions.UndefinedError: 'None' has no attribute 'earned_trophies'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 731, in async_render_to_info
    render_info._result = self.async_render(  # noqa: SLF001
                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 621, in async_render
    raise TemplateError(err) from err
homeassistant.exceptions.TemplateError: UndefinedError: 'None' has no attribute 'earned_trophies'`

Even when I manually add the helper under Settings -> Devices & Integrations -> Helpers, I still get the similiar error messages. Could it be possible that there's an issue with the translations since I'm logged in via de-DE?

Thanks again for your help!

Best, Levtos

Not 100% Sure but I think the state you are trying to get is invalid:

state: "{{ state_attr('sensor.psn_data', 'trophy_summary').trophy_level }}"

Try the below as a test, these should just bring back the trophy level and your platinum count {{ states('sensor.playstation_trophy_level') }} {{ state_attr('sensor.playstation_trophy_level', 'platinum') }}