- Platform information:
- Hardware: Raspberry Pi 4 / 8GB
- OS: OpenHABian / OH 4.3.5
I have just experienced an interesting issue.
I am using a Number type item as storage for the overall status of my underfloor heating and heatpump system. It can have several states which I store as numbers, which represent e.g. if all heating is off (item = 0), all is on (item = 2), or mixed status (item = 1).
The item is used to trigger several actions on change. Therefore, I have rule triggers like:
when
Item Status_alle_Heizungen changed from 2 or // von alleHeizungenStatusOn
Item Status_alle_Heizungen changed from 1 or // von alleHeizungenStatusMixed
Item Status_alle_Heizungen changed from 0 // von alleHeizungenStatusOff
then ...
Tonight, the system switched heating off due to the very warm period of days as expected, and I was wondering why some triggers were missing. I found the explanation in the logs:
2025-05-02 03:00:18.471 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Status_alle_Heizungen' changed from 2.0 to 0
→ it changed from 2.0 [float] to 0 [int]. Which does not trigger the above rule - I could reproduce that manually, if it changes from 2 to 0 it triggers, if it’s from 2.0 to 0 the trigger is missed.
The interesting part is that there is no action which ever sets the item to 2.0. Only int values are used for setting the item. It comes from the reload from persistence on any reboot / restart, which correctly restores the value as such, but changes its type from int to float. As the item changes only about twice per year, this reload is nearly inevitable.
The reason why I use these explicite “changed from” is also due to persistence reload. I only want to trigger the rule when the item changed from a valid value, using just “changed” or “changed to” gives me undesired triggers on reload from persistence (as it changes from uninitialized to the recent value).
I would like to avoid something like switching it to float values and using “changed from 2.0”, as comparing float values to exact equality is bad programming practice.
What would be an elegant while stable solution for this issue? Or is it a bug?