How to show the Raspberry Pi CPU temperature?

Invalid config for [sensor.command_line]: invalid template (TemplateSyntaxError: unexpected char ‘“’ at 54) for dictionary value @ data[‘value_template’]. Got ‘‘{{ value | multiply(0.001) | round(1) | replace("’", “”) |replace(“temp=”, “”) }}’’.

See my edit. I had a “ before replace(Temp-=

Weird. I’m getting fancy double and single quotes when I copy and paste your example.

So I typed this out:

value_template: '{{ value | multiply(0.001) | round(1) | replace("'", "") | replace("temp=", "") }}'

But HA is still not happy.

Invalid config for [sensor.command_line]: invalid template (TemplateSyntaxError: unexpected char ‘“’ at 54) for dictionary value @ data[‘value_template’]. Got ‘‘{{ value | multiply(0.001) | round(1) | replace("’", “”) | replace(“temp=", “”) }}’’.

Sometimes the forum does funny things with single inverted commas… you see the logic of the replace command though. I’m using similar command line sensors and value templates without any issue…

I do see your logic. I’ve been stripping it down to test one thing at a time and it seems HA has a problem with this:

replace("'", "")

it throws this error right at the single quote:

expected <block end>, but found '<scalar>' in "/config/sensors.yaml", line 64, column 41

Oh wow. You have to escape a single quote with a single quote in YAML!

http://yaml.org/spec/current.html#id2534365 (look at Example 4.57. Single Quoted Quotes)

This works:

- platform: command_line
  name: GPU Temperature
  command: "/opt/vc/bin/vcgencmd measure_temp"
  unit_of_measurement: "°C"
  value_template: '{{ value | replace("temp=", "") | replace("''C", "") }}' 

Thanks for putting me on the right track David.

2 Likes

Good Grief!!!

You’re Welcome.

This is how I rounded F to an integer and added an “F”

  - platform: command_line
    name: cpu_temperature
    command: "cat /sys/class/thermal/thermal_zone0/temp | awk '{printf \"%.0fF\", ((($1*.001) * 9 / 5))+32}'"

Does Glances (https://www.home-assistant.io/components/sensor.glances/) already work for Hass.io?

all components listed under home-assistant.io/components will work with HassIO (unless there is something specifically noted as not compatible, but i dont think any exist like that, at least not that I have seen)

However after having a quick look at glances it appears you will need to SSH into HassIO and start the server which is a little more involved than most components. Shouldn’t be an issue, just give it a try.

Yes, that should be possible but I don’t want to mess with my nice hass.io installation too much… :pensive:

so run another RPi for the Glances server…

@sapnho, f you don’t want to mess with glances have a look at this component.

Nothing more than yaml configuration required.

4 Likes

Thank @tom_l, good idea!

System monitor shows the cpu temperature for RPi? I don’t see it under configuration variables.

No system monitor does not include CPU temperature. Use this sensor:

- platform: command_line
  name: CPU Temperature
  command: "cat /sys/class/thermal/thermal_zone0/temp"
  unit_of_measurement: "°C"
  value_template: '{{ value | multiply(0.001) | round(1) }}'

And for the GPU:

- platform: command_line
  name: GPU Temperature
  command: "/opt/vc/bin/vcgencmd measure_temp"
  unit_of_measurement: "°C"
  value_template: '{{ value | replace("temp=", "") | replace("''C", "") }}'
7 Likes

On my system (Raspbian Release 9.6, Kernel version: 4.14) I do not have this command…

1 Like

Any time I use the degree symbol in my yaml, like:

unit_of_measurement: “°C”

I get an error:

Error loading /config/configuration.yaml: ‘utf-8’ codec can’t decode byte 0xb0 in position 2830: invalid start byte

It works fine if I leave that line out.

Try using different quotes. Single quotes work, also note the difference between your double quotes and the ones below.

unit_of_measurement: '°C'

unit_of_measurement: "°C"

I tried both kinds of quotes, no difference. The double quotes only looked wrong here in the forum because I quoted the line instead of using a code block like I should have.

I also verified that I’m using ASCII character decimal 176, xB0.

If I delete just that one character, the config checks OK. If I re-add it, I get the error again. I’ve already moved on, not worth worrying about. I used legit’s method of displaying in F, which works fine.