UoM Behavior I don't understand

  • Platform information:
runtimeInfo:
  version: 4.0.2
  buildString: Release Build
locale: en-US
systemInfo:
  configFolder: /etc/openhab
  userdataFolder: /var/lib/openhab
  logFolder: /var/log/openhab
  javaVersion: 17.0.7
  javaVendor: Raspbian
  osName: Linux
  osVersion: 6.1.21-v8+
  osArchitecture: arm
  availableProcessors: 4
  freeMemory: 112259504
  totalMemory: 778567680
  startLevel: 100
bindings: null
clientInfo:
  device:
    ios: false
    android: false
    androidChrome: false
    desktop: true
    iphone: false
    ipod: false
    ipad: false
    edge: false
    ie: false
    firefox: false
    macos: false
    windows: true
    cordova: false
    phonegap: false
    electron: false
    nwjs: false
    webView: false
    webview: false
    standalone: false
    os: windows
    pixelRatio: 1.5
    prefersColorScheme: light
  isSecureContext: false
  locationbarVisible: true
  menubarVisible: true
  navigator:
    cookieEnabled: true
    deviceMemory: N/A
    hardwareConcurrency: 8
    language: en-US
    languages:
      - en-US
      - en
    onLine: true
    platform: Win32
  screen:
    width: 1707
    height: 1067
    colorDepth: 24
  support:
    touch: false
    pointerEvents: true
    observer: true
    passiveListener: true
    gestures: false
    intersectionObserver: true
  themeOptions:
    dark: light
    filled: true
    pageTransitionAnimation: default
    bars: filled
    homeNavbar: default
    homeBackground: default
    expandableCardAnimation: default
  userAgent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML,
    like Gecko) Chrome/116.0.0.0 Safari/537.36
timestamp: 2023-08-27T14:16:20.749Z

  • Issue of the topic: I am in the process of creating new items using a consistent structure so that I can process them using one rule that is able to glean needed information from the item name, inspired by Design Pattern: Working with Groups in Rules.

When I created a new item for an iPhone Thing’s Location Accuracy Channel, it did not behave as I expected from reading the documentation, and from how the Item it is intended to replace behaves.

The Channel is Number (dimensionless). I want a Quantity with a unit to ensure consistency in other calculations.

The old Item, to which I had added the Unit metadata “m” works as expected. The new Item that I created using the “Add Items from Textual Definition” Developer Tool included {Unit=“m”}, appears to be treating the channel input as inches (default for my locale) and converting it to the unit specified in the metadata.

From the UI Channel view of the Thing:

The Items looks the same:
Old:


New:

In the events log, it is clear that the new one is thinking in inches:

2023-08-27 08:33:48.534 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Midway_MLE_Watch_Accuracy' changed from 12.156181357471018 in to 44.00847666450469 in
2023-08-27 08:38:49.784 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Emilys_Apple_Watch_Apple_Watch_SE_Location_Accuracy' changed from 44.00847666450469 m to 12.156181357471018 m

Based upon Units Of Measurement | openHAB
" In case you set a different unit (see above, e.g. km ) that is taken and the item will set it’s state to 5 km.", I would expect that in both cases my Items would get the same behavior and the dimensionless number received from the channel would be taken as in the unit specified in the metadata.

I created a new Item using the UI “Add Link to Item”, create a new item. I created it as the default Number item. It displayed the same number as the old item, but without the unit. Then I edited the Item and changed the Type to Number:Length, and added Unit metadata “m”. At first it displayed the same number and unit as the new item, but after the next update from the channel, it displayed the same number and unit as the old item (and which is the correct data).

Based on the above, I tried changing the new Item type to Number. It immediately displayed the same number as the old item, but without units. I couldn’t figure out how to remove the Unit metadata. I then edited it again back to Number:Length. Unfortunately, it returned to the original behavior and is treating the channel input as inches and converted it to meters.

I’m sure I’m missing something, but can’t figure it out. It seems odd that creating a Number:Length Item with Unit metadata yields a different result than creating a Number Item and then changing it to Number:Length and adding the unit metatdata. I guess it is a path function.

Wait, do you really mean Number:Dimensionless which represents one of the ratio units like %, db, etc or do you mean a Number Item without units?

If you mean a Number without units (i.e. defined a Number) than no units come into play. If the binding sends a value with unit to it, those are thrown away. No conversions take place, even if unit metadata is defined.

Show the Channel and in particular what units, if any it is documented to publish.

Number , without units.

Not completely sure what to show about the channel, but this is what it shows when trying to link a new item.

The iCloud Binding documentation for this channel lists:

Channel ID Type Description
locationAccuracy Number Accuracy of the last position report (Advanced Option on UI)

Item data from API Explorer

{
  "link": "http://oh-m:8080/rest/items/Emilys_Apple_Watch_Apple_Watch_SE_Location_Accuracy",
  "state": "13.669083742842584 m",
  "stateDescription": {
    "pattern": "%d m",
    "readOnly": true,
    "options": []
  },
  "unitSymbol": "m",
  "metadata": {
    "unit": {
      "value": "m"
    },
    "semantics": {
      "value": "Point",
      "config": {
        "isPointOf": "Emilys_Apple_Watch_Apple_Watch_SE"
      }
    }
  },
  "editable": true,
  "type": "Number:Length",
  "name": "Emilys_Apple_Watch_Apple_Watch_SE_Location_Accuracy",
  "label": "Location Accuracy",
  "category": "",
  "tags": [
    "Point"
  ],
  "groupNames": [
    "Emilys_Apple_Watch_Apple_Watch_SE"
  ]
}
{
  "link": "http://oh-m:8080/rest/items/Midway_MLE_Watch_Accuracy",
  "state": "13.669083742842584 in",
  "stateDescription": {
    "pattern": "%d m",
    "readOnly": true,
    "options": []
  },
  "unitSymbol": "in",
  "metadata": {
    "semantics": {
      "value": "Point",
      "config": {
        "isPointOf": "Emilys_Apple_Watch_Apple_Watch_SE"
      }
    },
    "Unit": {
      "value": "m"
    }
  },
  "editable": true,
  "type": "Number:Length",
  "name": "Midway_MLE_Watch_Accuracy",
  "label": "Midway MLE Watch Accuracy",
  "category": "",
  "tags": [
    "Point"
  ],
  "groupNames": [
    "Emilys_Apple_Watch_Apple_Watch_SE"
  ]
}
{
  "link": "http://oh-m:8080/rest/items/Emilys_Apple_Watch_Apple_Watch_SE_Location_Accuracy_Test",
  "state": "13.669083742842584 m",
  "stateDescription": {
    "pattern": "%d m",
    "readOnly": true,
    "options": []
  },
  "unitSymbol": "m",
  "metadata": {
    "unit": {
      "value": "m"
    },
    "semantics": {
      "value": "Point"
    }
  },
  "editable": true,
  "type": "Number:Length",
  "name": "Emilys_Apple_Watch_Apple_Watch_SE_Location_Accuracy_Test",
  "label": "Location Accuracy",
  "category": "",
  "tags": [
    "Point"
  ],
  "groupNames": []
}

From the above, the middle one, which is the one not behaving as I would like, has “unitSymbol” of “in”, which I think explains the behavior: the item receives a number from the channel, which it treats as inches but displays in meters.

I experimented with adding different items with different Item types to see what would happen.
This one was created as a Number Item, which is what the State shows. But somehow it picked up a pattern to display it as meters, which it doesn’t do - it just displays the number received from the channel as one would expect.

{
  "link": "http://oh-m:8080/rest/items/Emilys_Apple_Watch_Apple_Watch_SE_Location_Accuracy_Test3",
  "state": "12.290919273131488",
  "stateDescription": {
    "pattern": "%d m",
    "readOnly": true,
    "options": []
  },
  "metadata": {
    "semantics": {
      "value": "Point"
    }
  },
  "editable": true,
  "type": "Number",
  "name": "Emilys_Apple_Watch_Apple_Watch_SE_Location_Accuracy_Test3",
  "label": "Location Accuracy",
  "category": "",
  "tags": [
    "Point"
  ],
  "groupNames": []
}

I have tried enough different approaches that I may be confused, but it seems that if I add an Item in the UI as a Number:Length Item, the unitSymbol, unit metadata and pattern all use “m” (%d m" for the pattern). If I create a Number Item in the UI and then edit it and make it a Number:Length Item, the unitSymbol is “in” and the displayed pattern is the number received converted to meters. I get the same result when I create a Number:Length Item with {Unit=“m”} in the Developer Tools Add Items with Textual Definition.

I can solve my problem by deleting the items with structured names and recreating them in the UI as Number:Length items. If there is a way to change the unitSymbol from “in” to “m”, that would be easier, but don’t know how to do that, if it is possible.

Seeing that it’s just a Number Channel as shown here is enough.

That’s not terribly useful. So it doesn’t actually say what units the number is it’s reporting. Cou;d be miles, meters, or microns.

Did you set the State Description Pattern? If not we can probably assume that came from the binding and the units it’s publishing in are m.

Metadata namespaces, as with everything else in OH, is case sensitive. For all intents and purposes this Item doesn’t have any units so it’s using the system default which is in. It needs to be all lower case unit.

Probably comes from the binding.

Thanks for your customary patient and thorough help. I really appreciate the way you try to help people learn, not just solve a problem.

No, I did not. I’m pretty sure it is reporting meters.

Bingo. I entered a new unit using the Unit on the Add Metadata list. I guess I was thrown off by that being uppercase. When I did that, the next time the binding updated the channel, I got the expected result.