Playstation 4/PS4 custom component

I’m not sure if this is necro bumping, but I have to ask: Is there solution to set height of type: entity-button

I pasted your code and I’m very thankful, this is exactly what I looked for, but it would be more eye candy if we could have “ENTER”, " OPTIONS" and “BACK” buttons, same height as “arrow” buttons.

EDIT: Or i would make workaround - would make “ENTER”, " BACK" and “OPTIONS” icons, same dimensions as arrow icons and place them on buttons instead of text :slight_smile:

I’m no expert but when I tried to fix it, I found custom sizing wasn’t supported, probably due to the fact that Lovelace re-arranged to fit different screens and aspect ratios.

I like your idea. As yet another alternative, why not select existing icons that can represent those functions? Thumbs up, X, a cog/gear, etc.

Hi, thanks for info.
First of all, I am very new to HA and later I figured out that out of box, we are not able to put local icons, but only icons from https://cdn.materialdesignicons.com/4.5.95/ (let someone correct me if I’m wrong).

No matter, below is my modded configuration, but all credits goes to @aslongasbassstrings :slight_smile:

cards:
  - entity: media_player.playstation_4
    secondary_info: last-changed
    type: media-control
  - cards:
      - entity: media_player.playstation_4
        hold_action:
          action: more-info
        show_icon: true
        show_name: false
        tap_action:
          action: call-service
          service: ps4.send_command
          service_data:
            command: ps
            entity_id: media_player.playstation_4
        type: entity-button
      - entity: media_player.playstation_4
        style:
          height: 40px
        hold_action:
          action: more-info
        icon: 'mdi:gamepad-up'
        show_icon: true
        show_name: false
        tap_action:
          action: call-service
          service: ps4.send_command
          service_data:
            command: up
            entity_id: media_player.playstation_4
        type: entity-button
      - entity: media_player.playstation_4
        hold_action:
          action: more-info
        icon: 'mdi:cogs'
        show_icon: true
        show_name: false
        tap_action:
          action: call-service
          service: ps4.send_command
          service_data:
            command: option
            entity_id: media_player.playstation_4
        type: entity-button
    type: horizontal-stack
  - cards:
      - entity: media_player.playstation_4
        hold_action:
          action: more-info
        icon: 'mdi:gamepad-left'
        show_icon: true
        show_name: false
        tap_action:
          action: call-service
          service: ps4.send_command
          service_data:
            command: left
            entity_id: media_player.playstation_4
        type: entity-button
      - entity: media_player.playstation_4
        hold_action:
          action: more-info
        icon: 'mdi:gamepad-right'
        show_icon: true
        show_name: false
        tap_action:
          action: call-service
          service: ps4.send_command
          service_data:
            command: right
            entity_id: media_player.playstation_4
        type: entity-button
    type: horizontal-stack
  - cards:
      - entity: media_player.playstation_4
        hold_action:
          action: more-info
        icon: 'mdi:backburger'
        show_icon: true
        show_name: false
        tap_action:
          action: call-service
          service: ps4.send_command
          service_data:
            command: back
            entity_id: media_player.playstation_4
        type: entity-button
      - entity: media_player.playstation_4
        hold_action:
          action: more-info
        icon: 'mdi:gamepad-down'
        show_icon: true
        show_name: false
        tap_action:
          action: call-service
          service: ps4.send_command
          service_data:
            command: down
            entity_id: media_player.playstation_4
        type: entity-button
      - entity: media_player.playstation_4
        hold_action:
          action: more-info
        icon: 'mdi:thumb-up-outline'
        show_icon: true
        show_name: false
        tap_action:
          action: call-service
          service: ps4.send_command
          service_data:
            command: enter
            entity_id: media_player.playstation_4
        type: entity-button
    type: horizontal-stack
title: Playstation 4
type: vertical-stack

Of course, cover is also there, when PS is playing, currently is in rest mode.

I just found this: https://github.com/custom-cards/button-card and will try to playing later, after my job :slight_smile:

Btw, I don’t know if this is off topic, I also made Tasker - AutoVoice profiles, to run games with voice from my phone, via Tasker and Home Assistant plugin, and if someone is interested in that let me know on PM, I can create topic.

2 Likes

Custom button in the custom components section will let you use any image as a icon. That button will change your life and consume your free time for sure. I use it for 99% of my UI!

1 Like

This is how i did my PS4 Controls.
Two PS icons for ps and ps_hold buttons.
In general it’s 3 horizontal stacks of button entity:

Here is the code (i use pre baked scripts for every ps service action):

      - type: vertical-stack
        cards:
          - type: markdown
            content: >
                **Play Station 4**
          - type: horizontal-stack
            cards:    
              - entity: script.ps4_button_ps
                type: button
                icon: mdi:playstation
                show_name: false 
                tap_action:
                    action: toggle
              - entity: script.ps4_button_up
                type: button
                icon: mdi:arrow-up-drop-circle
                show_name: false
                tap_action:
                    action: toggle
              - entity: script.ps4_button_ps_hold
                type: button
                icon: mdi:playstation
                show_name: false
                tap_action:
                    action: toggle
          
          - type: horizontal-stack
            cards: 
              - entity: script.ps4_button_left
                type: button
                icon: mdi:arrow-left-drop-circle
                show_name: false
                tap_action:
                    action: toggle            
              - entity: script.ps4_button_enter
                type: button
                icon: mdi:location-enter
                show_name: false
                tap_action:
                    action: toggle
              - entity: script.ps4_button_right
                type: button
                icon: mdi:arrow-right-drop-circle
                show_name: false
                tap_action:
                    action: toggle
                    
          - type: horizontal-stack
            cards:
              - entity: script.ps4_button_back
                type: button
                icon: mdi:backspace
                show_name: false
                tap_action:
                    action: toggle
              - entity: script.ps4_button_down
                type: button
                icon: mdi:arrow-down-drop-circle
                show_name: false
                tap_action:
                    action: toggle
              - entity: script.ps4_button_option
                type: button
                icon: mdi:cogs
                show_name: false
                tap_action:
                    action: toggle

And the scripts are here:

'ps4_button_ps':
  alias: PS4 PS
  sequence:
  - data:
      command: ps
      entity_id: media_player.playstation_4
    service: ps4.send_command
'ps4_button_ps_hold':
  alias: PS4 PS Hold
  sequence:
  - data:
      command: ps_hold
      entity_id: media_player.playstation_4
    service: ps4.send_command
'ps4_button_down':
  alias: PS4 Down
  sequence:
  - data:
      command: down
      entity_id: media_player.playstation_4
    service: ps4.send_command
'ps4_button_up':
  alias: PS4 Up
  sequence:
  - data:
      command: up
      entity_id: media_player.playstation_4
    service: ps4.send_command
'ps4_button_option':
  alias: PS4 Option
  sequence:
  - data:
      command: option
      entity_id: media_player.playstation_4
    service: ps4.send_command
'ps4_button_left':
  alias: PS4 Left
  sequence:
  - data:
      command: left
      entity_id: media_player.playstation_4
    service: ps4.send_command
'ps4_button_right':
  alias: PS4 Right
  sequence:
  - data:
      command: right
      entity_id: media_player.playstation_4
    service: ps4.send_command
'ps4_button_enter':
  alias: PS4 Enter
  sequence:
  - data:
      command: enter
      entity_id: media_player.playstation_4
    service: ps4.send_command
'ps4_button_back':
  alias: PS4 Back
  sequence:
  - data:
      command: back
      entity_id: media_player.playstation_4
    service: ps4.send_command
1 Like

Hello every one,
I am trying to create a card for my harmony remote.
I followed petro’s setup Harmony Activities, Volume Slider, and Lovelace.
I am now trying to put the cover from my playstation as a state picture.
I managed to find the link for the cover which the entity_picture of the PS4.
I was wondering if there was a way to use entity_picture attribute to generate a link for the state picture.
Here is the code for the card:

aspect_ratio: 0%
entities:
  - entity: switch.ps4
  - entity: switch.fire_tv
  - entity: switch.watch_tv
  - entity: switch.listen_to_music
entity: sensor.harmony_activity
hold_action:
  action: none
state_image:
  Listen to Music: local/music.jpg
  Play PS4: #something using media_player.playstation4.entity_picture 
  PowerOff: local/Poweroff.png
  Watch Fire TV: local/fire_tv.jpg
  Watch TV: local/tv.jpg
tap_action:
  action: more-info
theme: Google Dark Theme
title: harmony
type: picture-glance

Thank you for your help

It’s possible but it takes alot to setup. You need to create a camera and cycle your images sent to the camera. Otherwise, if the URL set on Play PS4 changes, the picture will not update. Now you could also use a template card to get the same behavoir and it will update. I can help with it if you let me know what the entity and attribute is. You’d need to install HACS for custom cards and then get the 100% template card made by iantrich.

1 Like

Hi petro,
thank you very much for your response.
the PS4 entity is media_player.playstation_4 and the attribute for the cover is entity_picture

Did you get the 100% template card?

yes I have

Ah I forgot about a caveat, you’ll also need the preloader card because you have to use custom elements with it. You’ll need to preload picture-glance card.

type: custom:config-template-card
variables:
- states['media_player.playstation_4'].attributes.entity_picture
entities:
- media_player.playstation_4
- switch.ps4
card:
  aspect_ratio: 0%
  entities:
  - entity: switch.ps4
  - entity: switch.fire_tv
  - entity: switch.watch_tv
  - entity: switch.listen_to_music
  entity: sensor.harmony_activity
  hold_action:
    action: none
  state_image:
    Listen to Music: local/music.jpg
    Play PS4: "${ var[0] }"
    PowerOff: local/Poweroff.png
    Watch Fire TV: local/fire_tv.jpg
    Watch TV: local/tv.jpg
  tap_action:
    action: more-info
  theme: Google Dark Theme
  title: harmony
  type: custom:hui-picture-glance-card

Thank you very much for you help.
I have installed the preloader but I am no sure how to preload picture-glace card.

Hey everyone!

I have Router A connected to the internet, then I have Router B connected to Router A via ethernet.

My PlayStation4 is connected via ethernet to Router A, while my Raspi running HassOS is connected to Router B.

Internet --- Router A --- Router B --- Home Assistant
                |
               PS4

If I connect to Router B with my laptop, I can ping the PS4’s IP on Router A, I get a response so I’m able to reach it.
But when I try and pair the component, it won’t find my PS4 even if I type in the IP manually during the configuration.
Also the ps4 2nd screen app won’t find the PS4 if I connect my phone to Router B, but it finds it if I connect my phone to Router A.

Do you guys have any idea on how I could make it work please?

Thank you very much!

Still working on my auto button idea. But i have an issue with the entity pics. Any ideas how to import the links to the image files in json file that the ps4 integration is using to node red so i can use it to update the image on the sensor

Got it to work now i have 4 generic app sensors and 4 generic game sensors.that contains the 4last app/games i started on the ps4.

next step is to create template switches for them. but i think that will be the easy part

1 Like

Can you share how you achieved this? I’m interested to see how you did this, to use with PS4 and possibly other entities :slight_smile:

Sure . it may not be the prettiest or most effetive but i got it to work.

[{"id":"a99aca48.636358","type":"switch","z":"4d980637.848cf8","name":"","property":"ps4_media_image.media_content_type","propertyType":"msg","rules":[{"t":"eq","v":"game","vt":"str"},{"t":"eq","v":"app","vt":"str"}],"checkall":"false","repair":false,"outputs":2,"x":690,"y":460,"wires":[["e01ccecc.cd89"],["1197faa3.befed5"]]},{"id":"882d08da.7cd658","type":"ha-entity","z":"4d980637.848cf8","name":"ps4 game 1","server":"9b88cb19.5c8db8","version":1,"debugenabled":false,"outputs":1,"entityType":"sensor","config":[{"property":"name","value":""},{"property":"device_class","value":""},{"property":"icon","value":""},{"property":"unit_of_measurement","value":""}],"state":"data_app_game.attributes.media_title","stateType":"msg","attributes":[{"property":"entity_picture","value":"ps4_media_image.media_image_url","valueType":"msg"},{"property":"media_content_id","value":"data_app_game.attributes.media_content_id","valueType":"msg"},{"property":"media_content_type","value":"ps4_media_image.media_content_type","valueType":"msg"},{"property":"media_title","value":"data_app_game.attributes.media_title","valueType":"msg"}],"resend":true,"outputLocation":"","outputLocationType":"none","inputOverride":"allow","x":1530,"y":80,"wires":[[]]},{"id":"93809f99.8a0b2","type":"ha-entity","z":"4d980637.848cf8","name":"ps4 game 2","server":"9b88cb19.5c8db8","version":1,"debugenabled":false,"outputs":1,"entityType":"sensor","config":[{"property":"name","value":""},{"property":"device_class","value":""},{"property":"icon","value":""},{"property":"unit_of_measurement","value":""}],"state":"data_ps4game1.attributes.media_title","stateType":"msg","attributes":[{"property":"entity_picture","value":"data_ps4game1.attributes.entity_picture","valueType":"msg"},{"property":"media_content_id","value":"data_ps4game1.attributes.media_content_id","valueType":"msg"},{"property":"media_content_type","value":"ps4_media_image.media_content_type","valueType":"str"},{"property":"media_title","value":"data_ps4game1.attributes.media_title","valueType":"msg"}],"resend":true,"outputLocation":"data","outputLocationType":"msg","inputOverride":"allow","x":1530,"y":160,"wires":[[]]},{"id":"70b397b9.67f2e8","type":"ha-entity","z":"4d980637.848cf8","name":"ps4 game 3","server":"9b88cb19.5c8db8","version":1,"debugenabled":false,"outputs":1,"entityType":"sensor","config":[{"property":"name","value":""},{"property":"device_class","value":""},{"property":"icon","value":""},{"property":"unit_of_measurement","value":""}],"state":"data_ps4game2.attributes.media_title","stateType":"msg","attributes":[{"property":"entity_picture","value":"data_ps4game2.attributes.entity_picture","valueType":"msg"},{"property":"media_content_id","value":"data_ps4game2.attributes.media_content_id","valueType":"msg"},{"property":"media_content_type","value":"ps4_media_image.media_content_type","valueType":"str"},{"property":"media_title","value":"data_ps4game2.attributes.media_title","valueType":"msg"}],"resend":true,"outputLocation":"","outputLocationType":"none","inputOverride":"allow","x":1530,"y":220,"wires":[[]]},{"id":"939cb4e1.cbfdc8","type":"ha-entity","z":"4d980637.848cf8","name":"ps4 game 4","server":"9b88cb19.5c8db8","version":1,"debugenabled":false,"outputs":1,"entityType":"sensor","config":[{"property":"name","value":""},{"property":"device_class","value":""},{"property":"icon","value":""},{"property":"unit_of_measurement","value":""}],"state":"data_ps4game3.attributes.media_title","stateType":"msg","attributes":[{"property":"entity_picture","value":"data_ps4game3.attributes.entity_picture","valueType":"msg"},{"property":"media_content_id","value":"data_ps4game3.attributes.media_content_id","valueType":"msg"},{"property":"media_content_type","value":"ps4_media_image.media_content_type","valueType":"str"},{"property":"media_title","value":"data_ps4game3.attributes.media_title","valueType":"msg"}],"resend":true,"outputLocation":"","outputLocationType":"none","inputOverride":"allow","x":1530,"y":280,"wires":[[]]},{"id":"b6c3d143.ca2b4","type":"ha-entity","z":"4d980637.848cf8","name":"ps4 app 1","server":"9b88cb19.5c8db8","version":1,"debugenabled":true,"outputs":1,"entityType":"sensor","config":[{"property":"name","value":""},{"property":"device_class","value":""},{"property":"icon","value":""},{"property":"unit_of_measurement","value":""}],"state":"data_app_game.attributes.media_title","stateType":"msg","attributes":[{"property":"entity_picture","value":"ps4_media_image.media_image_url","valueType":"msg"},{"property":"media_content_id","value":"data_app_game.attributes.media_content_id","valueType":"msg"},{"property":"media_content_type","value":"ps4_media_image.media_content_type","valueType":"msg"},{"property":"media_title","value":"data_app_game.attributes.media_title","valueType":"msg"}],"resend":true,"outputLocation":"","outputLocationType":"none","inputOverride":"allow","x":1540,"y":400,"wires":[[]]},{"id":"6317a610.3948d8","type":"ha-entity","z":"4d980637.848cf8","name":"ps4 app 2","server":"9b88cb19.5c8db8","version":1,"debugenabled":false,"outputs":1,"entityType":"sensor","config":[{"property":"name","value":""},{"property":"device_class","value":""},{"property":"icon","value":""},{"property":"unit_of_measurement","value":""}],"state":"data_ps4app1.attributes.media_title","stateType":"msg","attributes":[{"property":"entity_picture","value":"data_ps4app1.attributes.entity_picture","valueType":"msg"},{"property":"media_content_id","value":"data_ps4app1.attributes.media_content_id","valueType":"msg"},{"property":"media_content_type","value":"data_ps4app1.attributes.media_content_type","valueType":"msg"},{"property":"media_title","value":"data_ps4app1.attributes.media_title","valueType":"msg"}],"resend":true,"outputLocation":"","outputLocationType":"none","inputOverride":"allow","x":1540,"y":480,"wires":[[]]},{"id":"5512c102.38a6b","type":"ha-entity","z":"4d980637.848cf8","name":"ps4 app 3","server":"9b88cb19.5c8db8","version":1,"debugenabled":false,"outputs":1,"entityType":"sensor","config":[{"property":"name","value":""},{"property":"device_class","value":""},{"property":"icon","value":""},{"property":"unit_of_measurement","value":""}],"state":"data_ps4app2.attributes.media_title","stateType":"msg","attributes":[{"property":"entity_picture","value":"data_ps4app2.attributes.entity_picture","valueType":"msg"},{"property":"media_content_id","value":"data_ps4app2.attributes.media_content_id","valueType":"msg"},{"property":"media_content_type","value":"data_ps4app2.attributes.media_content_type","valueType":"msg"},{"property":"media_title","value":"data_ps4app2.attributes.media_title","valueType":"msg"}],"resend":true,"outputLocation":"","outputLocationType":"none","inputOverride":"allow","x":1540,"y":560,"wires":[[]]},{"id":"68848ebd.9b60b","type":"ha-entity","z":"4d980637.848cf8","name":"ps4 app 4","server":"9b88cb19.5c8db8","version":1,"debugenabled":false,"outputs":1,"entityType":"sensor","config":[{"property":"name","value":""},{"property":"device_class","value":""},{"property":"icon","value":""},{"property":"unit_of_measurement","value":""}],"state":"data_ps4app3.attributes.media_title","stateType":"msg","attributes":[{"property":"entity_picture","value":"data_ps4app3.attributes.entity_picture","valueType":"msg"},{"property":"media_content_id","value":"data_ps4app3.attributes.media_content_id","valueType":"msg"},{"property":"media_content_type","value":"app","valueType":"str"},{"property":"media_title","value":"data_ps4app3.attributes.media_title","valueType":"msg"}],"resend":true,"outputLocation":"","outputLocationType":"none","inputOverride":"allow","x":1540,"y":660,"wires":[[]]},{"id":"189368be.a0bc5f","type":"inject","z":"4d980637.848cf8","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":100,"y":100,"wires":[["9b9d987.bbddb68"]]},{"id":"1197faa3.befed5","type":"api-current-state","z":"4d980637.848cf8","name":"","server":"9b88cb19.5c8db8","version":1,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"sensor.ps4_app_1","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data_ps4app1","override_data":"msg","blockInputOverrides":false,"x":1040,"y":400,"wires":[["98105449.793058"]]},{"id":"98105449.793058","type":"switch","z":"4d980637.848cf8","name":"","property":"data_app_game.attributes.media_content_id","propertyType":"msg","rules":[{"t":"eq","v":"data_ps4app1.attributes.media_content_id","vt":"msg"},{"t":"neq","v":"data_ps4app1.attributes.media_content_id","vt":"msg"}],"checkall":"false","repair":false,"outputs":2,"x":1370,"y":400,"wires":[["b6c3d143.ca2b4"],["b58d7d43.18dd6","b6c3d143.ca2b4"]]},{"id":"b58d7d43.18dd6","type":"api-current-state","z":"4d980637.848cf8","name":"","server":"9b88cb19.5c8db8","version":1,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"sensor.ps4_app_2","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data_ps4app2","override_data":"msg","blockInputOverrides":false,"x":1040,"y":480,"wires":[["435fce72.18fe4"]]},{"id":"435fce72.18fe4","type":"switch","z":"4d980637.848cf8","name":"","property":"data_ps4app1.attributes.media_content_id","propertyType":"msg","rules":[{"t":"eq","v":"data_ps4app2.attributes.media_content_id","vt":"msg"},{"t":"neq","v":"data_ps4app2.attributes.media_content_id","vt":"msg"}],"checkall":"false","repair":false,"outputs":2,"x":1370,"y":480,"wires":[[],["6317a610.3948d8","5b86750a.3c984c"]]},{"id":"5b86750a.3c984c","type":"api-current-state","z":"4d980637.848cf8","name":"","server":"9b88cb19.5c8db8","version":1,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"sensor.ps4_app_3","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data_ps4app3","override_data":"msg","blockInputOverrides":false,"x":1040,"y":560,"wires":[["4ceb1b16.ced0e4"]]},{"id":"4ceb1b16.ced0e4","type":"switch","z":"4d980637.848cf8","name":"","property":"data_ps4app2.attributes.media_content_id","propertyType":"msg","rules":[{"t":"eq","v":"data_app_game.attributes.media_content_id","vt":"msg"},{"t":"eq","v":"data_ps4app3.attributes.media_content_id","vt":"msg"},{"t":"neq","v":"data_ps4app3.attributes.media_content_id","vt":"msg"}],"checkall":"false","repair":false,"outputs":3,"x":1370,"y":560,"wires":[[],[],["5512c102.38a6b","5152fec1.05591"]]},{"id":"5152fec1.05591","type":"api-current-state","z":"4d980637.848cf8","name":"","server":"9b88cb19.5c8db8","version":1,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"sensor.ps4_app_4","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data_ps4app4","override_data":"msg","blockInputOverrides":false,"x":1040,"y":640,"wires":[["31a4caf1.459206"]]},{"id":"31a4caf1.459206","type":"switch","z":"4d980637.848cf8","name":"","property":"data_ps4app3.attributes.media_content_id","propertyType":"msg","rules":[{"t":"eq","v":"data_app_game.attributes.media_content_id","vt":"msg"},{"t":"eq","v":"data_ps4app1.attributes.media_content_id","vt":"msg"},{"t":"eq","v":"data_ps4app4.attributes.media_content_id","vt":"msg"},{"t":"neq","v":"data_ps4app4.attributes.media_content_id","vt":"msg"}],"checkall":"false","repair":false,"outputs":4,"x":1370,"y":640,"wires":[[],[],[],["68848ebd.9b60b"]]},{"id":"e01ccecc.cd89","type":"api-current-state","z":"4d980637.848cf8","name":"","server":"9b88cb19.5c8db8","version":1,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"sensor.ps4_game_1","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data_ps4game1","override_data":"msg","blockInputOverrides":false,"x":1100,"y":80,"wires":[["9ea0be65.d70a3"]]},{"id":"9ea0be65.d70a3","type":"switch","z":"4d980637.848cf8","name":"","property":"data_app_game.attributes.media_content_id","propertyType":"msg","rules":[{"t":"eq","v":"data_ps4game1.attributes.media_content_id","vt":"msg"},{"t":"neq","v":"data_ps4game1.attributes.media_content_id","vt":"msg"}],"checkall":"false","repair":false,"outputs":2,"x":1350,"y":80,"wires":[["882d08da.7cd658"],["500f5cfa.1f2f84","882d08da.7cd658"]]},{"id":"500f5cfa.1f2f84","type":"api-current-state","z":"4d980637.848cf8","name":"","server":"9b88cb19.5c8db8","version":1,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"sensor.ps4_game_2","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data_ps4game2","override_data":"msg","blockInputOverrides":false,"x":1100,"y":160,"wires":[["7ce4c93e.6a39b8"]]},{"id":"7ce4c93e.6a39b8","type":"switch","z":"4d980637.848cf8","name":"","property":"data_ps4game1.attributes.media_content_id","propertyType":"msg","rules":[{"t":"neq","v":"data_ps4game2.attributes.media_content_id","vt":"msg"},{"t":"eq","v":"data_ps4game2.attributes.media_content_id","vt":"msg"}],"checkall":"false","repair":false,"outputs":2,"x":1350,"y":160,"wires":[["93809f99.8a0b2","c8203612.aedd18"],[]]},{"id":"c8203612.aedd18","type":"api-current-state","z":"4d980637.848cf8","name":"","server":"9b88cb19.5c8db8","version":1,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"sensor.ps4_game_3","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data_ps4game3","override_data":"msg","blockInputOverrides":false,"x":1100,"y":220,"wires":[["47adcc65.9c9544"]]},{"id":"47adcc65.9c9544","type":"switch","z":"4d980637.848cf8","name":"","property":"data_ps4game2.attributes.media_content_id","propertyType":"msg","rules":[{"t":"eq","v":"data_app_game.attributes.media_content_id","vt":"msg"},{"t":"eq","v":"data_ps4game3.attributes.media_content_id","vt":"msg"},{"t":"neq","v":"data_ps4game3.attributes.media_content_id","vt":"msg"}],"checkall":"false","repair":false,"outputs":3,"x":1350,"y":220,"wires":[[],[],["70b397b9.67f2e8","dd191948.cb1ca8"]]},{"id":"dd191948.cb1ca8","type":"api-current-state","z":"4d980637.848cf8","name":"","server":"9b88cb19.5c8db8","version":1,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"sensor.ps4_game_4","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data_ps4game4","override_data":"msg","blockInputOverrides":false,"x":1100,"y":280,"wires":[["aac51492.ce59c8"]]},{"id":"aac51492.ce59c8","type":"switch","z":"4d980637.848cf8","name":"","property":"data_ps4game3.attributes.media_content_id","propertyType":"msg","rules":[{"t":"eq","v":"data_app_game.attributes.media_content_id","vt":"msg"},{"t":"eq","v":"data_ps4game1.attributes.media_content_id","vt":"msg"},{"t":"eq","v":"data_ps4game4.attributes.media_content_id","vt":"msg"},{"t":"neq","v":"data_ps4game4.attributes.media_content_id","vt":"msg"}],"checkall":"false","repair":false,"outputs":4,"x":1350,"y":300,"wires":[[],[],[],["939cb4e1.cbfdc8"]]},{"id":"24c561b1.25dc3e","type":"poll-state","z":"4d980637.848cf8","name":"","server":"9b88cb19.5c8db8","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"updateinterval":"60","updateIntervalUnits":"seconds","outputinitially":false,"outputonchanged":false,"entity_id":"media_player.pandoras_box","state_type":"str","halt_if":"playing","halt_if_type":"str","halt_if_compare":"is","outputs":2,"x":170,"y":40,"wires":[["9b9d987.bbddb68"],[]]},{"id":"9b9d987.bbddb68","type":"bigfile reader","z":"4d980637.848cf8","name":"","filename":"/config/.ps4-games.709E290032B2_9077.json","nopayload":true,"flow":"blocks","highWaterMark":16,"encoding":"utf8","format":"utf8","keepEmptyLines":false,"x":420,"y":120,"wires":[["e7f0d62d.9601b8"],[]]},{"id":"4f37366e.ff97f8","type":"split","z":"4d980637.848cf8","name":"","splt":",*","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":690,"y":200,"wires":[["8e6b764d.cb1928"]]},{"id":"e7f0d62d.9601b8","type":"change","z":"4d980637.848cf8","name":"file custom","rules":[{"t":"change","p":"payload","pt":"msg","from":"},","fromt":"str","to":"}},*{","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":530,"y":200,"wires":[["4f37366e.ff97f8"]]},{"id":"8e6b764d.cb1928","type":"json","z":"4d980637.848cf8","name":"","property":"payload","action":"","pretty":false,"x":410,"y":280,"wires":[["a2522c8.73476d"]]},{"id":"a2522c8.73476d","type":"change","z":"4d980637.848cf8","name":"ps4_media_image","rules":[{"t":"move","p":"payload","pt":"msg","to":"ps4_media_image","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":610,"y":280,"wires":[["7e4eeaba.ec9e84"]]},{"id":"7e4eeaba.ec9e84","type":"change","z":"4d980637.848cf8","name":"","rules":[{"t":"move","p":"ps4_media_image","pt":"msg","to":"ps4_media_image.orig","tot":"msg"},{"t":"set","p":"ps4_media_image.media_image_id","pt":"msg","to":"(ps4_media_image.orig.($keys()))","tot":"jsonata"},{"t":"set","p":"ps4_media_image.media_image_url","pt":"msg","to":"(ps4_media_image.orig.*.media_image_url)","tot":"jsonata"},{"t":"set","p":"ps4_media_image.media_content_type","pt":"msg","to":"(ps4_media_image.orig.*.media_content_type)","tot":"jsonata"},{"t":"delete","p":"ps4_media_image.orig","pt":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":440,"y":380,"wires":[["11d2c7bd.8c0b68"]]},{"id":"11d2c7bd.8c0b68","type":"api-current-state","z":"4d980637.848cf8","name":"","server":"9b88cb19.5c8db8","version":1,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"media_player.pandoras_box","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data_app_game","override_data":"msg","blockInputOverrides":false,"x":270,"y":460,"wires":[["79c34b4c.954b34"]]},{"id":"79c34b4c.954b34","type":"switch","z":"4d980637.848cf8","name":"","property":"data_app_game.attributes.media_content_id","propertyType":"msg","rules":[{"t":"eq","v":"ps4_media_image.media_image_id","vt":"msg"}],"checkall":"false","repair":false,"outputs":1,"x":550,"y":460,"wires":[["a99aca48.636358"]]},{"id":"9b88cb19.5c8db8","type":"server","z":"","name":"Home Assistant","legacy":false,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true}]

in short it checks the state of the ps4 (here named pandoras_box) every minute or so, then it picks up the info in the ps4 integration data file .ps4-games.json i dom some formatting and moving the payload around then i pick up the state again from the ps4 (you dont get all the info in the scheduled one as you get in the triggered one) then i clean it again, and then splt it based on app or game and start sending the data to populate the first sensor. in this I always update the firts sensor (ex. ps4_app_1), but if the payload and the ps4_app_1 does not match based on media content id it also sends it to the second sensor to trigger an update to copy the old ps4_app_1 data into ps4_app_2. and so on until it it comes to a ps4_app_x that have the same values as the one before (ps4_app_x-1) used to have.

so thats how it works in semi-short.

if you have any improvements let me know.

sincearly
Fredrik

1 Like

short note. this just creates the sensors and you have to rename the entities in HA.
i am working on the switch part to be able to start a recently used game or app. will post that code also when done

1 Like

Thanks a lot, I’ll experiment with your code :slight_smile: !

1 Like

here is the code for my related switch

      ps4_game_1:
        value_template: "{{ is_state_attr('remote.vardagsrum', 'current_activity', 'Ps4') and is_state('media_player.pandoras_box', 'playing') and ( state_attr('sensor.ps4_game_1', 'media_title') == state_attr('media_player.pandoras_box', 'source')) }}"
        entity_picture_template: "{{ state_attr('sensor.ps4_game_1', 'entity_picture') }}"
        turn_on:
          - service: media_player.select_source
            data:
              entity_id: media_player.pandoras_box
            data_template: {
              source: "{{ state_attr('sensor.ps4_game_1', 'media_title') }}"
            }
        turn_off:
          - service: media_player.media_stop
            entity_id: media_player.pandoras_box
2 Likes