Create Item Numbers

I read the article “Design Pattern: Working with Groups in Rules” - it’s very interesting.

If have a Switch Group with some Switch items. In then Startup rule I want create for every Switch in this group a Number Item. At the Shutdown I’ll delete this Number Items.

	Motions_Counter.members.forEach [ _Counter |
		Motions_Counter.removeMember(_Counter)
	]
	Motions.allMembers.forEach [ _Motion |
		Motions_Counter.addMember ( new NumberItem(_Motion.name+"_Counter") )		
	]
	Motions_Counter.members.forEach [ _Counter |
		_Counter.postUpdate(0)
	]

I receive then following error message, if I’ll display then Group Motions_Counter in the sitemap
2018-05-29 21:03:27.092 [ERROR] [ui.internal.items.ItemUIRegistryImpl] - Cannot retrieve item for widget org.eclipse.smarthome.model.sitemap.Text

2018-05-29 21:03:27.097 [ERROR] [ui.internal.items.ItemUIRegistryImpl] - Cannot retrieve item ‘Motions_BadUG_Counter’ for widget org.eclipse.smarthome.model.sitemap.Text

2018-05-29 21:03:27.103 [ERROR] [ui.internal.items.ItemUIRegistryImpl] - Cannot retrieve item ‘Motions_BadUG_Counter’ for widget org.eclipse.smarthome.model.sitemap.Text

2018-05-29 21:03:27.106 [ERROR] [ui.internal.items.ItemUIRegistryImpl] - Cannot retrieve item ‘Motions_BadUG_Counter’ for widget org.eclipse.smarthome.model.sitemap.Text

2018-05-29 21:03:27.110 [ERROR] [ui.internal.items.ItemUIRegistryImpl] - Cannot retrieve item for widget org.eclipse.smarthome.model.sitemap.Text

2018-05-29 21:03:27.114 [ERROR] [ui.internal.items.ItemUIRegistryImpl] - Cannot retrieve item ‘Motions_KorridorEG_Eingang_Counter’ for widget org.eclipse.smarthome.model.sitemap.Text

2018-05-29 21:03:27.119 [ERROR] [ui.internal.items.ItemUIRegistryImpl] - Cannot retrieve item ‘Motions_KorridorEG_Eingang_Counter’ for widget org.eclipse.smarthome.model.sitemap.Text

2018-05-29 21:03:27.123 [ERROR] [ui.internal.items.ItemUIRegistryImpl] - Cannot retrieve item ‘Motions_KorridorEG_Eingang_Counter’ for widget org.eclipse.smarthome.model.sitemap.Text

You can’t really create Items in Rules like this. You will need to use the REST API and sendHttp*Request to interact with that API.

OH really isn’t set up for dynamically created Items like this. What are you trying to accomplish? Tell me what you want to achieve, not how you want to do it.

The errors you are seeing are because those Items on your sitemap do not exist.

Hi Rich

Thank you for the fast response.

I want some motion sensors in a group. For all items in this group I want to create some additional items like timer for countdown and handle this in one event rule.

I can create this Items in the Items file, but when I forget one I receive en error.

thanks , Theo

You should create your items once and for all in an item file
Show us what you tried, we may be able to tell you whty it doesn’t work

That is by design. You should use that error as a reminder to go add the missing Item, not come up with some weird work around with dynamically created Items.

If you do need to keep track of a dynamic collection of data, you should use a List or a Map inside your Rule.

Ok Rich,
it isn’t possible.

The interesting thing is, that it works but not in a sitemap.
In the rule I can use the items correctly.

Thanks, Theo

It never gets added to the Item registry. I doubt those Items will still exist from one run of the Rule to the next, unless you are storing those Items somewhere.