I’m using hass.io installed on a RPI3 to control kodi media center and can’t get shell commands to work.
I set up my ssh keys and created a script called kodivapor.sh:
#!/bin/bash
# robottv = 192.168.0.30
/usr/bin/ssh -i "/config/.ssh/id_rsa" [email protected] '/usr/bin/kodi-send --action="Slideshow(/storage/videos/vaporwave/,[,recursive,random,])"'
# loungeboombox = 192.168.0.31
/usr/bin/ssh -i "/config/.ssh/id_rsa" [email protected] '/usr/bin/kodi-send --action="Slideshow(/storage/videos/vaporwave/,[,recursive,random,])"'
This runs from the command line without any prompts just fine. But it won’t launch from the web interface.
Error in the home-assistant.log
2018-07-01 19:43:11 ERROR (MainThread) [homeassistant.components.shell_command] Error running command: /config/shellscripts/kodivapor.sh
, return code: 255
NoneType: None
configuration.yaml
shell_command:
vaporwave: "/config/shellscripts/kodivapor.sh"
scripts.yaml
'vaporparty':
alias: vapor_party
sequence:
- alias: vapor party test
service: shell_command.vaporwave
What am I missing? Is it because when I ssh in I’m running as root, but the web interface runs as a different user? I’ve seen others say use the homeassistant user, but that one doesn’t exist on my system.
Alec
(Alec Rust)
January 16, 2019, 7:15pm
2
I have the same issue. Following command works fine when run manually from my Pi (Hass.io ):
ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i /root/.ssh/id_rsa [email protected] source scripts/evening_shutdown.sh
But if HA runs this via a shell_command
I get this error:
Error running command: `ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i /root/.ssh/id_rsa [email protected] source scripts/evening_shutdown.sh`, return code: 255
NoneType: None
finity
January 17, 2019, 5:26pm
3
you need to check your permissions on that shell command. if the homeassistant user doesn’t have execute permissions you will get an error.
Alec
(Alec Rust)
January 26, 2019, 12:01pm
4
@finity thanks for your reply. Won’t the user be root
as specified in the command? Or are you saying there’s a separate homeassistant
user?
I don’t see why it would work when run directly from the Pi’s shell but not the same command in a HA script.
with Hass.io try warping the commands in a python script see
NOTE This script is no longer required. All options now supported in @ keatontaylor custom component
I have been fighting to run the https://loetzimmer.de/patches/alexa_remote_control.sh in Hass.io
After some time I think I have a workable solution
I have created a new post as the original post is enormous and the information is now difficult to extract
This solution is for Hass.io and It will be a long post so “bare with me”
Before I begin . I would recommend anybody usi…
(long post look for local scripts)
Had real problems running shell scripts in Hass.io , may help
Alec
(Alec Rust)
January 28, 2019, 7:29pm
7
Thanks @lonebaggie . I created a /config/shutdown_wrapper.py
script that runs the command:
import subprocess
import sys
params = sys.argv[1]
cmd = "ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i /root/.ssh/id_rsa [email protected] 'sh /Users/alec/scripts/evening_shutdown.sh'"
x = subprocess.check_output(cmd, shell=True)
print(x.decode("utf-8"))
And call it from my shutdown_macbook
shell command:
shell_command:
shutdown_macbook: 'python3 /config/shutdown_wrapper.py'
But I get a generic error:
Error running command: `python3 /config/shutdown_wrapper.py`, return code: 1
NoneType: None
I notice python3
isn’t available when I SSH into my Pi to test this command manually. I assume it’s available in this “HA shell command” context though?
Anyway all seems a bit much just to run an SSH command from Hass.io !
I know nightmare . Your not passing any parameters so get rid of the params = line
not at my HA at the moment will check tomorrow for correct syntax to see if possible
Alec
(Alec Rust)
January 29, 2019, 9:01pm
9
Solved this, turns out the problem was the shutdown command within my evening_shutdown.sh
script
I had this (the -P
caused the error):
sudo shutdown -P now
Instead of this:
sudo shutdown -h now
But in fact, since my Mac stays logged in when I leave it (a limitation of the following approach) I use this now to shut down more gracefully:
osascript -e 'tell app "System Events" to shut down'
Not only that, but it works outside the Python script so now my Shutdown MacBook shell command is just:
shell_command:
shutdown_macbook: !secret shell_shutdown_macbook
The command in secrets.yaml
:
shell_shutdown_macbook: ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i /root/.ssh/id_rsa [email protected] 'sh /Users/alec/scripts/evening_shutdown.sh'
Thanks for your help!
1 Like