REST API value Formatting

Dear all,

I am interacting with OpenHAB through a self-developed AngularJS web application using the REST API.

So far so good, all works. However I do have one annoying behavior where I am not sure if I am the problem, or if the REST API has a specific behavior: value formatting.

If I retrieve e.g. Netatmo pressure data OpenHAB is sending a string incl unit of measure - hPa in this case: 1013.9000244140625 hPa

I would prefer 1013,900…. (using my local / regional formatting with , vs . and not having the string).

Is there a way to simply get the plain number values (especially for decimals) w/o unit or any other string elements? Would love to avoid having to „clean & transform“ any incoming string on AngularJS side to use the numbers for some calculations or conditional formatting…

If not it is not a big deal but wanted to consult with you prior to writing more code for something that might just be a mistake of use on my end.

Thx

  • Jens

There are a class of Number Items that have Units of Measurement. The state for those Items almost always carry the units along with the number to make up the state. This isn’t mere formatting. For example, one could compare a number carrying 20 °C and another one carrying 70 °F and get the right answer.

So you cannot really do anything about the units. It’s part of the Item’s state, carries meaning, and therefore it is not something you can just turn off.

As for the localization I am not sure. I suspect the answer is you can’t do much about that either but I can’t say that for sure. I know the issue is handled in OH’s UIs somehow but I don’t know if that’s implemented in the browser or somehow the localization is applied at the REST API level.

Thx @rlkoshak - will then transform the item state values in AngularJS when I read them from the Rest-API!

openHAB does server-side formatting and transformation for the regular UIs. They have a choice of presenting “raw” Item state or formatted state.

And this is something I can configure?

Most likely. Check the REST API for an Item with some state presentation. Or look to see how HABpanel does it, where the choice is user configurable.