Hello togehter,
I just switched from OpenHAB to HomeAssistant (HassIO on Raspberyy PI4 4GB).
Now I try to adapt my OpenHAB switches etc. to HomeAssistant.
One of the “problems” I’ve run into is a switch to power on / off my synology nas.
It seemed to be quite complicated due to the lack of permissions etc… Also everything i read on did not realy work for me. So I got a bit deeper (first time to use docker etc.)
And found the following Solution for my problem which I will show you below.
- Create a SWITCH for powering on / off.
switch:
- platform: wake_on_lan
name: YOURNAME
mac: YOURMAC
host: YOURIP
turn_off:
service: shell_command.turn_off_YOURNAME
shell_command:
turn_off_YOURNAME: bash /path/to/script/SCRIPTNAME.sh
- Create the script “SCRIPTNAME.sh” for powering off:
#! /bin/bash
sshpass -p "REMOTEPASSWORD" ssh -t REMOTEUSER@REMOTEIP "echo REMOTEPASSWORD | sudo -S poweroff"
- Install the “SSH & Web Terminal” Add-On and deactivate the “protection mode”.
In Terminal run:
docker ps -a
Look for the one with two times “homeassistant” in the name by “Image” and copy the “CONTAINER ID”
-
Run from Terminal:
sudo docker exec -it CONTAINERID /bin/bash
-
Run from Terminal:
apk add sshpass
-
Connect to remote host to verify the fingerprint
ssh -t REMOTEUSER@REMOTEIP
type “yes” to confirm the fingerprint and add your password.
Quit by typing:
exit
- Optional: Turn on “protection mode” again.
You’re done now. The switch will power on your NAS by using WOL and power it off by using sshpass.
NOTE: You have to do step 4 to 6 after every Update!
Hope that will help someone else!
Greetings