I’m trying to configure a binary sensor which checks if home assistant is still connected to a specific wifi network (mywifi).
I tested the command on home assistant using the terminal and it returns ON or OFF if it is connected to the WIFI. So the command is working.
My question now is what am I doing wrong in this configuration?
If you are running home assistant supervised or in a container, the shell command is executed inside the home assistant docker container. The container has its own virtual environment and cannot see outside of the container. You would need to ssh into the machine running home assistant which is complicated. It’s possible with sshpass sshpass: An Excellent Tool for Non-Interactive SSH Login - Never Use on Production Server but you would need to install it in the container everytime you upgrade to a new version of HA. nmcli is also not available inside the container, so you would need to install that also inside the container.
It’s probably easier to run a script on the machine that updates a sensor through the REST API.
Sure. Here is a simple bash script that creates a sensor in HA and sets the state to the current wifi network name. You need to get a long-lived access token from the HA frontend.
This is why your command is failing. Remember, the commands run within the homeassistant container and where you tested it is NOT in that container. You should test commands by connecting to the container. See:
#
# docker exec -it homeassistant nmcli
OCI runtime exec failed: exec failed: unable to start container process: exec: "nmcli": executable file not found in $PATH: unknown
# docker exec -it homeassistant bash
bash-5.1# which nmcli
bash-5.1# nmcli
bash: nmcli: command not found
bash-5.1# exit
There is no nmcli within the home assistant container. Let’s step back and see what you’re trying to do. Perhaps you can grab what you need from the supervisor itself?
For Example: I am not using wifi but you get the idea…
Ok, This works. So now I have the status of my wifi connection. But I think I’m running into the same problems trying to connect to the wifi because this is also a nmcli command.
The best way to test is to get ssh access and connect to the homeassistant docker to test. Otherwise you’re guessing… nmcli definitely isn’t available.
If I execute this command in the terminal (add-on) it works. So I guess the SUPERVISOR_TOKEN is not available to the shell_command or should I add it in a different way?