Are these Items being updated faster than every 5 seconds? What is the expire configuration.
Expire is implemented in core and therefore it has no direct interaction with the bindings. So there isn’t any interaction between Expire and MQTT. But MQTT may be updating the Item in a way that prevents Expire from triggering.
I noticed it for a thermometer that I use via zigbee2mqtt. Usually, it updates at least once per hour. I have an expiration timer of 2h on the humidity item.
The thing went offline (using the availability topic) because the battery was empty. The humidity should have gone to UNDEF after 2h, which would have resulted in an alert to me.
But when I checked, the humidity was not UNDEF after days of being offline.
So, I replaced the battery and the thing was online again. Then I set the expiration to 5 minutes to see if it would work and it does not. The humidity never goes to UNDEF.
I know that this worked before the upgrade to OH 5.x.
Then I checked another item with expiration timer, which is being updated via a rule. Set a short expiration timer and it worked.
Edit:
My testing was incorrect. After setting the Expiration time, it does not immediately run. It only starts the countdown after the next update. So I tested again and the Expiration timer is actually working again for the MQTT item.
I do not know, what was wrong with my openHAB when it did not trigger. Maybe it was in some weird state. In the meantime, I restarted it several times, that may have fixed it.
What probably happened was the battery ran out but before the two hour expire could trigger OH was restarted. The expire timer requires an event to start the timer and expire doesn’t restart timers that are running after a restart automatically. So restoreOnStartup initialized the Item (this does not trigger the expire timer) to what ever it was before and since there is no new event to start the timer it remains in that state.
I’ve created a rule template on the marketplace that runs at system started and updates all the Items with expire metadata to what ever state they are currently in. This kicks off the expire timers and makes sure that if a device stops responding while OH was offline the Item will still time out.