Q on cmd line in Linux


I’ve the following code in config under sensor but I get “unknown” as results. However, if I run the code on a cmd line, it works.

Where am I failing?
Rpi 3B running with Docker

    - platform: command_line
      name: CPU Temp
      command: "cat /sys/class/thermal/thermal_zone0/temp"
      unit_of_measurement: "°C"
      value_template: "{{ value | multiply(0.001) | round(1) }}"
-- WORKS --
    - platform: command_line
      name: GPU Temp
      command: "/opt/vc/bin/vcgencmd measure_temp"
      unit_of_measurement: "°C"
      value_template: '{{ value | regex_findall_index("=([0-9]*\.[0-9]*)", 0) }}'
    - platform: command_line
      name: CPU Clock
      command: "/opt/vc/bin/vcgencmd measure_clock arm"
      unit_of_measurement: "MHz"
      value_template: '{{ value | regex_findall_index("=([0-9]*)", 0) | multiply(0.000001) | round(0) }}'

This are the known cmds for that as far as i can see. But


is in /usr/bin on my Raspi4

Are you running that inside your docker container?

Maybe the container has no access to the /sys dir?

You may try

docker exec -it <your conatinername> sh

to open a shell inside the container and check out if the cmd work or if the cmd are in the place you are using.

Thank you.

Still confused. I do get the CPU temp as I stated in my post however, within the docker shell I do not.
Here’re my results:

/config # cat /sys/class/thermal/thermal_zone0/temp
/config # /opt/vc/bin/vcgencmd measure_temp
VCHI initialization failed
/config # /opt/vc/bin/vcgencmd measure_clock arm
VCHI initialization failed


I think the user inside the container has not the right to execute vcgencmd.

You must find out which user/userid the User inside the container executes the vcgencmd. This user has to be added to the user group (here: video) that is allowed to execute it.

sudo usermod -aG video <username>

video? :face_with_raised_eyebrow:

That’s the name of the usergrp which is allowed to execute the commands. You have to add the user to that group. Forgot <username> (?) (s. above)

Ok, got you. Thanks.
When I installed docker, I had to create a group docker. However, I’m logginig as pi:

pi@piServer:~ $ groups
pi adm dialout cdrom sudo audio video plugdev games users input netdev lpadmin docker gpio i2c spi
pi@piServer:~ $ groups  docker
groups: ‘docker’: no such user
pi@piServer:~ $

The user inside the container needs the right to execute the commands. Therefore he has to be in the group “video”.

You have to figure out which user tries to execute the vcgencmd and put the user in the group “video”

How do I do that? The log is not much of help…

2021-05-17 18:19:53 ERROR (SyncWorker_2) [homeassistant.components.command_line] Command failed: /opt/vc/bin/vcgencmd measure_temp