Temperature conversion from F to C with sensor with Value_template not working

I am trying to convert a F temperature sensor value to a new C temperature sensor. I have the following code that I am trying, but it only sets the sensor value to the F temperature comes from the original sensor.

  - platform: template
    sensors:
      octoprint_bed_temp_celsius:
        friendly_name: 'Bed Temperature'
        unit_of_measurement: "°C"
        value_template: "{{ ((states('sensor.octoprint_actual_bed_temp')|float-32)* 5 / 9)|round(1) }}"

If I take the template string to the template developer, it converts the F value to the correct C value. For some reason the sensor code does not put the correct value in the new sensor.

What is the current f value from the sensor?
What is this in C ?
What does your template sensor say it is?

Ie is it doing a double conversion?
Sometimes changing the uom is enough

See above for details of your questions

That’s Weird, That “Should” Work

  1. Have you restarted since creating this sensor ?
  2. Can you find ANY other reference to “octoprint_bed_temp_celsius” in ANY of your files ?
  3. Does your config check raise ANY errors ?

I’m grasping at straws here … Really weird

Yes, it’s really weird.
I’ve restarted many times without any change.
no other references to my sensor “octoprint_bed_temp_celsius” anywhere that I can find
No errors in config check or in the log…

All I want to do is report the temperature in Celsius instead of the Fahrenheit value received from the “sensor.octoprint_actual_bed_temp” - not really to complicated I didn’t think…

Tried several other ideas but nothing works. It seems that Octoprint’s output is Celsius and since I have unit_system: imperial, Hassio automatically converts it to Fahrenheit and assigns a “Unit of measurement= °F” to the sensor. If I change the unit_system to metric, the proper °C value is brought in to HA, but I have many other sensors that are imperial that get converted automatically to metric, and I don’t want that.

I have tried to change the Unit of measure to °C, but HA wont change it to °C.
Like I stated earlier, I can get a template to convert correctly in the template editor, but in my configuration, it doesn’t do the math, it just assigns the value from the source sensor and assigns a unit of measurement of °F.

Anybody have any ideas?

I am having the same issues. I am in the United States so we typically use F for our unit of measurement. How ever I use C for my 3d printer in Octoprint and would like it to display in C if possible. Was wondering if you figured this out.

Here’s what I ended up doing:

Since you are able to get a set of “default” sensors with the Octoprint integration, you just need to put in your customize.yaml file the following (make sure on the single quote around the C). It does the conversion for you. I couldn’t believe how easy it was once I found the correct format.

sensor.octoprint_actual_tool0_temp:
  unit_of_measurement: 'C'
  friendly_name: Nozzle Temperature
  icon: mdi:thermometer

2020-04-13_23h51_59

3 Likes

Sorry a total noob. but do I just create a file in Configurator and name it customize.yaml? Also do I have to add anything to my configuration.yaml to get the value of the sensor that is placed in the customize.yaml.

I got it, Thank you so much. I worked on this all Day. You made my night.

Yes, just create customize.yaml and add the lines and restart.It will then “set” the value to the correct Celsius value when you use it.

Hey, I was a noob a few months ago too, but have learned alot here in the forums.

1 Like

I just wanted to thank you guys because I have been going around pulling my hair out for months with this exact same issue until I dug deep enough in the Google results to find this thread.

I kept finding people either making template sensors or claiming that Home Assistant could convert it on its own and having no luck no matter how many places I specified the unit of measurement.

The thing that finally fixed it for me was the realization that Home Assistant requires you to specify the unit of measurement as ‘C’ and not ‘°C’. I’m not sure why they don’t think Celcius is measured in degrees, but everything started working as soon as I got the unit typed correctly.

Thanks again!

I had the same problem, when I wanted to display temperatures in F for my wife and in C for me. My system is set to F, so I created template sensors to convert temperatures to C, however, in the frontend they were still displayed as F.

It took me a while to figure out that when HA is set to one unit system and it finds values in the other system, it automatically converts them. My solution was to define unit_of_measurement as C (without the degree sign) instead of °C. That way HA doesn’t recognize them as temperature and doesn’t convert them back.

I being looking to solve my problem exactly like that for days…
Thanks a lot for explanation!

feature request vote

Thanks for this! I came here searching for temperature conversion override for exactly the same reason: wanting to look at equipment temps for my Prusa i3 in degrees C, while everything in my ‘normal’ life is degrees F.

While overriding it to a generic ‘C’ for units instead of a temperature value gets it to display correctly, I definitely think it’s a very useful feature to be able to opt out of autoconversion for a particular sensor rather than having to hack it like this. I voted for the feature request and if you agree, you might want do so as well.

1 Like

Wasn’t really much of a hack. Set it once and forget it. I havent looked or thought about it once it was set.

Still no luck for me. I tried both ‘°C’ and ‘C’. System units is set to Fahrenheit. Is there something I’m missing?

customize.yaml:

sensor.cr6_se_actual_bed_temp:
    unit_of_measurement: 'C'
    friendly_name: Bed Temp - Actual
sensor.cr6_se_target_bed_temp:
    unit_of_measurement: 'C'
    friendly_name: Bed Temp - Target
sensor.cr6_se_actual_tool0_temp:
    unit_of_measurement: 'C'
    friendly_name: Nozzle Temp - Actual
sensor.cr6_se_target_tool0_temp:
    unit_of_measurement: 'C'
    friendly_name: Nozzle Temp - Target

image

I don’t see anything wrong with what you have . Not sure why it is not working for you. I just checked mine and it still the same as what I put in the post above. Mine still works just fine.

Did you restart after adding it to your customize.yaml?

@toofewacres I restarted several times.