TeslaLogger icon indicating copy to clipboard operation
TeslaLogger copied to clipboard

fix: Add unit_of_measurement to time_to_full_charge MQTT sensor

Open qudiqudi opened this issue 1 month ago • 2 comments

The time_to_full_charge sensor was being published with device_class 'duration' but without a unit_of_measurement, causing Home Assistant to log an error.

This adds 'h' (hours) as the unit_of_measurement to comply with Home Assistant's requirements for duration sensors. The Tesla API returns time_to_full_charge in hours as a decimal value.

Fixes Home Assistant error: Entity is using native unit of measurement 'None' which is not a valid unit for the device class ('duration')

qudiqudi avatar Dec 07 '25 15:12 qudiqudi

Problem

The time_to_full_charge sensor was being published with device_class: "duration" but without a unit_of_measurement, causing Home Assistant to log the following error:

Entity sensor.xxx_time_to_full_charge is using native unit of measurement 'None' which is not a valid unit for the device class ('duration'); expected one of ['h', 'μs', 's', 'min', 'd', 'ms']

Solution

Added unit_of_measurement: "h" to the MQTT auto-discovery configuration for the time_to_full_charge sensor.

Rationale

  • Tesla API returns time_to_full_charge in hours (as a decimal value)
  • TeslaLogger passes this value through without conversion
  • Home Assistant requires a valid unit for sensors with device_class: "duration"

Testing

  • Verified the fix matches the pattern of other duration sensors in the codebase
  • Confirmed the Tesla API documentation specifies hours as the unit

Files Changed

  • TeslaLogger/MQTTAutoDiscovery.cs - Added unit configuration on line 107

qudiqudi avatar Dec 07 '25 15:12 qudiqudi

@Adminius could you please test it?

bassmaster187 avatar Dec 08 '25 10:12 bassmaster187

@Adminius could you please test it?

approved!

Adminius avatar Dec 15 '25 08:12 Adminius