[SOLVED] Is there a way to control the lifecycle of handlers

Hi all,

I have a bridge which I want to be fully initialized, to have made the necessary connections and fill all it’s data caches before the other thing handlers being initialized.

What I have is in initialize() of the bridge. I set the bridge to status UNKNOWN at the start of this method, then I do the rest of initialization/communication and at the end I set the bridge as ONLINE. I would expect the framework to not try to create thing handlers before the bridge is ONLINE but the framework creates all handlers and executes their lifecycle in parallel which sometimes leads to issues in retrieving the information which bridge caches in certain structures.
Maybe here is time to note that I use declarative creation of things (i.e. each thing has it’s own record in the binding.things file). Probably one way could be to switch to dynamic discovery mode which I haven’t yet researched how could be done.
I wonder if there is any other smart way to control this behavior through the framework or I should look into solving it in my coding?


I don’t have the docs in front of me, so I’m going off of memory (which is not so great these days).

You should be able to use bridgeStatusChanged in your thing handlers to be informed when you’re bridge goes online. That would be the trigger for your handler to start doing its thing.


Now I see that I probably did not really allowed the normal lifecycle of handlers to be handled by the openhab framework.
The default implementation of bridgeStatusChanged is just fine for my case.
What I did to fix is - I took out the setting of thing status to ONLINE from my initialize() leaving it to the framework.

Thanks a lot Mark !

1 Like

Please set the thing status to UNKNOWN after your initialization is finished (i.e. at the end of initialize()).

You might run into trouble otherwise.