maurizio53
(Maurizio Fabiani)
December 13, 2018, 11:31am
1
I get this error after creating a shell command:
Error running command: `sudo /home/homeassistant/.homeassistant/./alexa_remote_control.sh -e automation:"Alexa, sono a casa" -d "Echo Spot"`, return code: 1
NoneType: None
The command created is:
sono_a_casa: '/usr/bin/sudo /home/homeassistant/.homeassistant/./alexa_remote_control.sh -e automation:"sono a casa"'
How to get the command running ?
Hi, not an expert here but maybe I’m lucky. Two ideas:
1.- Have you tried running the command from the command-line to see if it works?
2.- What is that single dot between homeassistant and alexa_remote_control.sh? It’s strange, isn’t it?
Are you able to run the script without sudo ?
If you run it with sudo maybe you are prompted to give a password and it fails.
maurizio53
(Maurizio Fabiani)
December 13, 2018, 4:10pm
5
Hmmm… good question… without sudo i am not able to run it… It says permission denied…
But running from the terminale it works without asking the password.
So what to do?
gpbenton
(Graham)
December 13, 2018, 4:18pm
6
By default, the homeassistant user does not have sudo access. You can give it sudo access, but this greatly increases your security risk if you are allowing access to the internet.
If want to go ahead despite this warning, use the debian wiki page, starting at Creating new user from commandline
https://wiki.debian.org/sudo
You should also use the next section to restrict sudo use to the specific commands you want to use.
maurizio53
(Maurizio Fabiani)
December 13, 2018, 4:22pm
7
So how to run such script in a shell_command?
I see the script belongs to root…
I would change the ownership of the script to homeassistant user. Something like this:
$ sudo chown homeassistant:homeassistant alexa_remote_control.sh
But I really don’t know the security implications of doing this.
maurizio53
(Maurizio Fabiani)
December 13, 2018, 4:28pm
9
I already did it, but running after this from the terminal, it fails always with “permission denied”
-rwxr--r-- 1 homeassistant homeassistant 32687 dic 13 17:14 alexa_remote_control.sh
Ok, then it must be something inside that alexa_remote_control.sh file that needs some privileges.
I have another idea but not 100% sure it is going to work, so forgive me for making you loose your time. You can also wait for someone smarter.
Create this file /etc/sudoers.d/020_homeassistant_hassbian-scripts with this:
homeassistant ALL=(ALL) NOPASSWD: /home/homeassistant/.homeassistant/alexa_remote_control.sh
Basically it is saying that homeassistant user can run the script and no password will be asked for.
Disclaimer: I don’t know 100% the consequences in terms of security issues when doing this. You’ve been warned.
maurizio53
(Maurizio Fabiani)
December 13, 2018, 4:44pm
11
Ok thanks, i’ll do it as soon as i’ll be home and see what happens…
gpbenton
(Graham)
December 13, 2018, 4:45pm
12
You also need to add homeassistant user to the sudo group
1 Like
maurizio53
(Maurizio Fabiani)
December 13, 2018, 4:46pm
13
How to do it… not a linux GURU here…
I suggest you reading this
@gpbenton I thought it wasn’t necessary to include it in the sudo group. Are you sure?
@maurizio53 If you rely on what an anonymous says in the internet this is what you need to include homeassistant to sudo group:
sudo usermod -a -G sudo homeassistant
gpbenton
(Graham)
December 13, 2018, 4:58pm
15
I was looking for a better link, and it seems on a raspberry pi (as opposed to debian) you may not have to. See the sudoers
section of this page https://www.raspberrypi.org/documentation/linux/usage/users.md
maurizio53
(Maurizio Fabiani)
December 13, 2018, 5:01pm
16
Ok, and after that how to run the script in the shell_command?
Sorry, I’m not sure I understand your question. Are you asking how to run the script? In an automation?
maurizio53
(Maurizio Fabiani)
December 13, 2018, 5:08pm
18
Yes, i have this automation:
- alias: 'Sono a Casa'
initial_state: 'on'
trigger:
platform: state
entity_id: binary_sensor.motion_sensor_158d0001ddac9e
to: 'on'
condition:
- condition: time
after: '11:00'
before: '15:00'
action:
service: script.turn_on
entity_id: script.sono_a_casa
And the script is:
sono_a_casa:
alias: Sono a Casa
sequence:
- service: shell_command.sono_a_casa