How to display temperature in Celsius only for some sensors?

Being in the US, I would prefer most temperature to be shown in Fahrenheit. However, anything computer-related (e.g., CPU, hard drive, etc.) should be in Celsius (since it’s the norm for checking if there are thermal issues). I tried setting temperature_unit in the customize.yaml file, but it just changed the unit in the display without converting the number. What should I do to get the temperature value to be converted properly?

You have to make a template sensor for these. I had to do the same thing for my 3D printer to see some temperatures in Celsius.

Template example I use:

      - unique_id: ender3_actual_bed_temp_c
        unit_of_measurement: 'ºC'
        state: "{{ ((states('sensor.ender3_actual_bed_temp')|float-32)* 5 / 9)|round(1) }}"

After you reload templates, you’ll have to find the sensor.template_whatever and change the entity_id to your liking.

Got it. I feared that might be the case but it’s not really that many extra lines of code (or yaml in this case). Thanks so much.

Just one thing, this is not the degree symbol:

https://en.wikipedia.org/wiki/Ordinal_indicator

This is:

unit_of_measurement: '°C'

https://en.wikipedia.org/wiki/Degree_symbol

It may seem like a minor thing but it will prevent you graphing more than one temperature sensor on the same graph if you use a mix of units.

The masculine ordinal indicator º may be confused with the degree sign ° (U+00B0), which looks very similar and which is provided on the Italian and Latin American keyboard layouts. It was common in the early days of computers to use the same character for both.[citation needed] The degree sign is a uniform circle and is never underlined. The masculine ordinal indicator is the shape of a lower-case letter o, and thus may be oval or elliptical, and may have a varying line thickness.

2 Likes

Nice call. This is exactly the kind of thing that would irritate me once I found I was using the wrong symbol. Thanks!

I seem to remember having issues (many versions ago) where Home Assistant would convert it back to F anyways if I used the correct degrees symbol. Was likely user error or just not configured all the way, but honestly, for my needs, this worked fine. I just wanted to monitor current values of my 3D printer and this was good enough. Good feedback though.

Follow-up question. Is there any way to wrap up the Fahrenheit to Celsius conversion function in a macro? For example, something along the lines of:

{% macro fahrenheit_to_celsius(sensor) %}
  {{ ((states(sensor)|float - 32) * 5/9)| round(1) }}
{% endmacro %}

Then, I could use it in my configs (since I have a bunch of sensors for which I need to convert from Fahrenheit to Celsius:

template:
  - sensor:
    - name: "Synology CPU temperature"
      unique_id: "Synology CPU temperature"
      state: "{{ fahrenheit_to_celsius('sensor.synology_temperature_1') }}"
      unit_of_measurement: 'ºC'
      icon: "mdi:thermometer"

Hello,

Did you find an answer to your question? If so, would you mind sharing?

I have >10 temp sensors in various areas and would like to display their values in both C and F in separate lines.

As I understand, templating requires me to create a separate entry for each sensor and then apply a formula, instead of defining one macro/function (from C to F or other way around) and use that formula for all unuts.

Is my understanding correct?

2 Likes