Text item=MB_Charge_Today label="Lading [%.2f kWh]"
The problem is that hWh does not seem to be recognized, the item also appears as a unitless number in the log.
When changing the item unit to kWh, the unit appears in the log.
Any ideas?
Ok will do.
The data comes from the modbus binding:
Bridge modbus:tcp:battery-inverter
{
Bridge poller power [start=33161, length=20, refresh=4000, type="input"] {
Thing data charge_today [readStart="33163", readValueType="uint16"]
Thing data charge_yesterday [readStart="33164", readValueType="uint16"]
Thing data discharge_today [readStart="33167", readValueType="uint16"]
Thing data discharge_today [readStart="33168", readValueType="uint16"]
}
}
I tried using a javascript transformation at first but the unit of the item doesn’t show up in the sitemap when doing this.
This is the setup that I used:
I think you put it in the wrong place.
In the Item [presentation] means the Item state remains as it is, and the transform tries to work with real state - which will have units. Your JS won’t work with input string “9.8 kWh”.
As per Modbus binding docs, do it in your data Thing. At this point, it’s just an integer Modbus register.
Use the same little script, add Thing parameter readTransform="JS(divideBy10.js)"
Now the Modbus data Thing will output your value scaled in kWh, but just as a numeric (units don’t exist for Modbus).
That’s okay, openHAB will use what you have put in the Item [presentation] as a default unit. Number:Energy MB_Charge_Today "Lading [%.2f kWh] ..."
An alternative approach to using readTransform= and [Item default units] is to use the binding’s modbus:gainOffset profile on the Item-channel link instead.
The advantage here is that you specify the unit before it arrives at the Item state, and do not rely on the [presentation] to assume a default.