Wildcards for groups!

Groups 2.0

ever wanted to create a group of entities that all have a simular type of name? for example a group of zwave switches? and you dont want to add every switch manual? thats why i created this.

another option i built in is nested view. nested view is a group in a group.

to use this:

install Appdaemon (see instructions here http://appdaemon.readthedocs.io/en/latest/INSTALL.html )
add groups.py to your apps directory
edit apps.yaml like the sample to create your groups.
you dont even have to restart Home assistant to see the result. every successfull edit from apps.yaml immediatly results in an updated Home assistant GUI.

maybe if its liked enough i will create options to use * etc as wildcard.

3 Likes

I think this is what I have been looking for. I want to create one group for every switch / sensor / binary sensor so that each group has only one entity in it.

group.kitchen_light_alert > light.kitchen_light

group.back_door_alert > binary_sensor.back_door

Is this what your app does?

no this creates a group like this:

group:
  device_type: "sensor"
  entity_part: "zwave"

this would give a group with all sensors with zwave in the entityname.

but what you want is not that difficult in appdaemon.
an app with something like:

sensors = self.get_state("sensor")
for sensor in sensors:
  sensorlist =[]
  sensorlist.append(sensor)
  device, entity_name_part = self.split_entity(sensor)
  self.set_state("group." + entity_name_part,state="on",attributes={"view": "False","hidden": "False","assumed_state": "True","entity_id": sensorlist})

in the initialize function would create a single group for all sensors with the sensor in it.
add visibility to the attributes to make them visible or unvisible.
and you had already an app part to automate the visibility, i believe.

Great, thanks, I will give it a try

1 Like

I gave a modified Appdaemon a try from your example. It works except that the group state doesn’t change with the entity inside, it just stays on. I removed group attributes and I get this. I should note that some of the customized attributes where retained although I removed the groups from configuration.yaml. Any help would be appreciated. Thanks

import appdaemon.appapi as appapi

class create_group(appapi.AppDaemon):

  def initialize(self):
    binary_sensors = self.get_state("binary_sensor")
    for binary_sensor in binary_sensors:
      binary_sensorlist =[]
      binary_sensorlist.append(binary_sensor)
      device, entity_name_part = self.split_entity(binary_sensor)
      self.set_state("group." + entity_name_part + "_alert",state="on",attributes={"entity_id": binary_sensorlist})

Edit: After some investigating, I am not sure I can create a group that functions by setting the state. I went to the state page on the front end and made up a group name like group.test . with the following and it doesn’t change state with binary_sensor.mud_room_door although it shows up

{
  "assumed_state": false,
  "control": "hidden",
  "entity_id": [
    "binary_sensor.mud_room_door"
  ],
  "friendly_name": "Mud Room Door Alert"
}

you only create a group when you initialize the app.
and you set the state to on.
off course the state doesnt change when your sensor state changes for that you need a complete other app.

something like:

import appdaemon.appapi as appapi

class create_group(appapi.AppDaemon):

  def initialize(self):
    binary_sensors = self.get_state("binary_sensor")
    for binary_sensor in binary_sensors:
      self.listen_state(self.set_group_state,binary_sensor)

  def set_group_state(self, entity, attribute, old, new, kwargs):
      entitylist =[]
      entitylist.append(entity)
      device, entity_name_part = self.split_entity(entity)
      if new == "on":
        hidden = True
      else:
        hidden = False
      self.set_state("group." + entity_name_part + "_alert",state=new,attributes={"entity_id": entitylist, "hidden": hidden})

this will listen to the state from every binary sensor, and when the state changes to “on” it will show the group with state “on”
when state changes to “off” it will hide the group and set the state to off.

when the group doesnt exist, it will automaticly be created.

1 Like