Command Line Sensors Blank

- platform: command_line
  name: CPU
  command: "/usr/bin/sensors | grep 'Package id 0' | cut -c17-20"
  scan_interval: 30
  unit_of_measurement: "°C"

- platform: command_line
  name: SDA
  command: "hddtemp -n /dev/sda"
  unit_of_measurement: "°C"

In both of these cases, I get blank values. In the case of the bottom, the value is “unknown”. IN the case of the top, the value is simply blank.

Looking a bit further, it seems HASS doesn’t have sufficient permissions to run these commands. Is there any way to give it such permissions?

This is running on an Ubuntu Server system.

Check your logs, it’s probably a permission issue…
Also what happens when you manually run these commands in a terminal?

And what type if installation of HA are you running?

there are many and the answer may be related to which version of HA you running.

I had tried the docker-based installation of Home Assistant and HassIO and it seemed like I had extensive issues with both, so I did a “standard” install, whatever that would mean. I kept reinstalling it different ways at the time so I forgot which one ultimately worked.

I can say that I don’t have a user named “Hass” like I had on the Pi. So it may be running in a docker image.

I added “no password” permissions for hddtemp and sensors, and running these in a terminal both as root and as the main user yields the results I expected.

In Docker, you won’t have access to the host system, this is a basic safety/security which is key / basics for docker containers. is basically a docker version of HA
The way I’ve approached this is to have some python / shell scripts running on the host and publishing via MQTT.

You can set up the docker container to run commands on the host. I’ve done it. Here are the guides I used: from @juan11perez

and additional info can be found here:

I recently moved my HA installation from a Python virtual environment to a docker container. I have a command line sensor that ran a Python script to hit a URL do some simple processing on the result and spit out some JSON to stdout. Since moving to docker, the sensor returns ‘unknown’ and the error in the logs complains of empty output.

However, the command can be successfully run by a docker exec command. The user is root when I get a shell on the container. I have no idea what’s happening. Does anyone know the explanation for this behaviour?

FYI, this was a complete brainfart on my part because my config wasn’t in /config before running in a container.

@Jonathanese How did you solve it?