Can I combine percentage icon and absolute value on one line?

Is there a way to combine batteryvoltage as percentage and absolute value in one line?

I have an ESP measuring batteryvoltage and it sends that via 2 MQTT payloads as actual voltage as wel as percentage.

In Openhab I can easily display both by
Number battery_garden "Batterij Tuin [%.1f V]" <battery> (Garden) {mqtt="<[mosquitto:home/garden/BatteryVoltage:state:default]"}

for the actual voltage and

Number batter_garden_pct "Battery tuin [%.0f %%]" <battery> (Garden) {mqtt="<[mosquitto:home/garden/batterpct:state:default]"}

for the percentage

In the first case however, the icon always shows the 'empty battery’
is there a way that I in ONE line can make the icon react to the percentage and the actual number the absolute value

I know I can combine the text of the percentage and actual value with a rule as described here

but that doesnt seem to give me the changing icon. Was I barking up the wrong tree there, or is that the way to go?
Any suggestion is appreciated


That is the only way to combine Items but the problem is the icon is chosen by the state of the Item. The battery Icon needs to be used with a numerical state. If you combine the two you no longer have a numerical state.

You could theoretically make it work but you would have to create a version of the battery icon for every possible value for the combined percent and raw value that is possible.

According to Classic Icon Set there are battery icons for 0, 10, 20, … 90, 100 %, so eleven in total. In your sitemap using the visability parameter you could show the correct icon and hide the incorrect ones. This will then require a 11 similar lines in your sitemap of which only one is shown. So not exactly one line in your sitemap if that is what you meant with ONE. It will however show as one line in your GUI (e.g. Basic UI, Habdroid or the iOS app).

Thanks. Maybe i did not express myself properly. I meant displayed on one line.I am not doubting it takes more than one line of code :wink:

Hmm that is a bummer but thanks. Maybe for now I just will have to keep it on different lines :slight_smile: