hello I would like to know the syntax to know the members who compose a group, I can only do it in “rules dsl” and with “blockly”, could you help me?
here is blockly script:
var logger = Java.type('org.slf4j.LoggerFactory').getLogger('org.openhab.rule.' + ctx.ruleUID);
with files based in automation folder i have always error
thanks a lot
Blockly renders to ECMAScript 5.1 which isn’t going to be much help. But from the reference docs above you’ll see that the ECMAScript 2021 equivalent would be something like
here is what i get :
how a can get label of name ?
thanks for your help
I can only repeat what Rich said: Always refer to the reference documentation, before asking on the forum, that saves us all some time.
getItem(...) returns an
Item object with the following properties:
- Item :
- .type ⇒
- .name ⇒
- .label ⇒
- .history ⇒
- .state ⇒
- .rawState ⇒
- .members ⇒
- .descendents ⇒
- .isUninitialized ⇒
- .groupNames ⇒
- .tags ⇒
- .getMetadataValue(namespace) ⇒
- .updateMetadataValue(namespace, value) ⇒
- .upsertMetadataValue(namespace, value) ⇒
- .sendCommandIfDifferent(value) ⇒
The members of your
House group are returned as an Array (you can also see this in your log message with the brackets: ).
To log the label of each group member (as an example), which is an element of the Array, there are some possibilities:
// the array with the members of the „House“ group
var members = items.getItem('House').members;
// this logs the label of each member to a new line
members.forEach((item) => console.info(item.label));
// this uses the map function of Array to generate a new array with the names of the group members
// and joins the names into a single string
console.info(members.map((item) => item.name).join(', '));
Thanks a lot this is more clear to me now , thanks !