For MQTT battery channel, update 2 items simultaneously - voltage and %

  • Platform information:
    • Hardware: 64bit x86 Intel, 6GB RAM, 2TB HDD
    • OS: Windows 10
    • Java Runtime Environment: Zulu JDK 11
    • openHAB version: 3.2.0 stable
  • Issue of the topic:
    • Battery % item with JS transformation from voltage showing with units “V” in item page widget (which I believe is standalone widget) but shows correctly in item list page (Settings → Items, which I believe is list widget) and
  • Please post configurations (if applicable):
    • Humidity sensor Thing configuration
UID: HumiditySensor
label: Humidity Sensor
thingTypeUID: mqtt:topic
configuration: {}
bridgeUID: mqtt:broker
location: Master Shower
  - id: HumiditySensor_BatteryVoltage
    channelTypeUID: mqtt:number
    label: Battery Voltage
    description: ""
      postCommand: false
      unit: V
      min: 3
      stateTopic: Humidity Sensor/Battery
      max: 4.2
  • Humidity sensor Battery Voltage Item configuration
Name: HumiditySensor_BatteryVoltage
Label: Battery Voltage
Type: Number:ElectricPotential
Category: battery
Semantic Class: Measurement
Semantic Property: Voltage
  • Humidity sensor Battery Percent Item configuration
Name: HumiditySensor_BatteryPercent
Label: Battery Percent
Type: Number
Category: batterylevel
Semantic Class: Measurement
Semantic Property: None
  • Battery Percent Item to Thing Link
Profile: JS
Profile Configuration: | (((parseFloat(i) - 3)/0.012) + 0).toFixed(1) + "%"

With this configuration:

  • Battery Voltage shows (eg) 3.536 V
  • Battery Level shows 44.7 % in Settings → Items and Analyze chart, but 44.7 V in almost all other UI, eg:
    • overview UI, Settings → Items → Battery Percent, etc

If I remove “unit: V” from thing definition, item value starts showing “UNDEF” in UI.

Any recommendations to make this shows “%” units everywhere.

Give your battery Item a default unit of % in the Item ‘pattern’ metadata, and try again.

Thank you. That worked!