Configuration Template. How To convert F to C on temperature?

well thanks. that makes the config easier, although i do appreciate the exercise of the manual process in the thread anyway, as i learnt more that way.

1 Like

Your situation, having to convert Fahrenheit to Celsius (with Metric being the base unit system), is handled nicely by Home Assistant (as per petro’s advice posted above).

In contrast, what’s not (currently) possible is to display two different unit systems (i.e. some entities report in Celsius and others in Fahrenheit). The existing workaround is to omit the leading degree symbol because, without it, Home Assistant does not perform automatic temperature conversion. For more information, see this post.

1 Like

which all makes sense now.

Part of the problem, earlier in the thread, i wasn’t able to put the degree symbol in, my config was tossing an error about a bad symbol. it took my brain a day to realize i needed to change the encoding on the file to utf-8 and re-save my configs, then suddenly i could actually put a degree symbol in. but by then the manual / hard way solution was in place and working, so i didn’t think too much more about it.

Regardless, thanks everyone for the help. learnt a lot, and i’m still tinkering daily with HA configs. this system is such a yin-yang of complexity wrapped around flexibility. I dont like the fact i’ve sank a week + into learning and still feel like i’m only scratching the surface, but on the other hand, i cant think of anything which HA probably cant do given the correct inputs and figuring out how to write the syntax.

Yeah, that’s super annoying. I don’t know why the files default to ascii encoding. I had to do the same way back when. What text editor are you using to edit the files? That could be the root cause of the encoding errors.

EditPad Pro. a relatively unknown editor that i’ve been using for years, it’s awesome, full regex support and so much more, and no issues with encoding, it’s what i used to change the encoding.

Edit. my HA is in a docker container, using winSCP to actually get at the files on the pi.
I’ll use vi when i’m in linux directly, but nobody likes using vi. lol.

This does not seem to work for me, using the System Monitor sensor platform; it doesn’t seem to recognize the unit_of_measurement argument. I have my overall units set to Imperial, but I’d like to see CPU temperatures in Celsius, since that’s what my brain is calibrated to for computers :smiley:

Here’s what I have in my configuration.yaml file:

  - platform: systemmonitor
      - type: disk_use_percent
        arg: /home
      - type: memory_free
      - type: memory_use_percent
      - type: processor_temperature
        unit_of_measurement: '°C'

The units bit was just ignored, and my CPU temp still shows in F. Am I doing something wrong here, or is there a different/better way to accomplish this?

That’s working as intended. The units are always converted to your system wide units. If you want it to not convert, you have to use something other than ºC or ºF as a unit_of_measurement. You’ll also have to manually perform the conversion yourself.

I see…many thanks for the info. How would I go about doing the conversion myself? I definitely want my overall system units to be ºF, but I want the CPU temps to show in ºC.

I also have this question. I finally understand the posts from @petro, but I imagine for folks in the USA this is a pretty common need. We use imperial, so I want temps generally in Farenheit (humiture sensors, outdoor temp, etc) so my HA is set to that. But, when monitoring Raspberry Pi’s, Synology NAS, and other computers, most of us would want to see those in Celsius. What is the proper, and easiest way to do this in HA in 2021? I’ve been using HA significantly for more than a year now and this is one thing I still have yet to fully grasp…and one day I spent 4+ hours on this problem. Sure, I am probably being dense and over-complicating it some, but from everything I’ve read on the internet I don’t feel that it is incredibly intuitive.

1 Like

I second this complaint/request. Need to be able to display processor_temperatures in Celsius and not the “system configuration”. When we talk about computer systems temperatures few people use Fahrenheit.

One workaround to use command_line platform to cat /sys/class/thermal… However, this does not work for me on my system as the sensor moves around every boot. Attempting to do a longer code in the command_line platform like below throws command fail error

command: paste <(cat /sys/class/thermal/thermal_zone*/type) <(cat /sys/class/thermal/thermal_zone*/temp) | grep TCPU | awk '{print $2}'

@mike0xt @ehbush You guys are making this harder than it needs to be. Just change the unit_of_measurement to anything but ºF or ºC. Those unit of measurements cause it to translate.

You mean like this? Temperature unit is not a parameter for platform: systemmonitor. It’s coded to use system configuration units.

  - platform: systemmonitor
      - type: disk_use_percent
      - type: processor_use
      - type: memory_use_percent
      - type: swap_use_percent
      - type: processor_temperature
        unit_of_measurement: 'K'    #This will not work for this module.
      - type: last_boot

My workaround for the inflexibility of temperature units in systemmontor platform is to use the command_line platform pulling from /sys/class/thermal as many have done. My temperature sensors move around every boot, and the command I posted earlier did not work (Command failed). I think the problem is the use of the curly brackets { } and/or the single quotes ’ ’ in yaml. I didn’t know how to escape them in that particular string. What finally worked for me was to use /bin/bash and use the cut command:

command: /bin/bash -c "paste <(cat /sys/class/thermal/thermal_zone*/type) <(cat /sys/class/thermal/thermal_zone*/temp) | grep TCPU | cut -c6-10"

This tabulates out the sensor names and temperatures in my /sys/class/thermal/ and picks out just the sensor that is named “TCPU” on my system to finally read out the value.

This is no longer working for me. I tried ºC and ºF and C and F and nothing. The octoprint web page shows everything in C and on HA I have everything in F. But for 3d printing C is used, so I want to display this to ºC. I don’t care how the value is internally stored, because I’m not doing anything with it.

Yep. Broken. I filed a bug report on Lovelace (thinking that it was a lovelace issue) but I may file one or see if one has been filed on core.
I run Home Assistant OS, core-2021.11.5. If I add

  unit_of_measurement: '°C'

to customize.yaml and reload core, the displayed is some whacky number. In Farenheit, it should be ~464 farenheit. But with that unit of measurement change, its showing as 866.8 °F. BTW, it does not matter if I use single quotes or not.

Hey mfratto, fellow imperial user with the same issue, trying to get C out of a sensor for my 3d printers.

We are having the opposite issue here.

As our system is set to imperial, we are getting the sensor temps in F.

HOWEVER, if we set unit_of_measurement: ‘°F’ we get nothing as our system is already in F.

And of course when we go unit_of_measurement: ‘°C’ our system is taking the reading from the sensor and converting that to C.

For example right now my sensor is at 51F and is showing 124 when the config is set.


Keep in mind the F in the graph can be changed in the UI, it is just showing system norms.

It appears for us we are going to need something along the lines of the more complicated route showed above.

@Dangck @alpharesearch we’re discussing the same issue over here as the issue seems to be due to the 2021.9.0 upgrade.

I see @mfratto opened an issue on GH for this, but no one has touched it since opening other than a comment to create template sensors which I really don’t think is good solution…

I wonder if someone tried to end the confusion by recognizing C as °C and F as °F. I would try using something like Cel, *C, *F or Far as the units of measurement if I wanted to avoid automatic conversion. I have used templates in the past to convert temperatures manually. The trick is to make sure HA doesn’t recognize the unit of measurement you set and it won’t convert it.

Perhaps at some future point there will be an option in a template or a card that allows you to specify when you want to to display a different unit of measure from your default.

1 Like

Everything is moving that direction… sounds like we might need this as a month of WTH if it ever shows back up.

1 Like

Thank you!!! Just tried a bunch of conversions for an Accurite sensor, no luck. This is simple and works perfectly!

1 Like