Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

query members of virtual groups #40

Closed
NemoN opened this issue Feb 10, 2018 · 6 comments
Closed

query members of virtual groups #40

NemoN opened this issue Feb 10, 2018 · 6 comments
Assignees

Comments

@NemoN
Copy link

NemoN commented Feb 10, 2018

It is possible to get the members of (virtual) groups?

for example:

var array = apdapter.getMembers('<groupID>');

@AlCalzone
Copy link
Owner

AlCalzone commented Feb 10, 2018

You can. The virtual group object looks like this:

{
  "_id": "tradfri.0.VG-00001",
  "type": "channel",
  "common": {
    "name": "Test"
  },
  "native": {
    "instanceId": 1,
    "type": "virtual group",
    "deviceIDs": [
      65537,
      65538
    ]
  },
  // ...
}

So once you read the object with getObject, obj.native.deviceIDs contains the instance ids of the members. Those are always lightbulbs, so their IDs have the form "tradfri.X.L-YYYYY"

@NemoN
Copy link
Author

NemoN commented Feb 10, 2018

Some background of my question: I have a virtual group with 10 GU-10 bulbs. Sometimes 1-3 bulbs of the group don't react. If i retrigger the switch on/off command it works. My plan was now:

For example turning off all lamps:

  • Turn off virtual group
  • Check each lamp in group for state still on
  • Turn this lamp(s) off again

This works now. Maybe this could be handled from backend/Tradfri adapter too?

@AlCalzone
Copy link
Owner

This works now. Maybe this could be handled from backend/Tradfri adapter too?

Sounds reasonable, I'll need some additional input though. When that happens:

  • Do the lamps which did not react update their state in ioBroker? I imagine they don't.
  • Do the virtual group's states get updated?

@NemoN
Copy link
Author

NemoN commented Feb 12, 2018

Do the lamps which did not react update their state in ioBroker? I imagine they don't.

No the status is still tradfri.0.L-65549.lightbulb.state = 'true'
(if i trigger a "off" command)

Do the virtual group's states get updated?

If some bulbs of the VG can't switched, then the VG group state is empty tradfri.0.VG-00001.state = ''

my working workaround is now after turning off the VG group before

var newState = true;
var obj = getObject('tradfri.0.VG-00001');
var members = obj.native.deviceIDs;

members.forEach(function(m) {
    var stateId = 'tradfri.0.L-' + m + '.lightbulb.state';
    // console.log(stateId);

    getState(stateId, function (error, state) {
        // console.log(state.val);
        if (error) {
           console.log(error);
        } else {
            if (state.val != newState) { // Lampe hat den falschen State, nochmal schalten!
                setState(stateId, newState, false, function() { 
                    if (newState) {
                        log(stateId + ' turned ON again!');
                    } else {
                        log(stateId + ' turned OFF again!');
                    }
                });
            }
        }
    });
});

@AlCalzone
Copy link
Owner

Ok thanks. One more thing:
Does the log show any errors when this happens? Something along the lines of unhandled promise rejection?

@NemoN
Copy link
Author

NemoN commented Feb 12, 2018

no errors

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants