Switchmate Script issues

I think I am one step away from getting this to work for my self.

This is where I am at.

I followed the steps here:

I am at the point where I can run the following after I ssh into my raspberry pi3:
/switchmate/switchmate.py c8:a8:c0:49:b3:74 none switch off
And it works!

However after I put following in the config file:

  • platform: command_line
    command_on: python3 /switchmate/switchmate.py c8:a8:c0:49:b3:74 none switch off
    command_off: python3 /switchmate/switchmate.py c8:a8:c0:49:b3:74 none switch on

I get the following when I attempt to ‘flip the switch’:
Command failed: python3 /switchmate/switchmate.py c8:a8:c0:49:b3:74 none switch off
10:00 AM components/switch/command_line.py (ERROR)

Is it because I am running python under python ? XD

have you tried putting ‘single’ quotes or “double quotes” around the command? I had issues with command line switches in the past until I realized that quotes help it send the entire command at once.

Nope failed with both single and double quotes

Maybe try

/bin/bash -c "python3 ..."

command failed: /bin/bash -c “python3 /switchmate/switchmate.py c8:a8:c0:49:b3:74 none switch on”
8:59 AM components/switch/command_line.py (ERROR)

Maybe there’s something more basic wrong. I would try something extremely simple like the command “true”. If that fails then it’s not the command.

Also, when you tried logging in and running the command, 1) you probably ran it as user pi and not homeassistant, and 2) you ran it differently. I’d try logging in, then “sudo su -s /bin/bash homeassistant”, and trying the exact same command (“python3 …”) that you’re trying within HA.

OK what the issue appears to be is that I need to added the modules needed for this python script to the virtual homeassistant environment. I installed HomeAssistant over raspbian with the alternative install procedure.

When I try to run the scripts in the virtual python environment, I got the following:

(homeassistant) homeassistant@piHass:/srv/homeassistant $ /switchmate/switchmate.py c8:a8:c0:49:b3:74 none switch off
Traceback (most recent call last):
File “/switchmate/switchmate.py”, line 25, in
from docopt import docopt
ImportError: No module named ‘docopt’

This is what fixed it for me:
sudo su -s /bin/bash homeassistant
cd /srv/homeassistant
python3 -m venv .
source bin/activate
pip3 install tabulate
pip3 install bluepy
pip3 install docopt

1 Like