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%dfeels more natural, but for some reason it doesn’t work! - in my Main UI widget, use the
@"item"shortcut to usedisplayStateif defined, otherwise fall back tostate.
For instance:
text: =@"solar_total_power"
This is becausedisplayStateis only defined if it defers fromstate. For instance in my casedisplayStateonly 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.