Icon states for float 'Number' item

A ‘Number’ item like this

Number  Weather_Wind_Degree  "Wind direction [%.0f °]"  <compass>  (Weather) {weather="locationId=home, type=wind, property=degree"}

has states with float values like 200.00 (the .00 digits are always zero in just this case, I’m looking for a general solution though).

I created a few graphics using this script to generate images for every 10° difference:

#!/bin/bash
for i in `seq 0 10 359`;
do
	convert -rotate $i -background transparent compass.png compass-$i.png
done 

resulting in images like

compass-0.png	compass-10.png	compass-20.png	compass-30.png ...

In the Basic UI, one icon is requested via URL /icon/compass?state=130.00&format=png which shows only the basic image compass.png.

OpenHAB should always show the closest icon to the current state, for e.g. 131° will use the 130°. For now even converting between integer and float states is not working:

/icon/compass?state=130&format=png shows the 130° image
/icon/compass?state=130.0&format=png shows the standard image
/icon/compass?state=130.00&format=png shows the standard image
/icon/compass?state=131&format=png shows the standard image

Am I using the icon engine wrong?

No help for your problem, but -

Strictly I believe it selects the next lowest in value i.e. 139 gets you image-130 not -140

1 Like