Error in shell_command

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?

  1. Yes, i tried and the script is working as expected.
  2. I need it to run the script… if i don’t use it the script doesn’t run. I am not a linux guru so i only read docs about 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.

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?

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.

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.

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.

Ok thanks, i’ll do it as soon as i’ll be home and see what happens…

You also need to add homeassistant user to the sudo group

1 Like

How to do it… not a linux GURU here… :joy:

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 :joy: this is what you need to include homeassistant to sudo group:

sudo usermod -a -G sudo homeassistant

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

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?

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