hanninen
(Magnus Hannninen)
February 6, 2017, 9:45pm
1
Hi
I’m trying to control some 433mHz switches (Mercury 350.115).
After alot of trial and error I have manage to create a c++ program that I can control the switches through shh.
$ sudo /home/hass/./myMercurySwitch 2 on
This works fine.
Now I want to use this in home assistant.
In my configuration.yaml I have this:
switch:
platform: command_line
switches:
window_light:
command_on: '/home/hass/./myMercurySwitch 2 on'
command_off: '/home/hass/./myMercurySwitch 2 off'
This gives me “Command failed” in the home assistants log.
I think it has to do with that HA don’t allow me to use sudo, or that user hass are not allowed to execute the file myMercurySwitch. Trying to execute the file as hass gives me the error “can’t open /dev/mem”.
What permissions do I need to change to get this to work?
Or is command_line not the way to do it?
rpitera
(Robert Pitera)
February 6, 2017, 10:18pm
3
You can add the HA user to sudoers following the instructions in this thread:
Add your user hass to the sudoers list.
Edit the sudoers file
sudo nano /etc/sudoers
and add the following at the bottom:
hass ALL=(ALL) NOPASSWD: ALL
then in your shell_command add sudo in front of the player:
shell_command:
play_sound: sudo omxplayer /usr/share/scratch/Media/Sounds/Instruments/Trumpet2.wav
Also, sometimes certain accounts don’t have access to all the path environment variables, so probably best to make sure by adding the full path to omxplayer:
shell_command:
p…
Note that the HA user name may be hass or homeassistant depending on your installation method.
1 Like
hanninen
(Magnus Hannninen)
February 7, 2017, 12:18am
4
Thanks
I added both ‘hass’ and ‘homeassistant’ to sudoers
$ sudo visudo
hass ALL=(ALL) NOPASSWD: ALL
homeassistant ALL=(ALL) NOPASSWD: ALL
Then I added 'sudo ’ to the configuration.yalm.
switch:
platform: command_line
switches:
window_light:
command_on: ‘sudo /home/hass/./myMercurySwitch 2 on’
command_off: ‘sudo /home/hass/./myMercurySwitch 2 off’
This works now.
Many thanks
1 Like