Hello,
I am trying to configure some light switches using the command line and python scripts, but I am missing something, because the commands within HA are not working.
I am running HassOS 2.12 on a RPi3.
So far in the configuration.yaml file I have created a light switch (ON/OFF) as command line:
switch:
- platform: command_line
switches:
kitchen_light_1:
command_on: "/usr/bin/sudo /usr/bin/python3 /root/config/switchLight_Kitchen_1_On.py"
command_off: "/usr/bin/sudo /usr/bin/python3 /root/config/switchLight_Kitchen_1_Off.py"
and I have created the scripts to switch the light (e.g. ON):
#!/usr/bin/env python3
import serial
ser = serial.Serial(port='/dev/ttyACM0', baudrate=9600, bytesize=8, parity='N', stopbits=1)
ser.write(('is000FFF000FFF'+'\n').encode())
ser.close()
I have then created a switch card using the switch defined above, but when triggered I always get an error: Command failed: /usr/bin/sudo /usr/bin/python3 /root/config/switchLight_Kitchen_1_On.py
If I go to the Terminal (I use the add-on “SSH & Web Terminal”) and I run the same py script the switch is working and the light is going on.
The script is using pyserial (“import serial” is used in the python script).
I had initially installed the library using the command “pip3 install pyserial”.
I have thought of two possible causes:
- the scripts cannot be run by the HA user, but I have checked the permissions and it looks OK
- the serial library is not seen by HA when launching the commands, although it is visible in the Terminal
In the second case, how can I check whether HA can access the pyserial library?
I could not find any add-on with such library online.
Thanks for helping.