Create light group based on input_select helpers

Hi,

In preparation for the holiday season, I’m thinking to buy a few Zigbee smart plugs to automate my different Christmas lights. I want to be able to use the smart plugs for something else at different times of the year.

So far, I had 1 smart plug that I used either for my Christmas tree lights OR to plug in my WiFi extender, so I have better WiFi in the garden. I created an input_select helper to tell Home Assistant what was plugged into the smart plug and then based my automations on the state of this helper. This works great with 1 smart plug.

Now I want to add a bunch of smart plugs for different Christmas lights in- and outside the house AND be able to use the plugs for different use-cases outside the holiday period.

I’ve investigated creating a dynamic group and was partially successful as it creates a group of the input_select helpers if it contains the word ‘Kerst’. I wasn’t able to group the actual smart plug switches. I can’t get the group to contain the lights, while basing the selection criteria on the input_select helpers:

alias: Group Kerstverlichting
description: >-
  Create a group for all Christmas lights (inlcuding Christmas tree) plugged
  into a Smart Plug (identified through 'input_select' helpers)
trigger:
  - platform: state
    entity_id:
      - input_select.hue_smart_plug
condition: []
action:
  - service: group.remove
    data:
      object_id: kerstverlichting
  - service: group.set
    data:
      name: Kerstverlichting
      object_id: kerstverlichting
      icon: mdi:string-lights
      entities: >
        {{ states.input_select | selectattr('state', 'search', 'Kerst') |
        map(attribute='entity_id') | join(', ') }}
mode: single
  • Is there a better way than using input_select helpers?
  • If input_select helpers are the right approach: how do I dynamically create the group of smart plugs that have Christmas lights plugged into them?

Thanks for any suggestions or help!

For anyone interested: I got it to work with the addition of a regex_replace:

{{ states.input_select | selectattr('state', 'search', 'Kerst') | map(attribute='entity_id') | join(', ') | regex_replace('input_select', 'switch') }}

as part my automation:

alias: Group Kerstverlichting
description: >-
  Create a group for all Christmas lights (inlcuding Christmas tree) plugged
  into a Smart Plug (identified through 'input_select' helpers)
trigger:
  - platform: state
    entity_id:
      - input_select.hue_smart_plug
condition: []
action:
  - service: group.remove
    data:
      object_id: kerstverlichting
  - service: group.set
    data:
      name: Kerstverlichting
      object_id: kerstverlichting
      icon: mdi:string-lights
      entities: >
        {{ states.input_select | selectattr('state', 'search', 'Kerst') |
        map(attribute='entity_id') | join(', ') | regex_replace('input_select',
        'switch') }}
mode: single