Change an Item to display Miles instead of Km

Currently on OH 3.4.2

My Electric MINI displays the Range Item in KM but I would like Miles
I use MainUI with Location cards created from the Semantic Model for all displays.
I’m assuming I could put a Pattern in the Item Metadata to do the transformation, or do I need a Rule?
The documentation says use the Java formatter class syntax, so that is where I get lost.
Is it simply creating an equation that is Km*.62=miles?
Any advice would be appreciated.

1 Like

The documentation says to use the new unit metadata

In some cases the system default unit may not be the most useful unit for a given quantity. For measuring precipitation km/h would be a quite uncommon unit, while mm/h would be the expected unit. You can set the unit metadata to a different unit to change the item’s unit:

Number:Speed "Rainfall" { unit="mm/h" }

If you prefer imperial measurement simply set it to default (Main UI → Administration → Settings → Regional Settings → Show Advanced → Measurements → Imperial).

Thanks
Unfortunately the documentation does not address how to do it when Items are created in the MainUI not file based.
(Sadly this is a very common issue with our docs)
How do I define Unit= in the MainUI environment?

I prefer to use SI as the system default but only for Item I would like to change.

Unit is the first option under Add Metadata for every Item.

Edit: Sorry, just saw you are still on oh3, so unit is not avalable at all I am afraid.

so not possible in OH3?

Finally maybe a good reason to consider OH4!

Correct, Unit metadata and complete rework of UoM was introduced with openHAB 4.

Just to summarize here:

OH 3

Navigate to the Item. Click “Add metadata” and choose “State Description”. In the “Pattern” field add %.1 mi. That will convert the km to mi with one decimal place.

In OH 3 the State Description Pattern serves multiple purposes. Pay close attention that stuff like restore on startup and the charts are working as expected.

OH 4

Navigate to the Item. Click “Add metadata” and choose “Unit”. In the field put mi. Optionally add “State Description” with either %.1 mi or %.1 %unit% to limit the display to one decimal point.

In OH 4 unit controls the units of the Item’s state.These are the units that get saved and restored from persistence, served up over the REST API and what you will find in rules. The State Description Pattern only controls how the state of the Item is displayed in MainUI.

Thanks for the deeper explanation.
I tried it on OH3.4.2 and it didn’t work

value: " "
config:
  pattern: "%.1 mi."
  readOnly: true

Even after a restart.

What specifically do you mean by “didn’t work”? That pattern is not used everywhere in MainUI (notably the Items page). Where did you look?

Did the Item update after setting the pattern? Many changes like that do not get applied until the next update to the Item.

I added that pattern to the Item and it did Save.
Item still displayed km
Re-started OH but remained km
I will try to force an update by plugging in the car

Edit: Forcing up update made no difference

Where? Again, that pattern will not apply everywhere. You will always see km on the Items page. You will always see km on any widget that uses .state instead of .displayState. events.log I think will always show km in OH 3 (it might become mi during restoreOnStartup).

On the Location card for the Garage I have a Point
image

Still displays km

I’ve confirmed that Pattern is present on that Item.
There is no Category or Semantic Property for that Item, but that should not matter, correct?

There has to be at least one semantic tag or else the Item would not appear in the Semantic model at all and would not show up on the Location card.

The category doesn’t matter and for this, the semantic tag doesn’t really matter either.

This does show though why the whole unit of measurement needed a rework for OH 4 though.

Can I assume this Item doesn’t have a Default List Item Widget defined?

If not :person_shrugging: . I’ve been on OH 4 long enough now I don’t know where else to look. With a State Description Pattern of %.1f mi it should show the value in miles on the location card.

Actually got something working.

With a State Description Pattern of %.1f mi it should show the value in miles on the location card.

The Pattern was different in your last reply.
%.1f mi. at least it now displays miles but doesn’t convert the number.

This is for sure a Number:Length type Item? It’s not just a Number?

From what I can see the channel is defined Number:Length as well as the Item.

Not sure where else to check besides the GUI
All my cards are created automatically from the Semantic Model.

I think my next step is to update my Staging system (where this Binding lives right now) from 3.4.2 to 4.X

We’ve had previous discussions about the complexity of that move but it has to be done eventually. The family seems to have low tolerance for testing on the Production system!

Thanks for your help on this.

Are you by chance using Firefox? If so there is a known caching problem in Firefox. Sometimes you need to force a full reload of MainUI to see certain changes. There’s an issue open but no solution besides this workaround at the moment.

Strictly Google Chrome and iOS app