Purpose: To be able to start and stop Plex through Home Assistant so that it is not running all the time (save energy).
- Set the Plex server so that it is set to WoL.
- Allow remote shutdown of the Plex server
- Add a wake and shutdown button to HA.
- ToDo : When Smart Hub TV tries to start Plex, start the plex server
Based on input from Guide: Start up and shut down remote linux PC using Home Assistant – Creating Smart Home
show_icon: true
type: button
entity: switch.remotepc_2
icon: phu:plex
show_state: true
icon_height: 100px
name: Press once and wait 2 mins
On Plex server
sudo adduser homeassistant
sudo visudo
homeassistant ALL=(ALL) NOPASSWD: /sbin/poweroff, /sbin/reboot, /sbin/shutdown
mkdir /config/ssh_keys
ssh-keygen -t rsa -f /config/ssh_keys/id_rsa_homeassistant
ssh-copy-id -i /config/ssh_keys/id_rsa_homeassistant.pub homeassistant@plex_hostname
ssh -i /config/ssh_keys/id_rsa_homeassistant homeassistant@plex_hostname
Home Assistant Server
turn_off_plex: "ssh -i /config/ssh_keys/id_rsa_homeassistant -o 'StrictHostKeyChecking=no' homeassistant@plex_hostname sudo shutdown -h now"
shell_command: !include shell_commands.yaml
switch:
- platform: wake_on_lan
name: plex
host: <<plex server ip>>
mac: <<plex server mac>>
turn_off:
service: shell_command.turn_off_plex
turn_off_plex: "ssh -i /config/ssh_keys/id_rsa_homeassistant -o 'StrictHostKeyChecking=no' homeassistant@<<plex ip address>> sudo shutdown -h now"```
