TCP permissions?

Because it would fail any time I called it as /usr/bin/nc but creating a symlink in config (/usr/share/hassio/homeassistant) and calling that works.

I clearly have some kind of permission issue with the docker container or HA, and that’s what I’m trying to solve… but root is the only user that seems to be there… I’m new to docker so that may be why I’m struggling. The docs are all over the place too… I have found 5 walkthroughs from the last year on the home assistant site of how to install supervised and all are slightly different…

I did see that raspbian is not actually approved a s a “supported” OS… maybe I will start over (again…) with true Debian10 and see if that helps… nothing that worked in the HASSOS install works here and nothing that works here works in the HASSOS install.

Sorry. I have a tendency to read diagonally when there is too much text :wink:

You can enter your container with docker exec -it homeassistant /bin/bash from the OS.
You’ll get a shell under root. HA also runs under root in the container so you’d have a smilar environment.

Now, you might be able to debug more easily your issue.

Note that you don’t have a full bash. Just busybox. So that could limit the capabilities of your scripts
Nevermind. Seems a full bash. I’m not sure wthether shell commands run under bash or plain sh though, which is busybox, not bash. That might explain…

EDIT2: Setting the HA log level to debug would show the commands stdout/stderr, according to the doc

EDIT3: Again from the doc, the proper way to execute a script would be bash /config/shell/script.sh

All good, I have a tendency to use too many words to get my point across… lol

I will try that… but I did see that the add-on web ssh terminal is busybox which is why I tested there assuming if it works in that limited environment it should within HA. Also paths and env are different there so I used that to make sure all was good. I wonder if that provides yet another env…?

Had logs at debug but didn’t get more info from the error. I love errors, they tell you exactly how to fix the issue! I would kill to get some detailed errors! Lol

As for /config/shell/script.sh Is that needed? That folder doesn’t exist, though I have a folder I put those scripts in but the name was different. Is there something that allows for permissions for a folder with that name? I saw multiple people say on threads that they must be in the main config folder so I moved them there instead of the sub folder I had within config

Replace that with the path to your actual bash script, obviously :wink:

Oh, ok. I had them in /config/dd/ (with proper path) and they did not work so I moved them to /config/ and they didnt work. I was not sure if you were saying that /config/shell/ had special permissions within the HA environment… All my scripts have been in /config/ or a folder within.

Just connected with this technique and all scripts function properly with nc (actual /usr/bin/nc, not my symlink) OR curl OR echo to /dev/tcp/10.0.0.2/6722

They also all work from the busybox terminal in the add-on and the OS env… There are definately different permissions in the HA running environment than in any of these other three options. I also can write to files and /dev/null from any of those places but not from within HA…

Ah, not sure how you installed HA, but there is apparmor involved, which might limit what you can do under HA.
I had it disabled everywhere so cannot really help, there.

Now we are getting somewhere… lol!
I remember seeing an error or message about apparmor. I believe I was going through the info screen trying to make everything “approved” and it was not there so I added it… but now I cannot find that. I did not know what it was so I added it thinking it was required (again, never used docker before so a LOT of new things thrown at me)

How did you disable it?

I installed standard raspbian, then I did:

sudo apt autoremove
curl -fsSL get.docker.com -o get-docker.sh && sh get-docker.sh
sudo systemctl enable docker
sudo systemctl start docker
sudo usermod -aG docker pi
sudo apt-get install jq apparmor-utils socat network-manager
sudo reboot now
sudo apt-get purge modemmanager

I was “strongly suggested” to enable it there:

I guess doing the inverse would disable it?

I stopped the service and now I can run nc without the symlink! What I am noticing though is when I create a switch like this:

switch:
  - platform: command_line
    switches:
      lanterncont:
        command_timeout: 2
        command_on: shell_command.lantern_on
        command_off: shell_command.lantern_off
        command_state: shell_command.lantern_state
        value_template: >
          {% if (value[0] == "0") -%}
            {{ '0' }}
          {%- else -%}
            {{ '-1' }}
          {%- endif %}
        friendly_name: Lantern Control

and I have

shell_command:
  lantern_on: echo -n 21 | nc -w 2 10.0.0.2 6722
  lantern_off: echo -n 11 | nc -w 2 10.0.0.2 6722
  lantern_state: echo -n 23 | nc -w 2 10.0.0.2 6722

Creating a basic button and setting ‘tap_action’ to toggle, I get errors of script failed for the scripts in command_on, command_off, and command_status… which are calling my commands as shown (ie: command_on: shell_command.lantern_on) but if I do ‘tap_action’ of ‘call-service’ and call service shell_command.lantern_on it works with no errors… So this issue seems to now be in the toggle functionality… How can it work when triggered by a call-service but not when triggered by a toggle?!? The toggle function updates so fast on my other install but using call-service I need two buttons and have to process the status myself which is only when that tcp sensor updates which takes forever.

Got the time down to 5-10s…
By making the call-service button entity the tcp sensor rather than the switch.

Now if I can get it to use shell commands from a script file instead of “inline” commands in the yaml I should be good! The app-armor was definitely blocking the inline scripts but I can’t make it run .sh files still.

Using the bash /config/<myscript.sh> way?

nope. And all I get in the log is this:

2021-06-28 13:53:51 INFO (SyncWorker_1) [homeassistant.components.command_line.switch] Running state value command: shell_command.lantern_state
2021-06-28 13:53:51 ERROR (SyncWorker_1) [homeassistant.components.command_line] Command failed: shell_command.lantern_state

But triggering shell_command.lantern_state from a button with:

          tap_action:
            action: call-service
            service: shell_command.lantern_state
            service_data: {}
            target: {}

Works every time

I ran into permission problems similar to this and IIRC I had to install the community version of web terminal in order to get elevated permissions. Which version of ssh did you install, there are 2.

I installed “Terminal & SSH” at “Current version: 9.1.3”

all scripts work from there though.

From what I remember it was the same, I could get it to work from a command line but that was it. It’s in the lower portion.

Actually, I don’t think shell_commands in a command-line switch are supported.
All “command” options take strings, not entities.

See
Command line Switch - Home Assistant (home-assistant.io)

Well… there it is… the toggles work with text strings… :persevere:
Dont know how I missed that!! Thanks!