Use Units of Measurement conversion in main UI

Hello everyone,

I am currently looking into integrating an ETA for my daily commute on my main UI overview page.
The information is retrieved from the HERE routes API using the new HTTP binding and a JSONPATH.

Thing  http:url:hereLocation "HERE Location" [ baseURL=",6.0&destination=51.1,7.0&return=summary,mlDuration", refresh=30] {
        Type number : Duration "Duration" [ stateTransformation="JSONPATH:$.routes[:1].sections[:1].summary.mlDuration" ]

The duration is returned in seconds. So I have created an item for the duration channel with Time as Unit of Measurement and declared also seconds within the label.

Number:Time LocationDuration "Location Duration [%d s]"  {channel="http:url:hereLocation:Duration"}

The step I am missing now is how I can change the displayed unit in my main UI. For previous version of OpenHAB where a sitemap file was used, the label could just be adapted to “Location Duration [%d min]” which then did the conversion. In the new main UI, I am looking to getting this duration displayed within a list using the oh-label-item component. There is no attribute that would allow me to change how the item is displayed though. Or am I missing something?

Thanks in advance!

There is a metadata you can set called something like State formatting. Set that metadata with the same thing you would set for the label minus the [ ].

%d min

I actually tried to set the state description to %d min in the UI settings when editing the item as well as in the item definition.

Number:Time LocationDuration "Location Duration [%d s]" {channel="http:url:hereLocation:Duration", stateDescription=" " [readOnly=true, pattern="%d min"]}

But then the seconds value retrieved from the API is just displayed with “min” appended. So it’s not being converted.
I really like the idea of OpenHAB having knowledge of the unit, but putting this to use is not as easy as it should be.
Any other ideas? Otherwise, I would just add a conversion to minutes in the thing declaration as some kind of transformation I guess.

1 Like