items.getItem('Equipment_WaterIn_Pressure').postUpdate('231000 Pa');
console.log(items.getItem('Equipment_WaterIn_Pressure').state); // 231000 Pa
console.log(items.getItem('Equipment_WaterIn_Pressure').rawItem.getStateDescription().pattern); // %.2f bar
console.log(items.getItem('Equipment_WaterIn_Pressure').rawState.getUnit().getSymbol()); // Pa
console.log(items.getItem('Equipment_WaterIn_Pressure').rawState.format(items.getItem('Equipment_WaterIn_Pressure').rawItem.getStateDescription().pattern)); // 231000.00 bar WTF :)
console.log(items.getItem('Equipment_WaterIn_Pressure').displayState); // undefined
// how to get '2.31 bar' in JS rule?
OK, that’s the metadata you defined for the State Description. In that case it cannot be done. The state description is something that only gets created in MainUI.
You could maybe manage something using java.lang.String.format, passing the “pattern” field as the format and the .rawState and the thing to be formatted, but you’ll have to do all sorts of parsing and extra work to handle Items with units.
No, I don’t. It’s very rare that the pretty formatted state of the Item matters in a rule. About the only time I can think of where it’d be useful is logs, and who really cares that the logs are not “pretty”.