Displaying temps in BOTH C and F

Hoping somebody can help me here with a bit of a unique situation.
Working on my father’s HA config and they prefer to have any temperature from outside the house shown in C, and any temperature from inside the house shown in F. This may be a bit of a unique scenario as most would want all C or all F.

The system is set to metric, so default is in C.

I’ve tried using customize.yaml to allow HA to convert C to F.

sensor.family_room_button_temperature:
  unit_of_measurement: '°F'

This is having mixed effects. Some sensors show the same temp value as C but with the F at the end. IE: 19.5C and 19.5F
On some other sensors it’s showing a negative value:
IE: 19.5C and -3F
Except for the garage sensor which for some reason shows as 95F when it’s currently -3C.

So I decided to just create a template sensor instead.

- platform: template
    sensors:
      family_room_temp_f:
        friendly_name: "Family Room Temperature"
        unit_of_measurement: '°F'
        value_template: >-
          {% set t = states('sensor.family_room_button_temperature') | float %}
          {{((t)*9/5)+32}}

In dev tools I can check the calculation and it’s giving me the proper result in F.
But the sensor created is still showing the original value in C.

So lastly I tried customizing the template sensors hoping HA would convert it back to F.

sensor.family_room_temp_f:
  unit_of_measurement: '°F'

This results in a negative value. This sensor is currently showing -7.2C even though it’s roughly 20C which would be roughly 70F.

I’m at a complete loss here. Is there anybody else display temps in a mix of both C and F?

A workaround is to remove the ° symbol from the °F value for unit_of_measurement. It will simply show F next to the Template Sensor’s value and, more importantly, prevent Home Assistant from performing an automatic temperature conversion.

Intresting, not long ago someone on this forum confirmed that using degree symbol is correct way. And yes, he were right: °F snd °C are valid way of using those units

This is what I’ve resorted to. It’s kind of a crappy solution but it’s showing the right number at least. I would have expected the template sensor at least to allow the different temp measurement. Ah well.

Here is what I’ve been using and it works like a charm for me.

      temperature_livingroom:
        friendly_name: Living Room Temperature
        device_class: temperature
        unit_of_measurement: 'f'
        value_template: >-
            {{ (((states('sensor.ewelink_th01_333d1e23_temperature') | float(0)) * 1.8) + 32) | round(1) }}

It’s the inclusion of °F or °C in unit_of_measurement that serves as a flag for Home Assistant to perform an automatic temperature conversion to the base temperature unit system.

For example, if your Template Sensor’s template performed a conversion from Celsius to Fahrenheit and the result was 20, the automatic conversion would also kick in and produce a final result of -6.7. By dropping the ° symbol, the resulting unit_of_measurement no longer serves as a conversion flag.

1 Like

Thanks Taras, that’s good to know, I tried various things like ‘f’ and ‘F’ and that obviously did nothing but change the label. That’s what made me do the conversion myself.

This is the key. From my findings, if the base temperature unit system is C, there is absolutely no way for HA to display a temperature in F UNLESS you trick it into not knowing it’s a temperature.

Through the customize.yaml the ability to convert or not convert should be added as a new feature. It could be as simple as an extra field “convert: true” or “convert: false”.

3 Likes

OOOOooooh :smiley:

Also good to know. So maybe I won’t go “simplify” my template sensors.

Hello,

How did you resolve this problem? I need to display both F and C - my unit system is set as Imperial as System->General, as a result, everything is displayed in F in terms of temperature, even when a device sends temp in Celsius like Xiaomi sensors do.

I have a feeling that I might have to define a systemwide conversion like from C to F and other way around and then apply it to readings from sensors, but don’t know where to define it.

I never did find the perfect solution, but removing the degrees symbol from unit of measurement was key to letting it convert. Although when I load it into a temp card it still shows 72°C but if you look at the state history it shows 72F (notice no degrees symbol).

Is there a way to force this conversion?

Edit: Yes there is, Add the device_class to the sensor statement and it immediately converts it.

      unit_of_measurement: "°F"
      device_class: temperature

Was this conversion field ever added?