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.
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:
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?
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.
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.
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).
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.