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â.
I have exactly the same need, doing generic rules to push notifications.
Iâm searching for a way to avoid duplicated code, and state description pattern seemed to be a good start.
Do you know if there is a easy way (except HTTP / REST) to use getDisplayState from SseItemStatesEventBuilder ?
Currently when a door is open, voice assistant says âdoor blabla is ONâ not really âniceâ