Home Assistant

Calibrate any sensor with an offset or a reference

A template sensor applies an offset and an optional scale to any numeric sensor, and stays unavailable when the source is. A second sensor is the sum or the difference of two readings.

Difficulty · BeginnerSetup · 15–30 minutesHA · 2024.10 or newer
Get the pack · from $19Have us set it up

Some hardware links on this page are affiliate links. As an Amazon Associate I earn from qualifying purchases. We may earn a commission if you buy through them, at no extra cost to you. See the affiliate disclosure.

A cheap temperature sensor is often a degree or two off, and it is off by about the same amount every day. Replacing it does not fix the dashboards and automations that already use it. This pack is two template blueprints. One publishes a calibrated copy of a source sensor. The other publishes A minus B, or A plus B, for an indoor-outdoor delta or a room-to-room difference.

The calibrated sensor is unavailable when the source is unavailable. It does not hold the last good number.

A second sensor that should take over when this one goes offline is sensor failover. The usual node these offsets land on is ESP32-C6 climate sensor. Humidity that should run a fan or a dehumidifier, after the number is honest, is humidity climate control.

What problem it solves

You want the number on the dashboard to match a thermometer you trust, and you want a single sensor for “how much warmer is this room than outside,” without writing a new template for each pair.

How it works

  1. Calibrated sensor. You pick a source, an offset, and a multiplier. The state is source × multiplier + offset. Leave the multiplier at 1 when the sensor is only shifted. Rounding is on by default, to one decimal place. Turn it off if you want the full fraction.
  2. Unit and class. You set the unit, device class, and state class to match the source. A temperature copy uses °C or °F and device class temperature. A humidity copy uses % and device class humidity. State class stays measurement for a live reading.
  3. Unavailable. The availability template is the source having a real value. unknown and unavailable do not become zero, and they do not become the offset alone.
  4. Two sensors. The second blueprint takes sensor A and sensor B. Subtract is A − B. Add is A + B. If either side is unavailable, the result is unavailable. Set the unit and device class to match A. The blueprint does not convert °C to °F. Both sensors need to already be in the same unit.
  5. One import, many entities. Calibrating temperature and humidity is two template entities from the same blueprint, with two different sources and two different offsets.

docs/calibration-example.yaml is an example, not a helper package. It shows a room sensor that reads 1.7 degrees high, a humidity that reads 8 points high, and an indoor-outdoor difference. It is not loaded for you.

How to measure the offset

Put the cheap sensor and a reference thermometer in the same still air, out of the sun and away from a vent, a lamp, or a PC. Wait about 20 minutes. Offset = reference − cheap reading. A module that reads 23.1 while the reference reads 21.4 needs an offset of −1.7 and a multiplier of 1.

Do the same for humidity if you have a reference hygrometer. An offset of −8 means the module reads 8 points high. Use a multiplier only when the error grows with the reading (the module reads 80 in a room that is 70: multiplier 0.875, offset 0). If you are not sure, leave the multiplier at 1 and correct with the offset.

Write the temperature offset on the temperature entity and the humidity offset on the humidity entity. One number cannot correct both.

Snippet

The calibrated state. Inputs land in variables on the template entity.

sensor:
  state: >
    {% set raw = states(source) | float(none) %}
    {% if raw is none %}
      none
    {% else %}
      {% set value = raw * (multiplier | float(1)) + (offset | float(0)) %}
      {{ value | round(round_digits | int(1)) }}
    {% endif %}
  availability: "{{ has_value(source) }}"

A difference is the same shape with two sources: A − B, or A + B when the operation input is add.

Setup outline

  1. Copy both files from blueprints/template/ into config/blueprints/template/edotdev/. Reload blueprints.
  2. Create a template entity from Calibrated sensor. Pick the temperature source. Enter the offset you measured. Leave the multiplier at 1 unless you measured a scale error. Set the unit to the source unit and the device class to temperature.
  3. Create a second entity from the same blueprint for humidity, with its own offset. Set the unit to % and the device class to humidity.
  4. Create a template entity from Sum or difference of two sensors if you want indoor minus outdoor, or one room minus another. Pick A and B in the same unit. Choose subtract or add. Set the unit and device class to match A.
  5. Check Developer tools → States. Pull the source offline (unplug the node, or disable the entity). The calibrated sensor should go unavailable, not sit on the last number. Restore the source and confirm the offset is still applied.

Troubleshooting

  • The number is off by the offset twice. Another template, or a filter on the device, is already correcting the same source. Calibrate the raw sensor, not a sensor that is already adjusted.
  • It reads zero when the node is offline. The entity was created as a normal template with float(0), or the availability box was cleared. The blueprint uses has_value. Recreate it from the blueprint if the availability template was edited out.
  • Humidity shows as a temperature. The device class was left at the default, which is temperature. Set it to humidity and the unit to %.
  • The difference is huge. A and B are in different units, or one of them is already a delta. The blueprint does not convert units.
  • February-style “it updated once.” Template entities update when the source updates. A sensor that only reports every few minutes will look frozen. That is the source, not the offset.
  • The example file did nothing. It lives under docs/. Create the entities from the blueprints, or paste the example only after you change the entity ids.

Credits

The offset sensor and the two-sensor sum follow Simple adjusted value sensor and Add and subtract states sensor.

Changelog

v1.0 · Nov 2, 2026: First publish.