Problems with Number:DataAmount not converting units of scale - i.e. Bytes to Kilobytes or Kibibytes

  • Platform information:
    • Hardware: Raspberry Pi4 4Gig
    • OS: Raspbian GNU/Linux 10 (buster)
    • Java Runtime Environment: ?
    • openHAB version: 2.5.0
  • Issue of the topic: I have items configured as Number:DataAmount with units B (Bytes) but I cannot display them in more readable form as KiB or MiB in sitemap - they still show the same value which is obviously wrong! Have also tested KB and MB. Just to be sure I also tested items as Number:DataTransferRate which works OK.
  • I have created test configurations to make sure I hadn’t got something wrong in my production configs.
    • Items:
Number:DataAmount               testDataAmount                  "Test Data Amount [%d B]"
Number:DataAmount               testDataAmountControl           "Test Data Amount Control [%d B]"

Number:DataTransferRate         testDataTransferRate            "Test Data Transfer Rate [%d bit/s]"
Number:DataTransferRate         testDataTransferRateControl     "Test Data Transfer Rate Control [%d bit/s]"

  • Sitemap configuration related to the issue
sitemap DataTest label="Test Units" {
        Text    item=testDataAmount                     label="Test Data Amount [%d MB]"
        Slider  item=testDataAmountControl              label="Test Data Control [%d B]"                        minValue=0      maxValue=10000000       step=10240

        Text    item=testDataTransferRate               label="Test Data Transfer Rate [%d Mbit/s]"
        Slider  item=testDataTransferRateControl        label="Test Data Transfer Rate Control [%d bit/s]"      minValue=0      maxValue=10000000       step=10240

  • Rules code related to the issue
rule "Test Data Amount Units"
        Item    testDataAmountControl           received update         or
        Item    testDataAmountControl           changed

rule "Test Data Transfer Rate Units"
        Item    testDataTransferRateControl             received update         or
        Item    testDataTransferRateControl             changed

  • If logs where generated please post these here using code fences:
2020-02-07 11:41:41.014 [ome.event.ItemCommandEvent] - Item 'testDataTransferRateControl' received command 1402880 bit/s

2020-02-07 11:41:41.038 [vent.ItemStateChangedEvent] - testDataTransferRateControl changed from 471040 bit/s to 1402880 bit/s

2020-02-07 11:41:41.051 [vent.ItemStateChangedEvent] - testDataTransferRate changed from 471040 bit/s to 1402880 bit/s

2020-02-07 11:41:42.558 [ome.event.ItemCommandEvent] - Item 'testDataAmountControl' received command 1402880 o

2020-02-07 11:41:42.574 [vent.ItemStateChangedEvent] - testDataAmountControl changed from 9451520 o to 1402880 o

2020-02-07 11:41:42.593 [vent.ItemStateChangedEvent] - testDataAmount changed from 9451520 o to 1402880 o

2020-02-07 11:41:43.448 [ome.event.ItemCommandEvent] - Item 'testDataAmountControl' received command 3512320 o

2020-02-07 11:41:43.456 [vent.ItemStateChangedEvent] - testDataAmountControl changed from 1402880 o to 3512320 o

2020-02-07 11:41:43.466 [vent.ItemStateChangedEvent] - testDataAmount changed from 1402880 o to 3512320 o

The only potential issue I see in the logs is the use of o as the units and not B for DataAmount item type.

Another test I performed was to change item testDataAmountControl to Number:Dimensionless - this results in OpenHAB treating it as bits, as testDataAmount then becomes 1/8 the value and is hence being converted from bits to bytes.

This can be seen in the following chunk of log:

2020-02-07 11:48:42.296 [ome.event.ItemCommandEvent] - Item 'testDataAmountControl' received command 3968

2020-02-07 11:48:42.312 [vent.ItemStateChangedEvent] - testDataAmountControl changed from 3840 to 3968

2020-02-07 11:48:42.324 [vent.ItemStateChangedEvent] - testDataAmount changed from 480 o to 496 o

I have copied the configs from this topic into two more instances of OpenHAB, running on different systems, with the same result.

Using the following commands on each system shows the same versions:


cat /var/lib/openhab2/etc/

Responds with:

openHAB Distribution Version Information
build-no        : Release Build
online-repo     :

Repository        Version
openhab-distro  : 2.5.1
openhab-core    : 2.5.0
openhab1-addons : 1.14.0
openhab2-addons : 2.5.1
karaf           : 4.2.7


dpkg --list | grep openhab

Responds with:

ii  openhab2                              2.5.1-2                                         all          openhab2

Found that o represents Octet, which is 8 bits. According to some sources the term Byte is ambiguous - don’t know where they got that idea, but I guess they were listening to too much of Michael Jackson’s Bad, which seems to have confused generations with their use of language and meaning of words.
Anyway, I have found that conversion from Octet (o) to Kibioctet (Kio) and Mebioctet (Mio) functions as expected, however I would like to use the ‘traditional’ unit of Bytes which matches the type and unit of the original incoming data.