How to use unit_of_measurement, getting unexpected Celsius to Fahrenheit conversion

So I’ve got my system set up and I’ve been messing with it for a few days solid. I’ve figured out how to use a command_line platform in sensors to generate a CPU temperature sensor. When the cat /sys/devices/virtual/thermal/thermal_zone0/temp happens the result is usually around 49 (which is in Celsius). I defined the sensor like this:

- platform: command_line
  name: CPU Thermal Zone 0
  alias: cpu_thermal_zone_0
  command: "cat /sys/devices/virtual/thermal/thermal_zone0/temp"
  value_template: '{{ value | int }}'

I fully expected to see this show up in my display as 49°C but it doesn’t, it shows up as a bare number. I want to have °C appended, so I tried:

Using:

  • unit_of_measurement: 'Metric'
  • unit_of_measurement: Metric
  • unit_of_measurement: '°C'
  • unit_of_measurement: °C

All the above options (after restarting hass.io) yield a value converted to Fahrenheit dimension and is displayed with °F units! I’m not performing any deliberate conversions on it… what gives?

image

If I use these:

  • unit_of_measurement: 'Celsius'
  • unit_of_measurement: Celsius

It results in the bare number from the file with the word “Celsius” after it, like 49 Celsius. Not quite what I’m after either. How can I get this thing to not do a conversion and append the proper units? I’m struggling here and this seems like it should be pretty straight forward. :confounded:

Thanks,
-Greg

Did you check the doc’s?

Hi Coolie1101, I didn’t see that section of the docs. I was very hopeful. I tried it but it still gives me “°F”, and now the value reported is neither the value from the “cat” command nor the Fahrenheit conversion…

What do you get for “/opt/vc/bin/vcgencmd measure_temp”

I don’t have anything in /opt. Is there some way to install vcgencmd? I tried “apt install vcgencmd”, no dice.

Maybe apt-get or sudo apt-get

vcgencmd measure_temp

You’re using a image

Maybe cat /etc/armbianmonitor/datasources/soctemp or cat /sys/devices/virtual/thermal/thermal_zone0/temp

See unit_system here: https://www.home-assistant.io/docs/configuration/basic/

I suspect it’s set to imperial either manually or automatically based on location. Setting that option to metric could resolve the issue I think.

1 Like

Shouldn’t there be a hierarchy in the selection of units and the global Metric/Imperial selection should be the least significant? I would expect to be able to force the units at the entity definition or customization to be able to override the global selection. Is that not possible?

Thanks Coolie1101, I am able to get the result but the problem is still the same:

$ cat /sys/devices/virtual/thermal/thermal_zone0/temp
46
$

It’s represented in °C from the command line but it’s converted to °F, likely because of the configuration.yaml’s Imperial setting. I just thought that the global should be override-able.

Yes it’s a bit weird ATM. But on the other hand, how many people use both °C and °F at the same time.

A unit system converter will be quite a bit project in Home assistant but there’s already some discussion on how to move ahead here: https://github.com/home-assistant/architecture/issues/10

@SpikeyGG As @OttoWinter said, mine is set to imperial, that;s why the conversion in the sensor template takes effect.

homeassistant:
  name: Home
  latitude: !secret latitude
  longitude: !secret longitude
  elevation: !secret elevation
  # metric for Metric, imperial for Imperial  
  unit_system: imperial

Same surprise here.
I expected to use ‘unit_of_measurement’ to describe how the value should be presented in the UI, but instead it turns out to mean how the value is to be interpreted, and then the UI just presents it using the global setting for locale. Not what I expected, or wanted.
I display the outdoor temperature in Fahrenheit (because my locality references it that way), but I wanted to display CPU temperature in Celsius (because the sane part of the world refers to it in that manner). But the UI (unexpectedly) did the C-to-F math on the number and displayed it in Fahrenheit, removing my ability to display a Celsius temperature alongside a Fahrenheit one.

Perhaps the line in the docs could be clarified about what that parameter is going to do.

1 Like