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”…
see Outside WiFi weather station "WS3500" and local customized upload (no cloud needed)
presently I just grab the GET-Values and throw them blindly at the REST-API (with a prefix). Someplace I have to have some logic… So either in the PHP, so I have explicit actions on the GET-variable (like adding |°F or |inch), or I just add the logic in rules…
Ok. I don’t know PHP, but can’t you just create another key-value pair containing the units. Then concatenate the value and unit when you call the REST API?
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.
played around a bit, but adding “|°F” to my API-call just threw this warning:
2020-05-16 13:50:38.785 [WARN ] [rest.core.internal.item.ItemResource] - Received HTTP POST request at 'items/Weatherstation_indoortempf' with an invalid status value '77.4|°F'.
But just to get this straight in my head:
my locale is set to metric
in my items, I defined the “Number:Temperature” as “…%unit%”
if I update the item via REST with the “|°F” suffix (?), it should automatically update the value to Celsius?
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…