I want to unmount my Hard Drive (which is connected to my Raspberry Pi) with a simple shell_command through Home Assistant:
umount /dev/sda1
It works perfectly if I do it through terminal and it also works perfectly if I change to virtual enviroment in HASS with source /srv/hass/hass_venv/bin/activate and run same command there.
It doesn’t work through script (unmount), it doesn’t work through in single or double quotes, with eject or umount. There is no error in log, nothing happens.
Any help would be really appreciated, I don’t know what I am missing.
I don’t need to mount my HDD through HA, I just want to unmount it through HA.
To explain. This is and external HDD with external power supply, it’s connected directly to my Pi.
I want to create an automation that does the following things:
Movie TIme automation:
Turns on the RF outlet
With this HDD start and mounts on my Pi by itself
Starts KODI on my Pi
Turns on Hyperion TV Ambilight
Turns on my TV
Selects correct HDMI source
Turns off the lights
etc.
Movie time over automation:
Closes KODI
Unmounts HDD - my problem
Switches off RF outlet (this is where HDD power supply is connected)
etc
I’ve manage to integrate everything except unmounting HDD…and launching KODI through shell_commands is also a problem, but it at least works in a way.
I cannot simply turn off RF outlet before unmounting, because there could be data corruption on HDD.
I forgot, I added the hass user to the sudousers file (that’s not the right now, but I can’t login right now to check). Otherwise sudo is asking for a password I think.
I tried to set umount commands on command_line switches as command_on and commands defenitely fail (with or without sudo). This time they are properly logged:
no it’s a sudo file that allows hass to use sudo without challenging for a password. Look at the man pages for sudo it should point you there. If not, I’ll be able to check my system in a couple of hours and can reply with the information.
actually try the following.
I’m doing it logged in as pi not as hass. that way I don’t have to enter the sudo password when I create the file we need.
cd /etc/sudoers.d
create a file named 010_hass-nopasswd you’ll need to use sudo to do this.
sudo (whatever editor you like) 010_hass-nopasswd
in the file put the following line
hass ALL=(ALL) NOPASSWD: ALL
I think that should do it and you won’t be prompted for the password under hass anymore.
Thank you @turboc for your help. I added hass to sudoers and now everything is working!
@rpitera Thank you for pointing me to github discussion. I agree that adding hass to sudoers is not the right way to solve the problem, I don’t know any other way to do it. Also, all future commands with sudo wil now work as well, I won’t have to deal with specific problems and permissions every time.
SmartValley,
For home use that is probably fine. But in the business world, using sudo like we have set it up allows normally unauthorized users to install applications that could impact everyone on the system, instead of just being limited to their account.
I think the best solution will be for someone with a lot more unix/linux and HA knowledge than me, to figure out how to let hass run apps in needs to run without having to use sudo, but also making it so that we can work in the system without having to go into the hass user to do everything. I don’t know how to do it, like it said, it will take someone with a lot more unix/linux and HA knowledge than me to pull it off.
I had to point you to that discussion or I wouldn’t be doing my job as a mod. As long as you understand the implications, then the evaluation of the risk is up to you - and BTW, not judging! I just wanted to make sure that I made you aware of it.
I originally did a similar thing with perms on my certificates until I could find a proper solution so I know where you’re coming from.