Is it possible to get all entites of a group? Preferable in the AppDaemon API?
I will explain my problem. As of today a control all my lights based on sun, if anyone is home, who is awake and so on. The problem is when we have guest that stays in the guest room. If we have guests I want to disable the light-control in the guestroom temporarily, with a input_boolean. And I don’t want to hard code everything, I want to put everything in groups. When i turn on each device I want to first check if the input_boolean is on, if it is on I want to check if the device is in a group that contains all devices in the guestroom. I have this solution with another platform, but now I want to switch over to home assistant and I would like to make the same solution.
I do understand that I could achieve this by using args in the app configuration, but then I can’t reuse the information in another part of home assistant. (plus it’s an ugly solution)
i cant think of a way which you can check if an entity is part off a group or to check whitch entities are in a special group.
but i dont see the difference in writing a list of entities in de appdaemon.cfg or in the groups.yaml
all my automations go through appdaemon and my frontend is dashboard, so for me there is no use for grouping in HA anymore. ( i do it anyway to keep it a bit better to check things once in a while)
but maybe @aimc knows a way to solve it with HA groups.
It’s very easy to do this in AppDaemon - @ReneTode you should have more faith!
The information is available in HA State, and AppDaemon exposed this through the get_state() API Call. I wrote a quick function to do the check for you:
def check_group(self, entity, group):
group = self.get_state(group, attribute = "all")
return entity in group["attributes"]["entity_id"]
And you call it like this - it will return true if the entity is in the group, false otherwise.
Likewise, to iterate through list of entities in a group, I have been using this type of code:
groupitem = self.get_state(self.args["group_of_trigger_sensors"],"all");
entity_list = groupitem['attributes']['entity_id']
for i in entity_list:
self.log('Subscribing to state change for ' + i );
self.listen_state(self.sensor_trigger, i, new='on');
where my self.args[“group_of_trigger_sensors”] parameter is a group name (e.g., group.security_motion_sensors)
I take it from your example that it is not possible to perform a listen_state() call on a group and have the same effect (any state change on an entity in the group triggers a callback)?