Playnite is an amazing game library manager that combines all my pc games (and emulators) in a highly customisable front-end. The best part is the 'Fullscreen'-mode: An interface made for televisions with controller support.

The Goal

I want Home Assistant to know when we are playing a game on our TV so that I can automate the living room accordingly.

Let's take this step-by-step

To start off, I created a input boolean in Home Assistant called 'Game Mode'. Playnite will use this to tell Home Assistant a game is being played.

    name: 'Gamemode'
    initial: off
    icon: 'mdi:xbox-controller'
Home Assistant - configuration.yaml

At the Home Assistant side, this is pretty much it. Next up is using a Powershell Module, written by GitHub user ''. This will allow us to write a script that we can execute every time a game is run trough Playnite. Download the repository and extract the 'Home Assistant' folder to a place where it can sit untouched. This folder contains the 'Powershell Module' we will refer to later.

A PowerShell Module to Control the Home-Assistant home automation software - flemmingss/Home-Assistant-PowerShell-Module

I wrote the following little scripts to toggle 'Game Mode' on and off. Remember to add your own Home Assistant IP and Long Lived Access Tokens to the scripts. You can obtain the token via your profile page. Save these scripts in a folder where it won't accidentally be deleted.

Import-Module "C:\path\to\module"
New-HomeAssistantSession -ip <HOME_ASSISTANT_IP> -port 8123 -token <TOKEN>
Invoke-HomeAssistantService -service input_boolean.turn_on -entity_id input_boolean.gamemode
Import-Module "C:\path\to\module"
New-HomeAssistantSession -ip <HOME_ASSISTANT_IP> -port 8123 -token <TOKEN>
Invoke-HomeAssistantService -service input_boolean.turn_off -entity_id input_boolean.gamemode

The last step is to open Playnite's settings. On the 'Scripts'-tab, add the following lines to turn 'Game Mode' on when starting a game and to turn 'Game Mode' off when you quit playing.

A screenshot of the settings screen in Playnite.
powershell -executionpolicy bypass -File "C:\path\to\gamemode-on.ps1"
Code when starting a game
powershell -executionpolicy bypass -File "C:\path\to\gamemode-off.ps1"
Code when you stop playing a game

Further tweaking

This is a very basic way of connecting Playnite with Home Assistant. I would love to send Home Assistant metadata such as the name of the game we are playing, including the coverart. To be continued...