Multiple domains in input entity

Hi,

i am advancing my motion sensor blueprint and want to add groups as trigger. That is because if you need multiple mostion sensors to cover an area groups are really usefull and work well.

Now i can use two input entitys, make them optional and write down that at least one must be used and chaning the rest of the bluerprints to this two entitys (not that user friendly and harder to mantain) or i can make the entity choosable not only with motion sensor but with groups too.

So one input selector but with two domains, something like this:


input:
    motion_entity:
      description: Motion Sensor as trigger. Choose at least one trigger, otherwise this automation will never trigger
      default: none
      name: Motion Sensor
      selector:
        - entity:
            domain: binary_sensor
            device_class: motion
        - entity:
            domain: group

But that is not working:

2020-12-19 21:03:44 ERROR (MainThread) [homeassistant.config] Invalid config for [automation]: Invalid blueprint: Expected a dictionary for dictionary value @ data[‘blueprint’][‘input’][‘motion_entity’][‘selector’]. Got [OrderedDict([(‘entity’, OrderedDict([(‘domain’, ‘binary_sensor’), (‘device_class’, ‘motion’)]))]), OrderedDict([(‘entity’, OrderedDict([(‘domain’, ‘group’)]))])] (See /config/configuration.yaml, line 68).

Does somebody know if this is possible?

As far as I know, no, it’s not currently possible. You can make the selector supports everything (pick an entity, any entity) or you restrict it to one specific domain.

I encountered a similar requirement where ideally the user could choose either a light or a switch. However, there’s no way to make a single selector list the entities of two domains. The only workaround is clumsy: make separate selectors for each desired domain and supply each with default values. Your template will need to ignore any selectors that still have their default values.

Thanks for helping me out.

Hope this get added soon.

I think i will just remove the domain completly. With that a user could choose some unusefull but with adding two enttitys users could use both wich will lead (at least in my experience) to unexpected behaviour.

I think i am now at 3 possible features in my mind for blueprints :smiley:, still finding the idea behind this concept great.

Good news!

Community member kenlasko discovered how to permit the Entity selector to list multiple domains:

It’s undocumented and his example is the first that I’ve seen posted here (of course, I may have missed other examples).

This worked for me:

      selector:
        entity:
          domain: light
          domain: switch

EDIT

It may not work for your application. The moment you introduce device_class, to constrain the entity list, it flags the multiple domains as an error:

Logger: homeassistant.util.yaml.loader
Source: util/yaml/loader.py:218
First occurred: 4:41:33 PM (3 occurrences)
Last logged: 4:41:33 PM

YAML file /config/blueprints/automation/local/synced_lights.yaml contains duplicate key “domain”. Check lines 10 and 11
YAML file /config/blueprints/automation/local/synced_lights.yaml contains duplicate key “domain”. Check lines 11 and 12
YAML file /config/blueprints/automation/local/synced_lights.yaml contains duplicate key “domain”. Check lines 19 and 20

2 Likes

Hi,

many thanks for coming back to me!

very strange, i already tried that with the result that only the last mentioned domain is used :confused:

so this


selector:

        entity:

          domain: binary_sensor

          domain: input_boolean

gives me only the input booleans.

When i change the order i get binary sensors only

There’s probably a good reason this isn’t documented because the results are uneven. For example, I tried this:

      selector:
        entity:
          domain: light
          domain: switch
          domain: binary_sensor

and it only lists light and binary_sensor entities. Without domain: binary_sensor it lists light and switch entities. It would appear that we may be leveraging a bug (it overlooks to report multiple domains as an error) as opposed to an undocumented feature. :slight_smile:


EDIT

I’m now convinced it’s a bug.

If you use the blueprint, the moment the Entity selector displays multiple domains, you’ll get an error message posted to Logs.

Oh well, it was promising while it lasted.

I think you are completly right.

I tried the same domains as you, and i still only get the last ones.

So it looks like that is it even different for different installations

Was a rather short time, but boy, we had fun :smiley:

Without faffing around trying to find where this is discussed, have we tried…

selector:
  entity:
    domain:
      - light
      - switch
      - binary_sensor

?

That was the first thing I tried, and it didn’t work.

1 Like

Another one of those situations where neither Check Config or Reload Automation identifies it as a problem … then you see this in Configuration > Blueprints (where it should be displaying the blueprint’s name):

Invalid blueprint: expected str for dictionary value @ data[‘blueprint’][‘input’][‘first_entity’][‘selector’][‘domain’]. Got None

1 Like

How about trying this:

selector:
  entity:
    domain:
      - light
  entity:
    domain:
      - switch
  entity:
    domain:
      - binary_sensor

I haven’t tried 3 in my blueprint, but 2 didn’t produce any errors in the logs.

I try this one later m, but getting no error in the logs is not really an indicator.
Is the blueprint usable or do you see an error there? Look at the name of the blueprint, there you can see the error, if there is one.

got this when i try this:

Invalid blueprint: expected str for dictionary value @ data[‘blueprint’][‘input’][‘motion_entity’][‘selector’][‘domain’]. Got None

Found an interesting yet undocumented feature:

blueprint:
  name: Test Gist
  description: Test Gist
  domain: automation
  homeassistant:
    min_version: 2021.2.0

Results in

Resurrecting this 10 months later to see if anything has changed. I’m also trying to filter by multiple domains (binary_sensor and group), like the OP. Is the best practice still to leave domain open or does HA now support multiple selections? The documentation didn’t seem to provide a solution, so I’m asking here.

1 Like

re-resurecting this, some months later :slight_smile:
Any way to target multiple domains?

The docs say that a list of domain is valid even though it does not work.

The proper syntax for specifying a list, for example, is:

domain:
  - light
  - switch

Or:
domain: [light, switch]

I have pinged on the Discord list without an answer (yet).

In case it may help others who might come across this thread later: It appears that the syntax that @gwww mentions here indeed works (at least as of Home Assistant 2023.6.1).

And just for good measure, if you might need a list of domains in your Home Assistant instance, you can get that by pasting this snippet into the dev tools:

{{ states | groupby('domain') | map(attribute='0') | list | join('\n') }}
1 Like

I came across this post now looking for an answer and ended up checking the docs again.

Selectors - Home Assistant (home-assistant.io)

Under a pure entity selector, you can define a filter, then a domain, and provide a list to the domain, but if your selector is a device, with an entity below that, the domain can only be a single domain.

Quick summary:

Selector that allow a list of domains:

  • entity
  • target
  • area

One that don’t:

  • device