Dynamic Items through Rules


I’ve read this post:

because this topic demonstrates the same what I want to do. I want to create Items dynamically. Like this post above, the creation succeed but I cant give the created Items some Values. I tried with postUpdate and with sendCommand.
The Post Owner told something about an ItemRegistry and that I have to register the created items to. But there were no further posts and answers on it. Since this post was written on 2016 are there some new information about how you can create dynamic items in rules and update their values?

Your best bet is to use the REST API to create the Items. That is the same interface that is used when creating Items through PaperUI or Habmin. That will also persist your ITems across OH reboots since it will get saved to the JSONDB. You can use the sendHttp*Command Actions to make the calls. You can install the REST API docs, which are interactive, from the Misc tab in PaperUI…

If the HTTP Actions are too limited you will need to use executeCommandLine and use curl instead.

If I may ask, why do you want to do this? It is certainly not a use case that was planned for as OH developed and I’ve yet to see too many reason why users want/need to dynamically create Items. The Items are supposed to represent the state and control points of your home automation. Perhaps it is a lack of imagination, but the only use cases I can come up with where this would be better than alternatives or required are workarounds for the limitations of OH (e.g. Alarm Clock example) for which there are better workarounds available (IMHO, e.g. CalDav Binding).

Usually, when someone is going to these extreme lengths to make something work in OH, the JSR223 Rules Engine is more appropriate as it gives you much fuller general purpose languages to write Rules in.

My UseCase was only to store some data in dynamic dummy items for every member in specific groups, so that i dont have to create every item by myself.

That still just tells me what you want to do, not the actual problem you after trying to solve.

For example, “I want to be able to control reach one of my irrigation zones individually and I don’t know how many start and end times I need ahead of time so I need a way to dynamically create on and off timers.”

That tells me what problem is being solved.

“I want to create items dynamically because I don’t want to create then by hand” does not.

To check wether the amount of members and which members actually changed in groups.
Or to say it in a short way: to observe the membership of groups. Thats a Feature that I personally miss in OH.

You can achieve this by using Member and filter methods

Not as trigger and only if you store the previous data in some dummy values/items.

I am sorry but:

for what purpose?

That OH is completely usable to update Frontends e.g. Apps that shows the whole Content that can be managed by the user. And these Frontends are dependent on the Observer Functions of OH (and that means not only the state of the items, also the connection between those [Member of groups …]).

Oh well. No one ever seems to want to actually tell me why, just what. This explanation too is explain what you want to do. Not why.

It’s ok, it saves me time trying to come up with an alternative approach.

But I can say that nothing you said here requires creation of new items, it just requires dynamically changing group membership.

You are never going to be able to trigger a Rule with a dynamically created Item or Group. You can trigger a rule with statically defined Groups and dynamically change Group membership, but that is not the same thing as what you are asking to do.

This will need more explanation because everything you describe is present through the REST API, which is what any front end will use. And the REST API will allow you to create Items, create Groups, and list and change their Group membership all you want. That is how PaperUI and Habmin work.

The limitation with Rules still stands though, you can’t trigger a Rule using a dynamically created Item or Group. If you want something like that, create a MembershipModified Item and have your front end send a command to that Item when membership changes and in a rule that triggers on that item do what ever it is you need to do to detect what changed and what to do about it.

Okay is there also a function where I can listen for new changes in the Rest API?

The REST API users Swagger which I believe supports websockets. If not you can poll.