Dynamic group entity?

Is there any posibility to have a dynamic group entity? I tried it like the following code that i have implement in groups.yaml:

control:
  view: yes
  name: "Control"
  entities: >-
    {% if is_state('input_text.text1', 'test') %}
      - input_text.text1
      - input_select.time
    {% else %}
      - input_text.text1
    {% endif %}

However, it didn’t work. The error message that i get is something like this:

ERROR:homeassistant.config:Invalid config for [group]: Entity ID {% if is_state(‘input_text.text1’ is an invalid entity id for dictionary value @ data[‘group’][‘control’][‘entities’]. Got “{% if is_state(‘input_text.text1’, ‘test’) %}\n - input_text.text1\n - input_select.time\n{% else %}\n - input_text.text1\n{% endif %}”. (See /home/runcross/.homeassistant/configuration.yaml, line 232). Please check the docs at https://home-assistant.io/components/group/
ERROR:homeassistant.setup:Setup failed for group: Invalid config.

Is here somebody that can help me or does I have to look for an other way? Because if i do this in a sensor, I’m able to change the name or the icon. I just want to see the input_select.time when i have written the correct word into my textfield, like a passwordcontrol.

I’m wondering the same thing. Would be very convenient to have a group that showed only active media players or lights that were on… Based on what I’ve read, I think this may be possible using Floorplan, but I feel like that is more complex than I wold like.

Edit: Much less seemless, but another option may actually be to do this with an automation that adds an entity to a group based on state. See https://home-assistant.io/docs/configuration/group_visibility/. I do think doing this through a group definition would be much smoother though

1 Like

Is there any way to achieve this? AppDaemon can help?

You can use CustomUI with customizer.set_attribute to hide/display any component.
I use it to hide media_player when not on, a secondary switch depending on the primary switch status (hidden if off, shown when turned on)

The automation will be like this :

- alias: 'Hide stuff'
  trigger:
    platform: state
    entity_id: switch.anyswitch
    to: 'off'
  action:
    - service: customizer.set_attribute
      data:
        entity_id: media_player.denon
        attribute: hidden
        value: 'True'
    - service: customizer.set_attribute
      data:
        entity_id: switch.light
        attribute: hidden
        value: 'True'

And to display it :

- alias: 'Show stuff'
  trigger:
    platform: state
    entity_id: switch.anyswitch
    to: 'on'
  action:
    - service: customizer.set_attribute
      data:
        entity_id: media_player.denon
        attribute: hidden
    - service: customizer.set_attribute
      data:
        entity_id: switch.light
        attribute: hidden

Note that by setting your light/media_player as hidden you are excluding it from history and recorder.

Sad but true ! Same with “hide if away” option in the device tracker.

You can hide in UI-only using CustomUI templates instead:

customize:
  media_player.denon:
    templates:
      hidden: return entities['switch.anyswitch'].state === 'off'

I’ve been trying this a while ago, I couldn’t make it work. Tried a lot of syntaxes, the best I got was the “hidden” attribute was set correctly at startup but didn’t change when the reference switch changed.
I wish I could avoid the automation for each hide/display object but I didn’t find out the trick ?

I’ve spent some time to finally understand it and make it work.
I have made a topic with examples here.

My configuration is HA 0.62.1 on an ubuntu server, with CustomUI 20180126.