Run bash script for switch on turn_off

Hello Community,

sorry, but this flood of information on getting started with Home Assistant is overwhelming me a bit… I promise I’ll continue to read up on it… But get a little desperate here too.

Where do I have a mistake here? Am I thinking too simplistically?

switch:
 - platform: wake_on_lan
    mac: XX:XX:XX:XX:XX:XX
    name: "NAS"
    host: 10.10.1.100
    turn_off:
      service: shell_command.shutdown_nas 

# Exposes service shell_command.shutdown_nas
shell_command:
  shutdown_nas: bash /config/nas_shutdown.sh

nas_shutdown.sh (saved in /config/)

#!/bin/bash

ssh -l username 10.10.1.100 "sudo shutdown"

i’ve done the ssh-key-stuff from inside the haas container… so sudo is not the problem.

Thanks

Should be switch:, but besides that, seems fine.

EDIT: Well, assuming the script actually runs ok in the HA container.

changed it…

from the terminal it works…

running

bash nas_shutdown.sh

What terminal? You need to go inside the container to do a proper test.
Assuming you use keys, you’ll at lease need ssh -i to point to the private key to use

the script runs fine from the “Terminal & SSH-Addon” but not by clickin the switch.

i’m using a supervised docker installation on a rpi4 and installed the “Terminal & SSH” Add-on…

but now i get an error

Error running command: `bash /config/nas_shutdown.sh`, return code: 255

thx for the assistance!

edit: but as u said you’re right with “-i” for the key … i’m tryin that now.

Random ssh of mine

ssh -4 -i /root/.ssh/id_rsa -o ConnectTimeout=3 -o StrictHostKeyChecking=no me@hostlan 'dmesg -T --level=err | tail -n 1' || echo 'ERROR: cannot connect'

thanks, at first i thought it worked… but nope :frowning:

ssh -4 -i /root/.ssh/id_rsa -o ConnectTimeout=3 -o StrictHostKeyChecking=no [email protected] "sudo shutdown"

on home (iOS device), i can turn off the switch for it… but nothing happens, on the dashboard it just swipe back to on position…

still got the return Code 255 under logs for a shell.command logger entry

runnin a test right now, but i think my Synology NAS blocked the rpi, he’s now on the allow list

from “terminal & ssh” the command is working fine…
but with the switch its still return code 255

bash /config/nas_shutdown.sh

also workin well inside “terminal & ssh”

my last try… but nope…

Try the ssh command directly in HassOS terminal. The 255 is generic, afaik.
You’ll get detailed errors in terminal.

BTW, you don’t need to go through a script. I use my ssh commands directly in the shell_command.