I ended up solving this with (note: edited to include @JustinG suggestion in his reply right below):
- In item definitions, change the item state presentations to always be floats, with 0 decimals when I want to see an integer without decimals. For instance:
"Inverter Total Output Power Sunsynk [%.0f W]"
.
Important note: setting it to%d
feels more natural, but for some reason it doesn’t work! - in my Main UI widget, use the
@"item"
shortcut to usedisplayState
if defined, otherwise fall back tostate
.
For instance:
text: =@"solar_total_power"
This is becausedisplayState
is only defined if it defers fromstate
. For instance in my casedisplayState
only gets defined if the underlying item value isn’t a round integer.
With this I do get the expected format, and the UI code then makes no assumption on what unit is exported by the underlying item, so no risk of mismatch.