Trying to combine a couple of numeric items which work/show well individually - into a new string, but including their formatting.
These are my items:
Number Wind_Gust_Direction "Gust Direction [SCALE(windDir.scale):%s]" <wind>
Number Wind_Gust_Strength_Mps "Gust Strength [%.0f m/s]" <wind>
This is the stringing in my rule, I hoped would work - but it doesnt:
var String tmp = String::format("%1$.0f m/s / SCALE(windDir.scale):%2$s", Wind_Gust_Strength_Mps, Wind_Gust_Direction)
What am I missing here ? - how could this be achieved ?
I am looking for a result like this “8 m/s / WNW” if;
Wind_Gust_Direction = 302 (would translate to “WNW”)
Wind_Gust_Strength_Mps = 8.1
This java function doesn’t know anything about openHAB transformations, you’ll have to do that separately in your rule.
Why not develop this one step at a time.
Get the state of one Item as a string. Format if you like. Transform it if you like. Get another Item, process similarly. Combine your new strings.
When it’s working, then try to get it all in one line if you must.
Makes sense - and thanks for sending me in the right direction. This is how I fixed it in the end:
var String tmp = transform(“SCALE”, “windStrength.scale”, (Wind_Gust_Strength_Mps.state.toString)) + " (" + Wind_Gust_Strength_Mps.state.format("%.0f m/s") + " fra " + transform(“SCALE”, “windDir.scale”, (Wind_Gust_Direction.state.toString)) + “)”