SMHI Binding decimal numbers instead of integers

A few days ago my SMHI binding stored enumeration values as decimal ie. 2.0 and 6.0 where it should be 2 and 6.
This messes up my mapping to text and icons.

Am I the only one having this problem?

I don’t know if the problem is the binding or if the SMHI has changed?

Did you update OH before this started happening? If so, what version are you on? Does it occur for daily or hourly forecasts, or both? Do you use any transformation or custom state description to convert the values for display?

I did not update OH when it started happening. I am on openHAB 3.1.0 Release Build.
I have the problem on both hour and daily. No mapping.

Number Smhi_PrecipitationCategory_4_Days "SMHIprecipitation 4 days [%s]" {channel="smhi:forecast:f3ac2f84:day_4#pcat"}

Looked through my logs, and noticed the same, but only occasionally, and only for the last few days, so I guess it’s some bad values coming from smhi. I’ll see if I can make the binding handle it better when that happens.

Edit: what’s strange though, is that the values in the logs are inconsistent:

2021-09-27 00:07:14.322 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'SMHI_Hour2_Wsymb' changed from 1 to 2
2021-09-27 01:00:14.349 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'SMHI_Hour1_Wsymb' changed from 4 to 2
2021-09-27 02:00:15.395 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'SMHI_Hour0_Wsymb' changed from 4 to 2
2021-09-27 02:00:15.418 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'SMHI_Hour2_Wsymb' changed from 2.0 to 4
2021-09-27 03:00:16.457 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'SMHI_Hour1_Wsymb' changed from 2 to 4
2021-09-27 03:00:16.461 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'SMHI_Hour2_Wsymb' changed from 4 to 6
2021-09-27 04:00:17.502 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'SMHI_Hour0_Wsymb' changed from 2 to 4
2021-09-27 04:00:17.511 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'SMHI_Hour1_Wsymb' changed from 4 to 6
2021-09-27 05:00:18.802 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'SMHI_Hour0_Wsymb' changed from 4 to 6
2021-09-27 06:00:20.195 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'SMHI_Hour2_Wsymb' changed from 6.0 to 4
2021-09-27 07:00:21.467 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'SMHI_Hour1_Wsymb' changed from 6.0 to 4

E.g it changes from 4 to 6 (Both integers), but then changes from 6.0 to 4, so the value that was initially an integer suddenly isn’t. Not sure, but this might mean that it can’t be fixed in the binding. I’ll look into it regardless, thank you for reporting!

1 Like

Comment; you will also see this effect when using e.g. restoreOnStartup to recover Item states from persistence.
While Item state 2 is distinguishable from 2.0, persistence services generally store all numbers as decimals.
It’s generally best to make rules etc. cater for both cases, where possible.

1 Like

@Bjorn_Caroll have you experienced the issue today as well? Not sure if the fixes I’m trying out are working, or if it’s just coincidence, since the issue seemed to be intermittent.

Yes I still have the same problem.

Then try this version and see if it helps. Drop it in your addons-folder, then you might need to disable the old version either by uninstalling it or run bundle:stop <bundle id> in the karaf console. If you can confirm the problem is fixed I will make a PR with the changes asap.

Yes, it works now.
I even did a test stopping the new bundle and starting the old one and the problems came back immediately.
Thanks for quickly fixing it.