Hello everyone,
I am currently running Home Assistant OS 6.1 with core-2021.6.6 on a Raspberry Pi 4. The only user present on my HomeAssistant installation is “root” as installed by Home Assistant OS. To remotely start and stop my projector I decided to use a Command Line Switch. I created two shell scripts inside the config-directory using the Terminal & SSH Add-On installed via Supervisor and made them executable from command line:
Shell script for on command (/config/shell_commands/projejctor_on.sh)
#!/bin/bash
echo "start" >> /tmp/test.txt
# Login twice - only after the second attempt the correct cookie is retrieved
/usr/bin/curl -X POST -d "***" -s -S --cookie-jar /tmp/cookie http://projector/tgi/login.tgi > /dev/null
echo "1" >> /tmp/test.txt
/usr/bin/curl -X POST -d "***" -s -S --cookie-jar /tmp/cookie http://projector/tgi/login.tgi > /dev/null
echo "2" >> /tmp/test.txt
/usr/bin/curl -X POST -d "pwr=Power ON" -s -S --cookie /tmp/cookie http://projector/tgi/control.tgi > /dev/null
echo "3" >> /tmp/test.txt
# logout again and delete the cookie
/usr/bin/curl -s -S --cookie /tmp/cookie http://projector/tgi/logout.tgi > /dev/null
echo "4" >> /tmp/test.txt
/bin/rm /tmp/cookie
echo "end" >> /tmp/test.txt
Both scripts can be run from the command line via the SSH Add-On and execute properly. I subsequently added the following lines to my configuration.yaml:
switch:
- platform: command_line
switches:
projector:
command_on: "/config/shell_commands/projector_on.sh"
command_off: "/config/shell_commands/projector_off.sh"
Afterwards I restarted Home Assistant. Turning this switch on, leaves me with the following two logs:
Timout & Command Failed
Logger: homeassistant.components.command_line
Source: components/command_line/__init__.py:26
Integration: command_line (documentation, issues)
First occurred: 21:20:45 (1 occurrences)
Last logged: 21:20:45
Timeout for command: /config/shell_commands/projector_on.sh
Logger: homeassistant.components.command_line.switch
Source: components/command_line/switch.py:109
Integration: command_line (documentation, issues)
First occurred: 21:20:45 (1 occurrences)
Last logged: 21:20:45
Command failed: /config/shell_commands/projector_on.sh
Increasing the log-level (homeassistant.components.command_line) to debug also does not render more output (I checked /config/home-assistant.log directly via ssh).
When I reconfigure my switch to the following
switch:
- platform: command_line
switches:
kitchen_light:
command_on: "echo 'test' >> /tmp/test.txt"
command_off: "rm /tmp/test.txt"
I don’t see any errors inside the logs, but the txt file is not created either.
Only when I create that txt file inside of the /config/shell_commands folder, I see that file from within my SSH shell. I can confirm that (by make the switch echo whoami) that the user running these command line switches is “root” and that he can see the /tmp directory. Funny enough, listing stuff inside the tmp directory inside “that switch environment” shows me my formerly created test.txt and the cookie file (that I both cannot see via SSH).
The /tmp/test.txt files inside the switch environment contains “start 1 2” and some “test” spammed into - so generally some parts of the script seem to run. Checking the content of the cookie-jar shows that curl must have at least run, but somehow does not retrieve the cookies properly:
# Netscape HTTP Cookie File
# https://curl.se/docs/http-cookies.html
# This file was generated by libcurl! Edit at your own risk.
Does anyone know what is going on here? In which environment does my command get executed? What file-system is that? And what is happening to my first curls? Why are they not properly retrieving the cookie? Any help would be greatly appreciated!