Sensor Command Line Error

I try to run a simple bash command with a command line sensor. The code worked until I decided to reinstall the machine and have HASS now running according to the steps for VirtualEnv.

The sensor does not show the value and at the same time I have the following error in the log:

17-01-20 19:48:17 homeassistant.components.sensor.command_line: Command failed: echo $(/opt/vc/bin/vcgencmd measure_temp) | cut -d ‘=’ -f2 | sed ‘s/…$//’

Anybody seen this and have an idea how to fix it ?

Thanks !

Try to run that command in the virtual env.

To enter the virtual env use this command:
sudo su -s /bin/bash homeassistant
Replace homeassistant by your hass username if it’s a different one.

I suspect that your virtual env doesn’t have the right to read /opt/vc/bin/vcgencmd measure_temp

Thanks for the quick reply, but as the user I can execute the command and it give me the value I expect.

Here is the sensor code …

  • platform: command_line
    name: GPU Temperature
    command: “echo $(/opt/vc/bin/vcgencmd measure_temp) | cut -d ‘=’ -f2 | sed ‘s/…$//’”
    unit_of_measurement: “°C”
    value_template: ‘{{ value }}’

This looks odd to me. If the command sends the result to stdout, shouldn’t the command be

/opt/vc/bin/vcgencmd measure_temp | cut -d '=' -f2 | sed 's/..$//

The echo $(…) would be looking for an environmental variable with the name of the result of the command - I think.

Thanks, but even though your code works under the user running HASS, once I use it in a sensor I get the same error message.

Using the VirtualEnv I ran into more issues. Discovery and Wemo would not work (due to the fact that dependencies could not be installed). I spend some time installing the dependencies by hand (in the VirtualEnv) and even gave the HASS user access to all groups.

However, in the end the problem stayed and I uninstalled HASS from the virtual environment and put it directly on the machine.

@DownUnder what does this command do? sed 's/..$//'

It removes the last two characters from the line.

But this command is more efficient, as it only starts one subprocess

vcgencmd measure_temp | sed "s/temp=//;s/'C//"