Add Nautical Miles as a valid unit for 'distance' device class

I have an AIS receiver and plot the maximum range that I can detect vessels, however this is returned from the unit in Nautical Miles (1,852m) and HA doesn’t accept this as a valid device class

ValueError: Sensor sensor.ais_catcher_max_range_last_hour has device class ‘distance’, state class ‘None’ unit ‘nmi’ and suggested precision ‘None’ thus indicating it has a numeric value; however, it has the non-numeric value: ‘None’ (<class ‘str’>)

Given that speed is already allowed in knots (kn) which are equal to 1NM per hour, this seems like an oversight.

Acceptable abbreviations for Nautical Mile include (NM - uppercase to distinguish from nanometers), nmi or possibly ‘M’ but I figure the last one could be easily confused with metre or statute miles.

Don’t forget to vote for your request :slight_smile:

I just wanted to bring up the same!

I also have an AIS receiver and it spits out the distance of a vessel in nautical miles. I have to convert it like this:

      - name: "rsk450ni_md.maximum_distance"
        unit_of_measurement: "km"
        state: "{{ state_attr('sensor.rsk450ni_md', 'maximum_distance') * 1.852 }} "
        unique_id: rsk450ni_md.maximum_distance
        state_class: measurement
        device_class: distance

to be able to properly use it in HA!

The exchange rate is: 1 nautical miles equals 1852 meters (one thousand eight hundred fifty two meters).

Abbreviation should be “NM”, see here.

Since I’m working on an AIS receiver integration (Add AIS tracker integration by mib1185 · Pull Request #123956 · home-assistant/core · GitHub) to be added to HA core, why not also add nautical miles to HA unit conversion system :sunglasses:

Neccessary architectual discussion about entity model change started:

The architectural discussion has been approved and the corresponding PR #124723 is merged. It will be available in 2024.11

1 Like