Strange behavior of Number item containing big numbers

Hi all,
I have a strange behavior of Number items which contain numbers bigger than >= 10000.
My setting:
I have two Number Items, one defining a threshold, one holding a sensor value.

Number luminosity_min "Minumum Luminosity [%.0f]"
Number luminosityAverageGarden "Average luminosity garden [%.0f]"

Then I use it within a custom widget and compare the values:

<div class="box-content dummy" ng-style="{ 'background-color' : itemValue('luminosity_min') < itemValue('luminosityAverageGarden') ? 'darkgreen' : 'darkred' }">

if luminosity_min now gets updated to a number bigger than 9999 the comparison always is true, so the background never gets red. Going back to 9999 the comparison works as expected and the background changes according to the numbers.

Tested it also with a template widget and the following code:

{{ itemValue('luminosity_min') < itemValue('luminosityAverageGarden')}}

Same result. Given a value of 4000 for luminosityAverageGarden setting luminosity_min to 5000 will result in false, setting it to 15000 will result in true.

Interestingly, if both numbers are above 10000, the comparison works again.

Any idea, what the problem could be?

Thanks in advance,
Frank

It’s not completely clear, but I’m guessing you are using HABPanel? I’ve moved this to the HABPanel category so hopefully it will get more attention. Sitemaps don’t use widgets.

image
That’s JavaScript for you.
itemState (or formerly itemValue) always returns strings, not numbers even if the item type is Number - that’s how the API works.

The trick is to put a + before to convert them to numbers (assuming they remain positive) like so:

{{ +itemState('luminosity_min') < +itemState('luminosityAverageGarden')}}
1 Like