This is a solution, somehow. but in my eyes not the correct one. Why should I configure the unit, when it is maintained correctly by OH?
In my eyes not the right field in the item’s JSON is used.
For my Netatmo station I have confgured a bunch of items (in an .items file). For the temperature the OH unit °C is used, so I have not configured a unit. The CO2 is dimensionless, so set the unit=“ppm”.
Via the API one gets the following values:
{
"link": "http://ohdev4:8080/rest/items/Netatmo_WZ_Temperatur",
"state": "20.2 °C",
"stateDescription": {
"pattern": "%.1f °C",
"readOnly": false,
"options": []
},
"unitSymbol": "°C",
"editable": false,
"type": "Number:Temperature",
"name": "Netatmo_WZ_Temperatur",
"label": "Temperatur",
"category": "temperature",
"tags": [],
"groupNames": []
}
and
{
"link": "http://ohdev4:8080/rest/items/Netatmo_WZ_Co2",
"state": "813 ppm",
"stateDescription": {
"pattern": "%d ppm",
"readOnly": true,
"options": []
},
"unitSymbol": "ppm",
"metadata": {
"unit": {
"value": "ppm"
}
},
"editable": false,
"type": "Number:Dimensionless",
"name": "Netatmo_WZ_Co2",
"label": "CO2",
"category": "carbondioxide",
"tags": [],
"groupNames": []
}
Only in the second case metadata.unit.value is provided as “ppm”.
But, in both cases the field unitSymbol contains the right symbol, “°C” and “ppm”, independent of whether it is configured explicitly or not.
After setting the unit of Netatmo_WZ_Temperatur to “°F” manually in the .items file, which leads to
2024-03-02 11:36:01.037 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Netatmo_WZ_Temperatur' changed from 20.2 °C to 68.18 °F
one gets (I forgot to change the label)
{
"link": "http://ohdev4:8080/rest/items/Netatmo_WZ_Temperatur",
"state": "68.180 °F",
"stateDescription": {
"pattern": "%.1f °C",
"readOnly": false,
"options": []
},
"unitSymbol": "°F",
"metadata": {
"unit": {
"value": "°F"
}
},
"editable": false,
"type": "Number:Temperature",
"name": "Netatmo_WZ_Temperatur",
"label": "Temperatur",
"category": "temperature",
"tags": [],
"groupNames": []
}
both the unitSymbol and metadata.unit.value contain “°F”.
So in my eyes the best solution is that HABapp evaluates “unitSymbol” and not “metaData”.“unit”.“value”.
Then there is no need to maintain the “unit” field in the items file in most cases.