Skip to content

Unit of Measurement of Output Sensor is wrong #124

Closed

Description

@ajvdw

Since the output sensor can be freely defined. The percentage does not make sense as a unit of measurement.

class PIDOutputSensor(
    CoordinatorEntity[PIDDataCoordinator], RestoreEntity, SensorEntity
):
    """Sensor representing the PID output."""

    def __init__(
        self, hass: HomeAssistant, entry: ConfigEntry, coordinator: PIDDataCoordinator
    ):
        super().__init__(coordinator)

        name = "PID Output"
        key = "pid_output"

        BasePIDEntity.__init__(self, hass, entry, key, name)

        **self._attr_native_unit_of_measurement = "%".**  
        self._attr_state_class = SensorStateClass.MEASUREMENT

    async def async_added_to_hass(self):
        await super().async_added_to_hass()
        if (state := await self.async_get_last_state()) is not None:
            try:
                value = float(state.state)
                self._handle.last_known_output = value
            except (ValueError, TypeError):
                self._handle.last_known_output = 0.0

    @property
    def native_value(self) -> float | None:
        if self.coordinator.data is None:
            return None
        return round(self.coordinator.data, 2)

Activity

  1. bvweerd commented on Jan 7, 2026

    @bvweerd
    Owner

    Thanks for noticing. The reason for having a unit is that without a unit long-term statistics will not be recorded for the entity. During design I have seen this as a valuable addition to the sensor, that's why it has received the % as a unit.

  2. ajvdw commented on Jan 7, 2026

    @ajvdw
    Author
  3. bvweerd commented on Jan 7, 2026

    @bvweerd
    Owner

    solved in v1.5.2

  4. ajvdw commented on Jan 7, 2026

    @ajvdw
    Author

    solved in v1.5.2

    Looks like the reported version number is not changed (still 1.4.2)

  5. bvweerd commented on Jan 7, 2026

    @bvweerd
    Owner

    fixed as well, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions