I made PS5 MQTT/Home Assistant sensor and a flow to get cover from SteamgridDB

I wanted to share this if anyone would like to improve or use this in their HA/Node Red system:


[{"id":"0dcc9ae986cbbb75","type":"subflow","name":"Get SteamGrid Cover for Playstation","info":"","category":"","in":[{"x":60,"y":80,"wires":[{"id":"1f881717285897a7"}]}],"out":[{"x":1780,"y":300,"wires":[{"id":"428c9b67f1b711b3","port":0}]}],"env":[],"meta":{},"color":"#DDAA99"},{"id":"76b522dfcb8a4154","type":"http request","z":"0dcc9ae986cbbb75","name":"SteamGridDB get Image URL","method":"GET","ret":"obj","paytoqs":"ignore","url":"","tls":"","persist":false,"proxy":"","insecureHTTPParser":false,"authType":"","senderr":false,"headers":[],"x":1450,"y":300,"wires":[["428c9b67f1b711b3"]]},{"id":"e2f9e6c080f10680","type":"function","z":"0dcc9ae986cbbb75","name":"Search SteamGridDB for Cover Image","func":"// Your SteamGridDB API key\nconst API_KEY = msg.steamgridapi;\n\n// The game ID you want to search for (can be passed in msg.payload)\nconst gameId = msg.gameid;  // Replace with a default game ID if not provided\n\n// Construct the URL\nconst url = `https://www.steamgriddb.com/api/v2/grids/game/${gameId}`;\n\n// Manually construct the query string\nconst queryParams = [\n    `dimensions=600x900`,\n    `type=static`,\n    `limit=1`\n].join('&');\n\n// Set up the request headers\nmsg.headers = {\n    'Authorization': `Bearer ${API_KEY}`\n};\n\n// Set the request URL with query parameters\nmsg.url = `${url}?${queryParams}`;\n\n// Return the message object to continue the flow\nreturn msg;\n","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1430,"y":260,"wires":[["76b522dfcb8a4154"]]},{"id":"18ca4bc76354203f","type":"change","z":"0dcc9ae986cbbb75","name":"Set Game ID","rules":[{"t":"set","p":"gameid","pt":"msg","to":"payload.data[0].id","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1390,"y":140,"wires":[["0c13391836fbb24d"]]},{"id":"0888acaa564216d5","type":"http request","z":"0dcc9ae986cbbb75","name":"SteamGridRequest for Game ID","method":"GET","ret":"obj","paytoqs":"ignore","url":"","tls":"","persist":false,"proxy":"","insecureHTTPParser":false,"authType":"","senderr":false,"headers":[],"x":1330,"y":100,"wires":[["18ca4bc76354203f"]]},{"id":"24a393b55604cc5c","type":"function","z":"0dcc9ae986cbbb75","name":"Search SteamGridDB by Game Name","func":"// Your SteamGridDB API key\nconst API_KEY = msg.steamgridapi;\n\n// The name of the game to search for (coming from the inject node)\nconst gameName = msg.payload;\n\n// Construct the URL\nconst url = `https://www.steamgriddb.com/api/v2/search/autocomplete/${encodeURIComponent(gameName)}`;\n\n// Set up the request headers\nmsg.headers = {\n    'Authorization': `Bearer ${API_KEY}`\n};\n\n// Set the request URL\nmsg.url = url;\n\n// Return the message object to continue the flow\nreturn msg;\n","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1030,"y":140,"wires":[["0888acaa564216d5"]]},{"id":"8c687a9b3e00dff0","type":"api-current-state","z":"0dcc9ae986cbbb75","name":"PS5 Game Name from Sensor","server":"b3afb4a3.474b18","version":3,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"sensor.ps5_title_name","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"steamgridplaystation","propertyType":"msg","value":"","valueType":"str"},{"property":"gameid","propertyType":"msg","value":"","valueType":"str"}],"for":"0","forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":730,"y":140,"wires":[["24a393b55604cc5c"]]},{"id":"27e01b63b8413176","type":"credentials","z":"0dcc9ae986cbbb75","name":"SteamgridDB Api","props":[{"value":"steamgridapi","type":"msg"}],"x":490,"y":140,"wires":[["8c687a9b3e00dff0"]]},{"id":"428c9b67f1b711b3","type":"change","z":"0dcc9ae986cbbb75","name":"Set Payload","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.data[0].url","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1670,"y":300,"wires":[[]]},{"id":"1f881717285897a7","type":"api-call-service","z":"0dcc9ae986cbbb75","name":"Update PS5 sensors","server":"b3afb4a3.474b18","version":5,"debugenabled":false,"domain":"homeassistant","service":"update_entity","areaId":[],"deviceId":[],"entityId":["sensor.ps5_title_id","sensor.ps5_title_image","sensor.ps5_title_name","sensor.ps5_mxp_activity"],"data":"","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":240,"y":80,"wires":[["4cf383c375788c8a"]]},{"id":"0c13391836fbb24d","type":"delay","z":"0dcc9ae986cbbb75","name":"","pauseType":"delay","timeout":"600","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":1370,"y":200,"wires":[["e2f9e6c080f10680"]]},{"id":"4cf383c375788c8a","type":"ha-wait-until","z":"0dcc9ae986cbbb75","name":"Wait Until PS5 is Playing","server":"b3afb4a3.474b18","version":2,"outputs":1,"entityId":"sensor.ps5_mxp_activity","entityIdFilterType":"exact","property":"state","comparator":"is","value":"playing","valueType":"str","timeout":"0","timeoutType":"num","timeoutUnits":"seconds","checkCurrentState":true,"blockInputOverrides":true,"outputProperties":[],"entityLocation":"data","entityLocationType":"none","x":250,"y":320,"wires":[["27e01b63b8413176"]]},{"id":"b3afb4a3.474b18","type":"server","name":"Home Assistant","addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"","connectionDelay":true,"cacheJson":true,"heartbeat":false,"heartbeatInterval":"25","areaSelector":"friendlyName","deviceSelector":"friendlyName","entitySelector":"id","statusSeparator":"","statusYear":"hidden","statusMonth":"hidden","statusDay":"numeric","statusHourCycle":"h12","statusTimeFormat":"h:m","enableGlobalContextStore":true},{"id":"79af261c55048c30","type":"subflow:0dcc9ae986cbbb75","z":"e95326a6e4ed5bcf","g":"9f5d1ca132e688ed","name":"","x":470,"y":780,"wires":[["89ce2be2c3753931"]]}]

Basically, with the HA PS5Mqtt addon you can get sensor values from your Playstation 5. You can template out some attribute sensors for Game Name, Game ID (Playstation, not SteamgridDB), etc. I then had it so whenever the PS5 turns on, it will grab the game name attribute from the activity sensor, then go into SteamGridDB and search for Game ID by Title, then pull that game id into a similar api query for the Game cover. You can set query params to find cover size or style (You need the SteamgridDB api key, so an account is necessary). I then get the payload result and return it back into a home assistant sensor to do with it as you please.

For my example I created a generic camera which when the ps5 is off will show a static image, and when the MQTT is detected on the camera will load from this flow to a steam grid db cover.

Any improvements are welcome as this is made by a guy who is not a programmer by trade.