The problem is I have no idea where I can set up the units of measurement. Every things and items were added in Main UI. According to the release notes of OH 4 all should be converted by the upgrade scripts.
I added information about units in the places I could. For example, it was very easy for mqtt. I set up it in the channel configuration:
- id: batteryLevel
channelTypeUID: mqtt:number
label: Battery Level
description: Remaining battery in %.
configuration:
unit: "%"
min: 0
stateTopic: zigbee2mqtt/XiaomiAqaraMotionSensor009
transformationPattern: JSONPATH:$.battery
max: 100
I have an item linked to the channel with default conversion:
label: Battery Level
type: Number:Dimensionless
category: batterylevel
groupNames:
- XxxxxxMotionSensor
groupType: None
function: null
tags:
- Status
- Level
It displays the same value as before upgrade (the difference only in logs I wrote before): “97 %”
The situation with things bound to Mi Home is different.
I have the thing:
UID: mihome:sensor_motion_aq2:158dxxxxxxxxxx
label: Xiaomi Aqara Motion Sensor 002
thingTypeUID: mihome:sensor_motion_aq2
configuration:
itemId: 158dxxxxxxxxxx
bridgeUID: mihome:bridge:xxxxxxxxxxxx
The thing has several channels:
<?xml version="1.0" encoding="UTF-8"?>
<thing:thing-descriptions bindingId="mihome"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:thing="https://openhab.org/schemas/thing-description/v1.0.0"
xsi:schemaLocation="https://openhab.org/schemas/thing-description/v1.0.0 https://openhab.org/schemas/thing-description-1.0.0.xsd">
<thing-type id="sensor_motion_aq2">
<supported-bridge-type-refs>
<bridge-type-ref id="bridge"/>
</supported-bridge-type-refs>
<label>Xiaomi Aqara Motion Sensor</label>
<description>Sensor that detects movement. Also called Occupancy Sensor or Human Body Sensor. After it detects motion,
it goes to sleep for 1 minute.</description>
<channels>
<channel id="motion" typeId="motion"/>
<channel id="illumination" typeId="illumination"/>
<channel id="motionOffTimer" typeId="motionOffTimer"/>
<channel id="lastMotion" typeId="lastMotion"/>
<channel id="batteryLevel" typeId="system.battery-level"/>
<channel id="lowBattery" typeId="system.low-battery"/>
</channels>
<config-description-ref uri="thing-type:mihome:device"/>
</thing-type>
</thing:thing-descriptions>
I have an item linked to “batteryLevel” channel with default conversion:
label: Battery Level
type: Number:Dimensionless
category: Battery
groupNames:
- YyyyyyyXiaomiAqaraMotionSensor
groupType: None
function: null
tags:
- Status
- Level
It displays the wrong value after upgrade : “8300 %”
I thought that “system.battery-level” is a system-channel type which should provide right units of measure. And it provides something, otherwise the UI display “one”, but it displayes “%”.
I tried to define unit of metadata for the item as you adviced, but UI does not allow it (I have done it for group aggregation items and it helped there, thanks for the advice). I think it is becase the unit of measure was provided by channel.
It look like a bug, but I hard to belive nobody found it since 4.0 was released. Maybe I do something wrong?