If you installed hass.io, i assume (i’m not using it) there is no user pi, and so there is no directory /home/pi.
The question is, what should your switch do?
It’s not buggy… it’s just those commands are executed in the Home Assistant container and those directories /usr/bin/touch and home/pi are not mapped or available in the container.
Having spent a week screwing around with a shell script, the easiest way I found to debug what is and isn’t available and what you can and cannot use is to open a console in the Home Assistant container (use the Portainer addon) and execute your commands in there. If they work there, they will work in Home Assistant shell_command/command_line switch.
Is there a way to expose them to the docker container?
Otherwise a workaround would be to execute a command through ssh (docker has ssh in its stuff), but I would like to avoid that
Not if you run hass.io The shell is very limited in what you can do. As an example, the date command date -%z (or is it +) should return the Time Zone and it does in the normal bash shell but it doesn’t work in the home assistant container… That and about 100 other things I was trying to do. I found convoluted workarounds to all my issues though.
The O/S can see all the HA config folder though so why don’t you attack it by creating files in /config or a sub directory and then just use cron or something else in the host to copy or move the files to where you really want them? There’s always a way… just need to think outside the box and work within the constraints imposed by hass.io.
unfortunately, there’s no way to call host’s executables from a docker container.
A solution seems to make a python script with a MQTT client that catches msgs on a reserved topic outside docker and then execs the commands on the host’s env.
Then no “command_line” input is necessary.
I can share the code, if anyone is interested
No matter what, you’re constrained by what you can run from a shell in the Home Assistant container. In my case I was using curl and date and jq… stuff like that… I wanted to publish json to my MQTT broker… but yeah… no mosquitto_pub in the container for that so I just ended up using a long term token and curl and it published the json to the sensor I wanted… Always multiple ways to get where you want to go.