How can my integration set all of my sensor units to Celsius for all users

3D printers (the people using them) now almost universally use Celsius, not Fahrenheit. When my integration is being configured I’d like to default all the temperature units to Celsius and possibly also all length measurement units to mm to match that expectation so that few to no users need to do that manually for a whole bunch of sensors.

Is there a way an integration can do that?

http://homeassistant:8123/config/general

it should use your default config from homeassistant , unless your printer had a value settings

It does. That’s the problem. Everyone wants the integration to show temperature in Celsius because that is standard for the 3D printer community even when it’s not the standard for their country (US). So everyone in has to go change the many sensors over to Celsius individually.

Have you thought using a template sensor?

template:
  - sensor:
      - name: "Temperatura en Celsius"
        unit_of_measurement: "°C"
        state_class: measurement
        device_class: temperature
        state: >
          {% if states('sensor.temperatura_fahrenheit') not in ['unknown', 'unavailable'] %}
            {{ ((states('sensor.temperatura_fahrenheit') | float - 32) * 5 / 9) | round(2) }}
          {% else %}
            unknown
          {% endif %}


They are talking about overriding the unit in an integration they are writing. Not configuration.

The developer docs list a suggested_unit_of_measurement property.

See: Sensor entity | Home Assistant Developer Docs

The unit of measurement to be used for the sensor’s state. For sensors with a unique_id, this will be used as the initial unit of measurement, which users can then override. For sensors without a unique_id, this will be the unit of measurement for the sensor’s state. This property is intended to be used by integrations to override automatic unit conversion rules, for example, to make a temperature sensor always display in °C regardless of whether the configured unit system prefers °C or °F, or to make a distance sensor always display in miles even if the configured unit system is metric.

1 Like

That sounds perfect and exactly what I am wanting to do. I will try it and reply here if it works as advertised.

Yes, it works! Oddly the writable ‘number’ entities are already defaulting to celsius which I’d not noticed until now. And those don’t support the setting - it’s limited to sensor entities by the looks of it.

1 Like