Fixing Fahrenheit-to-Celsius as a one-off conversion template

As someone living in the United States, we use Fahrenheit for temperatures and imperial measurements for measuring things. (Including measuring ingredients by weight or volume, depending!) Which is why my HA uses Fahrenheit/imperial. But in 3D printing, I use Celsius.

Sometime in August/September 2021, Home Assistant broke part of my process. It could be that my customization.yaml file's "C" designation broke, or that Home Assistant figured out what was going on and decided to "help" me by converting Celsius from the printer into Fahrenheit. Doesn't matter - end result: my Octoprint sensors were reporting Fahrenheit temps instead of my desired Celsius.

First step: Create conversion template entities

I added this to my configuration.yaml file:

sensor:
  - platform: template
    sensors:
      octoprint_micro_actual_bed_temp_c:
        friendly_name: "Micro Bed (°C)"
        value_template: "{{ ((states('sensor.octoprint_micro_actual_bed_temp') | float - 32) * (5/9)) | round(0) }}"
      octoprint_micro_actual_tool0_temp_c:
        friendly_name: "Micro Nozzle (°C)"
        value_template: "{{ ((states('sensor.octoprint_micro_actual_tool0_temp') | float - 32) * (5/9)) | round(0) }}"
      octoprint_mini_actual_bed_temp_c:
        friendly_name: "Mini Bed (°C)"
        value_template: "{{ ((states('sensor.octoprint_mini_actual_bed_temp') | float - 32) * (5/9)) | round(0) }}"
      octoprint_mini_actual_tool0_temp_c:
        friendly_name: "Mini Nozzle (°C)"
        value_template: "{{ ((states('sensor.octoprint_mini_actual_tool0_temp') | float - 32) * (5/9)) | round(0) }}"

It creates 4 new sensors - the ones with the "_c", gives them friendly names, and runs the conversion. If you want decimal points, change the round(0) into round(1), etc. Obviously, you'll change the original names of your sensors and those new sensor names, but you get the point. Save your configuration.yaml file.

You don't need to restart your Home Assistant to get these sensors in. Click on Configuration in the sidebar, and scroll down to Server Controls>Check Configuration. If that works, scroll down on that page and reload "Template entities". Your four new sensors should be in the system now.

Optional: Verifying the new Template Entities

If you want to check it out before going on, click on Developer Tools in the sidebar, which starts you on "STATES". In the entity dropdown, find one of your new sensors. Mine reads "state" of -18, because it's not on. Do I always check, using Developer Tools? No. But it's a troubleshooting step if something is awry.

Fixing the old pages

If you've used my previous documentation, you'll need to adjust your printer page. Overview (sidebar)>select the page to change>upper right corner to Edit Dashboard. Select the EDIT on the card you need to update, then select which tile you need to update. In my case, mine was the second row, and I needed to change the names of two sensors to the "_c" versions. Close it, and your new sensors should be there.

That's it. Eventually I'll figure out a replacement for the -18 when HA is not connected to the printer.

Comments

Popular posts from this blog

Home Assistant Controlling Octoprint through MQTT - Chapter 1

Setting up MQTT on HA and Octoprint

Home Assistant Controlling Octoprint through MQTT - Chapter 2