From d0b6ea0e1a848c2f5817c9fe7c690f56023fbda6 Mon Sep 17 00:00:00 2001 From: Julian Pawlowski Date: Wed, 8 Apr 2026 08:01:16 +0000 Subject: [PATCH] fix(sensors)!: fix DURATION sensors displaying in minutes instead of hours Added `suggested_unit_of_measurement=UnitOfTime.HOURS` to all 7 DURATION sensors to prevent HA from auto-selecting minutes as the display unit. Without this, HA would pick "min" for small values (e.g., 0.75 h) and then display large values as "1238 Min." instead of the intended "20 Std. 38 Min." Affected sensors: - trend_change_in_minutes - best_price_period_duration / peak_price_period_duration - best_price_remaining_minutes / peak_price_remaining_minutes - best_price_next_in_minutes / peak_price_next_in_minutes BREAKING CHANGE: Sensor state unit changes from minutes to hours for users whose entity registry stored "min" as the display unit (the previous default). Automations using the raw state value (e.g., `state < 60` for "less than 60 minutes") must be updated to use hours (e.g., `state < 1`). The state attributes `remaining_minutes` and `next_in_minutes` continue to provide integer minutes and are unaffected. Impact: Duration sensors now display dynamically as "X h Y min" (e.g., "1 h 15 min") instead of a large minutes value like "1238 Min.". Users who manually customized the unit in HA settings are not affected. --- custom_components/tibber_prices/sensor/definitions.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/custom_components/tibber_prices/sensor/definitions.py b/custom_components/tibber_prices/sensor/definitions.py index f6ed421..8dd956e 100644 --- a/custom_components/tibber_prices/sensor/definitions.py +++ b/custom_components/tibber_prices/sensor/definitions.py @@ -524,6 +524,7 @@ FUTURE_TREND_SENSORS = ( icon="mdi:timer-outline", device_class=SensorDeviceClass.DURATION, native_unit_of_measurement=UnitOfTime.HOURS, + suggested_unit_of_measurement=UnitOfTime.HOURS, state_class=None, # Countdown timer: no statistics suggested_display_precision=2, entity_registry_enabled_default=True, @@ -685,6 +686,7 @@ BEST_PRICE_TIMING_SENSORS = ( icon="mdi:timer", device_class=SensorDeviceClass.DURATION, native_unit_of_measurement=UnitOfTime.HOURS, + suggested_unit_of_measurement=UnitOfTime.HOURS, state_class=None, # Duration not needed in long-term statistics suggested_display_precision=2, entity_registry_enabled_default=False, @@ -695,6 +697,7 @@ BEST_PRICE_TIMING_SENSORS = ( icon="mdi:timer-sand", device_class=SensorDeviceClass.DURATION, native_unit_of_measurement=UnitOfTime.HOURS, + suggested_unit_of_measurement=UnitOfTime.HOURS, state_class=None, # Countdown timers excluded from statistics suggested_display_precision=2, ), @@ -719,6 +722,7 @@ BEST_PRICE_TIMING_SENSORS = ( icon="mdi:timer-outline", device_class=SensorDeviceClass.DURATION, native_unit_of_measurement=UnitOfTime.HOURS, + suggested_unit_of_measurement=UnitOfTime.HOURS, state_class=None, # Next-start timers excluded from statistics suggested_display_precision=2, ), @@ -738,6 +742,7 @@ PEAK_PRICE_TIMING_SENSORS = ( icon="mdi:timer", device_class=SensorDeviceClass.DURATION, native_unit_of_measurement=UnitOfTime.HOURS, + suggested_unit_of_measurement=UnitOfTime.HOURS, state_class=None, # Duration not needed in long-term statistics suggested_display_precision=2, entity_registry_enabled_default=False, @@ -748,6 +753,7 @@ PEAK_PRICE_TIMING_SENSORS = ( icon="mdi:timer-sand", device_class=SensorDeviceClass.DURATION, native_unit_of_measurement=UnitOfTime.HOURS, + suggested_unit_of_measurement=UnitOfTime.HOURS, state_class=None, # Countdown timers excluded from statistics suggested_display_precision=2, ), @@ -772,6 +778,7 @@ PEAK_PRICE_TIMING_SENSORS = ( icon="mdi:timer-outline", device_class=SensorDeviceClass.DURATION, native_unit_of_measurement=UnitOfTime.HOURS, + suggested_unit_of_measurement=UnitOfTime.HOURS, state_class=None, # Next-start timers excluded from statistics suggested_display_precision=2, ),