Formatting a value template for a Gauge

Hi all. I’m attempting to display my 3D printer temperature readings in a gauge card through Lovelace. My hass is talking and receiving temperature readings from my octoprint server, but it’s in degrees F and I need them displayed in degrees C, without changing the system unit labels.

I created a “sensors.yaml” file and added that to my configuration.yaml file. The sensors.yaml file looks like this:

platform: template
  #
  #
  #  OctoPrint Sensor conversions 
  #
  #
sensors:

  hotend:
    friendly_name: 'Hotend Actual'
    value_template: "{{ ((states('sensor.octoprint_actual_tool0_temp') | float-32) | float*(5/9)) | round(2) }} °C"
       
  bed:
    friendly_name: 'Bed Actual'
    value_template: "{{ ((states('sensor.octoprint_actual_bed_temp') | float-32) | float*(5/9)) | round(2) }} °C"

When I add “sensor.hotend” to a gauge card, I get the error “Entity is non-numeric: sensor.hotend”. So, how can I format the output of the template sensor to be a float, so I can display it in a gauge card?

Thanks!

1 Like

Alright. I’ve answered my own question. I needed to remove the *C at the end of the value_template, and it’s working in my gauge cards nicely. Having the unit of measure in the template itself was changing my value to a string.

This is solved.

I’m having a similar issue where the system is overriding my temperature to Fahrenheit no matter what I do. The only way to break this behavior is to use a template sensor like you did and set the °C after the formula exactly as you did. This breaks the state history though. In the past, people that had this same dual unit error said to take the unit of measurement out of your config file and then you could override the dimensions. However, with the new General Configuration onboarding I can’t find a way to ignore the units.

You’re overall system units drive all temperatures. It’s impossible to have ºC and ºF sensors on a system. It will always be one or the other. Also, because of this, you don’t need to convert the values as the system will do it for you.

Do the converted °C values appear correct? I would be surprised as you have not included the 32° offset. Converting °F to °C formula should be (°F - 32) x 5/9.

Can you explain what you mean here? If you scroll to the right in the code block in the original post you’ll see the formula being used.

This is also from 2 years ago and have since changed the way I display those temperatures. I’m not in front of my instance right now to paste how I’m implementing it, but either way it worked 2 years ago because HA was changing the sensor to a string type. Removing the *C label from the template forced it to remain a float and display correctly in the gauge card (which at the time required integer or float types.) Then in the gauge card itself I was able to show the *C based on the name variable.

I completely missed the float -32 being a part of the formula.