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

Ability to query group state #4989

Closed
stefanheule opened this issue Nov 15, 2020 · 8 comments
Closed

Ability to query group state #4989

stefanheule opened this issue Nov 15, 2020 · 8 comments
Labels
feature request Feature request stale Stale issues

Comments

@stefanheule
Copy link

It would be nice to be able to query the state of a group. My home automation system uses this at startup (of the home automation system, not zigbee2mqtt) to learn the current state of the system. It seems like there is no way to get the state of groups any more, they only output their state when the state changes.

Describe the solution you'd like

Explicitly querying the state of a group at "zigbee2mqtt/<group_name>/get" should send out the current state of that group.

Describe alternatives you've considered

I could have my external system know the group to device mapping and learn the state by querying all the member devices. That's doable, but it seems like just re-implementing state tracking outside of zigbee2mqtt.

Additional context

It used to be possible to query the group state by querying any of the members. This was recommended as a solution by @Koenkk in #764 (comment). However, I believe with the change for #3461 that stopped working.

@stefanheule stefanheule added the feature request Feature request label Nov 15, 2020
@github-actions
Copy link
Contributor

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 7 days

@github-actions github-actions bot added the stale Stale issues label Dec 16, 2020
@stefanheule
Copy link
Author

If a developer familiar with the code sends me a few pointers, I could try implementing this myself and sending a PR. What are some files/functions I likely need to touch?

@github-actions github-actions bot removed the stale Stale issues label Dec 17, 2020
@Koenkk
Copy link
Owner

Koenkk commented Dec 17, 2020

My home automation system uses this at startup (of the home automation system, not zigbee2mqtt) to learn the current state of the system.

For this use case you can use the retain option. This is a native MQTT feature which will send the last message published to a topic upon subscribing to it. Read more about this option here: https://www.zigbee2mqtt.io/information/configuration.html#all-devices

Example for configuration.yaml:

groups:
  '1':
    friendly_name: group_1
    retain: true

@stefanheule
Copy link
Author

Thanks! But that requires resubscribing, which may not always be desirable. Is there a reason there is no option to query the state of a group just like you can query individual elements? If I were to send a PR that adds this functionality, would you accept that?

It seems like a very natural feature, but maybe I'm missing something.

@Koenkk
Copy link
Owner

Koenkk commented Dec 18, 2020

Is there a reason there is no option to query the state of a group just like you can query individual elements?

Because groups actually have no state (and the state of devices in it can vary in theory).

I'm wondering if it makes more sense to add a command to republish all known states? E.g by publishing to zigbee2mqtt/bridge/request/publish_states?

@stefanheule
Copy link
Author

Okay, I guess that makes sense. Basically groups can be set, and it's equivalent semantically to setting each member of the group to the same state (though in terms of timing the group set seems to do all of them at once, while the iterative "do each member" is noticeably sequential).

A command to republish all states would actually be truly useful to me. Would it also republish group states? My guess is no, since as you point out there is no real state with groups. Either way, it would be useful :)

@Koenkk
Copy link
Owner

Koenkk commented Dec 20, 2020

Would it also republish group states? My guess is no, since as you point out there is no real state with groups. Either way, it would be useful :)

This would be republish the states as available in the data/state.json file.

@github-actions
Copy link
Contributor

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 7 days

@github-actions github-actions bot added the stale Stale issues label Jan 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request Feature request stale Stale issues
Projects
None yet
Development

No branches or pull requests

2 participants