Get items with same metadata namspace in Blocky - possible?

Hi Gents,
Is it possible to program this in Blocky?

from this post

Thanks

Blockly doesn’t have available for the kind of easy filtering and working with arrays/lists that other languages do. The devs of openHAB have even worked with the upstream developers of Blockly itself to see if there would be ways to add it to no avail.

So what you can do is use the inline script block to add some JS code that would otherwise be challenging or impossible to do with the existing blocks.

In this case create a variable using the standard blocks, let’s call it “batteries”.

Then add an inline block with code along these lines:

batteries = items.getItems().filter(i => i.getMetadata("level") !== null);

That will populate the variable batteries with all the Items that have metadata level.

From there you can use the for each block to loop over all the Items and do what ever you want to do with each one using blockly.

image

You could do it all in the inline script block but I assume you would want to do as much as possible in Blockly instead.

1 Like

Thanks Rich, it is very usufull.