Sensor command_line does not work

Hi
I did a sensor like this:

- platform: command_line
  name: wlan0
  command: "/usr/bin/nmcli dev status|grep wlan0| /usr/bin/awk '{print $3}'"
  scan_interval: 60

when i executed the command manually it is working

➜  /config /usr/bin/nmcli dev status|grep wlan0| /usr/bin/awk '{print $3}'
disconnected

unfortunatly my sensor is always empty in ha

do you know why ?


in debug it is running

➜  /config tail -f home-assistant.log| grep -i wlan0
2023-02-26 20:48:06.952 DEBUG (SyncWorker_10) [homeassistant.components.command_line.sensor] Running command: /usr/bin/nmcli dev status|grep wlan0| /usr/bin/awk '{print $3}'
2023-02-26 20:49:07.064 DEBUG (SyncWorker_1) [homeassistant.components.command_line.sensor] Running command: /usr/bin/nmcli dev status|grep wlan0| /usr/bin/awk '{print $3}'

Tkx for your help

And where do you execute it manually?
In the Docker hostOS or the Docker guestOS?

Hi
Thx for your help.
I don’t know what’s “hostOS” or “GuestOS”
I am on a raspberry pi 4 with Homeassistant distribution installed
It is helpfull for you to determine hostOS or guestOS ?
thx

You often have one system running on your device and then docker with another system running on top of that.
The first one will be the hostOS and the one in the docker will be th guestOS.
Typically HA will be running in the docker as a guestOS.
Your SSH connection might be to the hostOS and therefore give other results than what HA gives you.

Ok but what about my command_line sensor?

No nmcli on my HA Docker:

image

Can you set up another sensor:

- platform: command_line
  name: cmd_test
  command: echo "nmcli: `which nmcli`; awk: `which awk`'"

and paste what that returns?

here is the result

nmcli: ; awk : /usr/bin/awk

That’s mean nmcli is not reachable from guestOS right?
how can i access nmcli from guestOS?

Correct.

You can’t: you’ll have to find another way to achieve what you’re trying to do, as NetworkManager isn’t a part of the HA installation. What are you trying to achieve?

i would like to know if my wlan0 interface is connected or disconnected

Ping your router.