Blockly "get items with tag" does not work with multiple tags

OH 4.3.2

The blocky documentation says for “get items with tag”:

“multiple tags can be provided which then need to be separated with a comma”

I tried “tag1,tag2” and it returns nothing even if I have an item with both tags.

Are you using a variable or a text block?

I just tried it out and it appears to be working as expected. Maybe there was a relevant bug fixed in 4.3.3?

I understand the issue, this only works if you are explicitly typing the tags in the text field. If it comes from a variable it does not work, or even worst if I use directly the text join function in place of the text. From what I understand, the parsing is done directly by the block by analyzing the string. Here is the generated code for this:

image

shutters = items.getItemsByTag('tag1','tag2');

So it cannot work if you pass it a variable as it will interpret it as a single string.

Should I report this as an issue or a limitation?

Note the hint from the docs:

Get Items with Tag

blockly-getMembers

Function: Gets all items with the given tags which you can iterate over via a loop

  • returns a collection of items which have the given tags
  • multiple tags can be provided which then need to be separated with a comma
  • if multiple tags are given, the item must have all of the tags (“and”-condition)

Hint: Make sure you are using typed variables!

Try it with shutters defined as a String variable from the typed Variables menu. If it still doesn’t work file an issue.

In the mean time, you should be able to use a List variable instead of a String.

Typed variable (String) does not make a difference, nothing is returned, and using a collection gives a conversion error because the function expects strings and not an array.

The problem is that the getItemsByTag() function expects multiple strings as arguments to work, it does not support arrays and if a variable is passed the content is considered as a single argument and thus a single tag.

I will report this as an issue.

Thanks.

I have to admit that I perceive it as a bug. Please file a bug for it.

Note that your example means it has to have both tags at the same time. Often what you want is to have a list that contains items with any of these tags. In this case you have to retrieve two lists of each tag and then concatenate them as mentioned in the docs.

I understand your use-case, but in my use-case it is really an “and” condition I need.

I will report the bug.

For those who want to follow it:
Blockly “get items with tag” does not work with multiple tags when using variable · Issue #3077 · openhab/openhab-webui