Use Home Assistant as a Remote Control for Playnite Web

Use Home Assistant as a Remote Control for Playnite Web

Overview

You can connect Playnite Web with Home Assistant, an open source home automation tool, so that you can use Playnite Web to remotely control your games with these actions:

  • Start

  • Stop

  • Restart

  • Install

  • Uninstall

To use Playnite Web as a remote control, you need to install the Playnite Web MQTT plugin so that Playnite can receive MQTT messages. You then need to configure an automation webhook in Home Assistant so that Playnite Web can post an MQTT message to perform an action.

Requirements

Before you begin, make sure you have installed:

Step 1 - Set Up a Webhook Automation in Home Assistant

We recommend setting up one automation for starting, stopping, and restarting games, to avoid errors caused by running multiple automations concurrently.

See the Home Assistant Documentation for setting up a webhook automation trigger.

You must set up the automation to publish MQTT topics that will execute the matching action in Playnite Web to start, stop, or restart a game. The message payload is in JSON format. See below for the MQTT topics and an example payload.

MQTT Control Topics

Replace "game-room-gaming-pc" in the topics to match the Playnite host you want to receive the command, based on the identifier reported by Home Assistant.

Action

Topic

Sample payload

Description

Action

Topic

Sample payload

Description

Start

playnite/{device_name}/request/release/start

{ "releaseId": "PlayniteGuid", "platformId": "PlayniteGuid" }

Starts the release. If it is not installed, the plugin will kick off installation first; starting happens separately once the install completes.

Stop

playnite/{device_name}/request/release/stop

{ "releaseId": "PlayniteGuid", "platformId": "PlayniteGuid" }

Attempts to gracefully stop the running game. If the process cannot be found, the plugin falls back to stopping the parent launcher (Steam, Epic, etc.).

Restart

playnite/{device_name}/request/release/restart

{ "releaseId": "PlayniteGuid", "platformId": "PlayniteGuid" }

Issues a stop request and automatically queues a fresh start after a short delay.

Install

"playnite/{device_name}/request/release/install"

{"releaseId": "PlayniteGuid", "platformId: "PlayniteGuid"}

Installs the game if it's not already installed. Otherwise, does nothing.

Uninstall

"playnite/{device_name}/request/release/uninstall"

{"releaseId": "PlayniteGuid", "platformId: "PlayniteGuid"}

Uninstalls the game. Note that some launchers may require administrator permissions to uninstall games. You may need to run Playnite Web as an administrator.

Request Payload

{ type: "StartReleaseRequested" | "StopReleaseRequested" | "RestartReleaseRequested" payload: { id: string // Release Playnite Web ID playniteId: string // Game Playnite ID title: string coverUrl: string // relative path from PW host platform: { id: string name: string playniteId: string } source { id: string name: string playniteId: string } library: { id: string name: string playniteId: string } } }

Example Automation

This assumes the existence of the following additional entities:

  • rest_command.playnite_web
    This is used to update Playnite Web game run state for platforms that do not update Playnite directly, e.g. PlayStation.
    Requires a token to access the API and stored in the Home Assistant secret.yaml file. See GraphQL Rest Command.

  • input_boolean.is_restarting_game
    This is helpful for when you switch games. In doing so, when the first game turns off, you do not want to treat it as a stop game “activity.” You still want the TV to be on, etc. This toggles helps differentiate between stopping a game because another is about to start versus stopping all games (done with the gaming activity).

This is an example of a Home Assistant automation that can start, stop, and restart your games using Playnite Web:

description: "" mode: restart triggers: - trigger: webhook allowed_methods: - POST local_only: false webhook_id: YOUR_UNIQUE_WEBHOOK_ID_HERE conditions: [] actions: - variables: platform_id: "{{ trigger.json.payload.platform.id }}" platform_name: "{{ trigger.json.payload.platform.name }}" platform_playnite_id: "{{ trigger.json.payload.platform.playniteId }}" release_playnite_id: "{{ trigger.json.payload.playniteId }}" release_id: "{{ trigger.json.payload.id }}" library_playnite_id: "{{ trigger.json.payload.library.playniteId }}" action_type: "{{ trigger.json.type }}" - alias: Choose automation based on type of event choose: - conditions: - alias: Event type is to start a release condition: template value_template: "{{ action_type == \"StartReleaseRequested\" }}" sequence: - alias: Start game choose: - conditions: - condition: template value_template: "{{ platform_name is search(\"PC\") }}" alias: PC sequence: - action: mqtt.publish metadata: {} data: qos: "2" topic: playnite/YOUR_MQTT_DEVICE_NAME/request/release/start payload: >- {"releaseId":"{{release_playnite_id}}","platformId": "{{platform_playnite_id}}"} alias: Start PC game - conditions: - condition: template value_template: "{{ platform_name is search(\"PlayStation\") }}" alias: PlayStation sequence: - action: rest_command.playnite_web metadata: {} data: query: | mutation MyMutation($release: ReleaseInput!) { updateRelease(release: $release) { id } } variables: >- release {{ dict( release = dict( id = release_id, runState = "running" ) ) }} alias: Manually update run state in PW - conditions: - condition: template value_template: "{{ action_type == \"StopReleaseRequested\" }}" alias: Event type is stop release sequence: - alias: Stop game action: mqtt.publish metadata: {} data: qos: "2" topic: playnite/YOUR_MQTT_DEVICE_NAME/request/release/stop payload: >- {"releaseId":"{{release_playnite_id}}","platformId": "{{platform_playnite_id}}"} - action: rest_command.playnite_web metadata: {} data: query: | mutation MyMutation($release: ReleaseInput!) { updateRelease(release: $release) { id } } variables: >- release {{ dict( release = dict( id = release_id, runState = "stopped" ) ) }} alias: Graph update stopped alias: Event type is to stop a release - conditions: - condition: template value_template: "{{ action_type == \"RestartReleaseRequested\" }}" alias: Event type is restart sequence: - action: input_boolean.turn_on metadata: {} target: entity_id: input_boolean.is_restarting_game data: {} - alias: Choose platform choose: - conditions: - condition: template value_template: "{{ platform_name is search(\"PC\") }}" alias: PC sequence: - alias: Restart PC game action: mqtt.publish metadata: {} data: qos: "2" topic: playnite/YOUR_MQTT_DEVICE_NAME/request/release/restart payload: >- {"releaseId":"{{release_playnite_id}}","platformId": "{{platform_playnite_id}}"} - conditions: - alias: PlayStation condition: template value_template: "{{ platform_name is search(\"PlayStation\") }}" sequence: - action: rest_command.playnite_web metadata: {} data: query: | mutation MyMutation($release: ReleaseInput!) { updateRelease(release: $release) { id } } variables: >- release {{ dict( release = dict( id = release_id, runState = "running" ) ) }} alias: Graph update running - delay: hours: 0 minutes: 0 seconds: 10 milliseconds: 0 - action: input_boolean.turn_off metadata: {} target: entity_id: input_boolean.is_restarting_game data: {} alias: Event type is to restart a release

GraphQL Rest Command

Replace {host} with your Playnite host name. You may need to allow your Home Assistant domain/host to access the Graph API via the ALLOWED_ORIGINS environment variable. See Environment Variables for more details.

rest_command: playnite_web: url: "https://{host}/api" method: POST headers: Authorization: !secret playnite_web_token Content-Type: application/json Accept: application/json # Build a proper GraphQL JSON body. Use tojson so quotes/newlines escape correctly. payload: > { "query": {{ query | tojson }}, {% if operation_name is defined and operation_name %} "operationName": {{ operation_name | tojson }}, {% endif %} "variables": {{ variables | tojson }} } timeout: 30

Step 2 - Add the Webhook URL to Playnite Web

Add the webhook URL for your Home Assistant trigger so that Playnite Web can initiate the automation:

  1. Sign in to Playnite Web.

  2. Navigate to Account → Settings.

  3. Provide the same webhook URL that Home Assistant provided you when you set up the automation trigger.

Step 3 - Access Playnite Web to Remotely Control Your Games Library

You must be signed in to Playnite Web in order to trigger your Home Assistant automation.

  1. Sign in to Playnite Web on the device you want to use as a remote control.

  2. Use the game details pane to select an action. It must be an action that you configured Home Assistant to publish the corresponding MQTT topic for.