I’m having difficulties to understand the UoM-concept in terms of items not attached to a binding and things. As I understand, if a binding is configured and updates states, you can define the “origin” unit for the binding and then I can decide in the item-definition, if I want another unit. So e.g. my binding collects sensors in imperial measures, I can easily display them in the item as metric measures.
When you update your item you specify the units (e.g. 21|°F) and when you display the item, you specify the unit in the item or sitemap label (e.g. "Temp [%.1f °F]"). Alternatively, if you have the openHAB regional settings configured to use Metric, you should just be able to do "Temp [%.1f %unit%]"
Edit: I apologize if there are any typos in the above. It’s still early and I haven’t had much coffee yet).
So I’ll have a look into the “77|°F” option, because right now, I have the locale set to metric - so an update is supposed to be in Celsius. So my PHP-Script would be a way more complex - so I’ll guess I stick to having double items and update the metric ones “onUpdate”…
The update will be in whatever units you supply. That’s what you tell it, that’s what goes into the state.
When you come to read out the state, for display or for processing in a rule etc., it is up to you to take note of whatever units it is in -or- to request it in the units of your choice (for auto conversion).
For REST API, you’ll probably have to study how a UI does it using [label format] options.
curl -X POST --header "Content-Type: text/plain" --header "Accept: application/json" -d "14°F" "http://192.168.178.10:8080/rest/items/Weatherstation_indoortempf"
=> resulted in:
2020-05-16 18:03:28.523 [vent.ItemStateChangedEvent] - Weatherstation_indoortempf changed from 74.8 °C to -10.00 °C
of course, it’s not freezing cold inside => but you can see, it worked. Thing is… Now I already rewrote everything to fit - but I won’t need the wrong units anyways, so I just refactored everything from scratch…
one thing needed a bit tweaking, though. The “base unit” for “length” for metric is “meter”, for imperial is “inch”. So if the weatherstation sends “0.252 inch” of rain, it gets translated to “0.0 meter” of rain. Which should be “0.6mm” of rain. So I hat to change the Unit in the items from %unit% to mm - and it worked also…