Alternitave to shell_commands, for those who can't get it to work

Hi Everyone,

I’ve just spent 9 or so hours trying to figure out how to run CATT through node-red, and one of the things that surprised me is the large number of people having the same problem as me. I was trying to use a shell_command to run a CATT command. However, no matter what I tried, It would give me 127 or 126 errors.

The problem lies in the way that hassos works. For those who don’t know, hassos is actually a docker-style instance with multiple containers (you can see this by installing the Portainer addon). When you install a program through pip (like CATT), it’s installed in the overall OS, not in the homeassistant container. The problem is, shell_commands can only access files in the homeassistant container, so they have no way of accessing or running programs installed in HASSOS. A solution to this is to use an addon, more specifically SSH & Web Terminal

When you install an add-on in HASSOS, it’s installed outside of the homeassistant container. That’s why the shell can access folders like homeassistant can’t (for example, the /usr/bin folder.) The reason we have to use this specific addon is because of the hassio.addon_stdin service. This action allows you to submit data to some addons using a service call. All you have to do is call that service, with these actions:

If you are using homeassistant’s automations:

service: hassio.addon_stdin
data:
  addon: a0d7b954_ssh
  input: YOUR COMMAND HERE

If you are using node-red, import this node:

[{"id":"61ae424a.20154c","type":"api-call-service","z":"117467cc.ef2398","name":"Command line","server":"161668c4.e6c7f7","version":1,"debugenabled":true,"service_domain":"hassio","service":"addon_stdin","entityId":"","data":"{\"addon\":\"a0d7b954_ssh\",\"input\":\"INSERT COMMAND HERE\"}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":520,"y":220,"wires":[[]]},{"id":"161668c4.e6c7f7","type":"server","name":"Home Assistant","addon":true}]

Now an important final step is if you are using pip to install packages (this may apply for other command-line tools also) you will need to reinstall the program every time the addon is restarted. This is because the terminal is run in a secure environment, that resets every time the addon is restarted. The best way to fix this is to simply add a startup command in the SSH Configuration.
image
Just type the install command between the two brackets, and hit save.


That should basically be it! No more shell_commands, no more 127 errors.

TLDR: Install the SSH & Web Terminal addon, call the hassio.addon_stdin service, and add the install command to your startup processes.

Hope this helps someone, and I apologize if this is a bit badly written. I’m typing on my phone while in the back of a train :smile:
I’ll try my best to answer any questions!

1 Like