In this post, I will show you how you can control your PS4 with home assistant and turn it on with a Google Mini.
The Sony Playstation 4 integration into Home Assistant allows you to control your playstation with various actions such as turning on / off launching games. With the creation of a script within HA we are able to expose a series of commands to the Google Home app.
Table of Contents
New to Home Assistant?
If you are just getting started with home assistant I suggest you enroll in my Free Home Assistant Course !
Before Starting
- Download the PS4 second screen app on your smartphone.
- Turn on your PS4
- Ensure that your PS4 remains connected to the LAN while in rest mode, in this way HA will be able to communicate to it.
How to setup PS4 in Home Assistant
In home assistant navigate to Configuration –> Integration and search for Playstation.
In the PS4 2nd Screen App, refresh devices and select ‘Home-Assistant’
Now select either Auto-discovery or manual IP address, I selected manual IP as my PS4 has a static IP address.
The PIN you will find in your PS4, now in your PS4 go to:
Settings –> Mobile App Connection Settings and select ‘Add Device’
Now enter the PIN displayed into Home Assistant
Select your region.
These regions at the time of writing are not included:
China, Japan, Philippines, Serbia, Ukraine, Vietnam
Press Submit and assign PS4 to a room.
Now your PS4 has been added as an entity in home assistant: media_player.playstation_4.
You can use any service that is linked with media_player, such as media_player.turn_on and media_player.turn_off.
To send specific commands to PS4 you can use ps4.send_command specifying the entity id and command
List of commands are:
ps |
PS (PlayStation) |
ps_hold |
PS Hold/Long Press |
option |
Option |
enter |
Enter |
back |
Back |
up |
Swipe Up |
down |
Swipe Down |
left |
Swipe Left |
right |
Swipe Right |
As you might have noticed the service is missing the traditional four PS4 commands, I will be using an harmony hub to workaround this.
Script
Before you run this script you will need to do the following:
- Set your PS4 into rest mode
This script does the following things:
- Turns on ps4
- Turn my Living Room 1 off
- Turn my Living room lamp on
Turn on my Harmony PS4 Activity
- A 35 seconds delay before the next step.
- Press the PS button to login, as soon as the PS4 booted into an idle state.
- Turns the Living Room 2 red
- Launch a game called Dead by Daylight
play_dead_by_daylight:
alias: Play Dead By Daylight
sequence:
# Turn PS4 on
- data: {}
entity_id: media_player.playstation_4
service: media_player.turn_on
# Turn Living Room 1 Off
- service: light.turn_off
entity_id: light.living_1
# Turn Lamp ON
- service: light.turn_on
entity_id: light.hue_white_candle_1
- service: light.turn_on
entity_id: light.hue_white_candle_2
# Turn harmony to PS4
- service: remote.turn_on
entity_id: remote.living_room
data:
activity: 'Play PS4'
# 35 seconds delay
- delay: 35
# Send PS command
- data:
command: ps
entity_id: media_player.playstation_4
service: ps4.send_command
# Set Living Room 2 to Red
- service: light.toggle
data:
color_name: red
entity_id: light.living_2
entity_id: light.living_2
# Start Dead By Daylight
- data:
source: 'Dead by Daylight: Special Edition'
entity_id: media_player.playstation_4
service: media_player.select_source
Google Home App
In order for you Google Home to interact with Home Assistant you have two routes:
- Manual configuration
- Using Nabu Casa cloud service (this is the option I’m using)
To link the google home app with home assistant do the following:
- Press + button and set up device
- Tap on “Have something already set up”
- Search for “Home Assistant Cloud by Nabu Casa”
- Login with your Nabu Casa Account
- All devices are added by default and you can assign rooms to them.
Now if you wanted to not expose certain domains or certain entities you can add this code into your configuration.yaml
cloud:
google_actions:
filter:
include_entities:
- media_player.playstation_4
include_domains:
- script
The snippet above only includes the playstation 4 media player and all of the scripts. Bear in mind that the scripts in the google home app do not appear in the home section.
To find scripts navigate to the following location:
Press on the round button with your initial –> Assistant Settings –> Home Control (scroll down) –> Scenes
Now you can try saying:
“Hey Google, turn playstation 4 on”
“Hey Google, turn playstation 4 off”
“Hey Google, activate play dead by daylight”
Home Assistant Dashboard (Lovelace)
Before adding the PS4 to your dashboard you will need two custom components which you can get from HACS (Home Assistant Community Store)
Button-card: https://github.com/custom-cards/button-card#installation-and-tracking-with-hacs
Mini-Media-Player: https://github.com/kalkih/mini-media-player
Now you will need to find out a few things:
- Entity ID of playstation in home assistant.
- Device ID of remote within the harmony configuration file (harmony_xxx.conf)
For part of this I’m using a Harmony Hub to send specific commands to PS4
card:
cards:
- artwork: full-cover
entity: media_player.playstation_4
hide:
icon: true
power: true
progress: true
source: true
volume: true
type: 'custom:mini-media-player'
- cards:
- color: '#003791'
color_type: card
icon: 'mdi:playstation'
type: 'custom:button-card'
tap_action:
action: call-service
service: remote.send_command
service_data:
command: PS
device: 28803486
entity_id: remote.living_room
- color: '#91b8e3'
color_type: icon
icon: 'mdi:window-close'
type: 'custom:button-card'
tap_action:
action: call-service
service: remote.send_command
service_data:
command: Cross
device: 28803486
entity_id: remote.living_room
- color: '#1fd0c8'
color_type: icon
icon: 'mdi:triangle-outline'
tap_action:
action: call-service
service: remote.send_command
service_data:
command: Triangle
device: 28803486
entity_id: remote.living_room
type: 'custom:button-card'
action: service
- color: '#d4aad2'
color_type: icon
icon: 'mdi:square-outline'
tap_action:
action: call-service
service: remote.send_command
service_data:
command: Square
device: 28803486
entity_id: remote.living_room
type: 'custom:button-card'
- color: '#f57b8a'
color_type: icon
icon: 'mdi:circle-outline'
tap_action:
action: call-service
service: remote.send_command
service_data:
command: Circle
device: 28803486
entity_id: remote.living_room
type: 'custom:button-card'
type: horizontal-stack
type: vertical-stack
conditions:
- entity: switch.ps4
state_not: 'off'
type: conditional
Additional Resources
https://www.home-assistant.io/integrations/ps4
https://www.home-assistant.io/integrations/script
https://www.home-assistant.io/docs/scripts/#delay
https://www.nabucasa.com/config/google_assistant/
https://www.home-assistant.io/integrations/google_assistant/
https://www.home-assistant.io/integrations/harmony/
https://community.yio-remote.com/t/yio-remote-with-logitech-harmony-hub-and-home-assistant/624