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