Dynamically adding items at runtime in openhab2

Hi!

I am new at openhab and I am implementing a control interface for a custom irrigation system.
In openHAB 1.x the way to go was to implement a custom ItemProvider and register it as an OSGi service in parallel to the default GenericItemProvider.
As I saw the new Things and Discovery concept in eclipse smarthome project, I switched to openHAB2. There I found the ManagedItemProvider. In the description of the provider I found this:

“ManagedItemProvider is an OSGi service, that allows to add or remove items at runtime by calling ManagedItemProvider#addItem(Item) or ManagedItemProvider#removeItem(Item) .”

But now I dont know how to add items at runtime in my custom binding java code with the ManagedItemProvider.
Am I already on the right way?

Thanks in advance,
Thomas

Hi Thomas,

As a first remark: Please address such questions about the APIs and architecture directly at the ESH forum, as this is nothing specific to openHAB.
Secondly, bindings must not add items themselves. They instead can implement a discovery service, which will create Things. It is then up to the user to create and link items to the channels of these Things.

Best regards,
Kai

Hi Kai,

Thank you for the quick answer. I will consider that if I have further questions.

Best regards,

Thomas

Hi Kai,

Can you explain more on the implementing a discovery service and creating Things dynamically??

Thanks in advance,
Abin

I’d suggest to check out the Homematic binding, which makes excessive use of dynamic things, so you should be able to learn from it how it works.

1 Like