How to support multiple `device_id` in a trigger on a `zha_event`?

Issue:
When setting the multiple prop value to true for the switch input the trigger will no longer work. This seems to be caused by the fact that device_id does not support yaml lists like entity_id does.

Is there a work around for this or a different approach I should take?

blueprint:
  name: Test: ZHA | IKEA E1743
  description: ""
  domain: automation
  input:
    switch:
      name: IKEA TRADFRI switch (E1743)
      description: Select the switch to use.
      selector:
        device:
          integration: zha
          manufacturer: IKEA of Sweden
          model: TRADFRI on/off switch
          multiple: true
trigger:
  - platform: event
    event_type: zha_event
    event_data:
        device_id: !input 'switch'
...
3 Likes

I have run into the same limitation when building a blueprint for multiple IKEA open/close remotes.
Did you ever solve this and in case you did, how did you do it?

I have the same problem, any news?

This is a simple syntax problem. Multiple: belongs at the level of entity: and filter:, one level up in the YAML. Integration, manufacturer, model all belong under filter:
Check the docs…

@Sir_Goodenough Thank you so much for the hint! But unfortunately, it is not working.

Now the blueprint is invalid with the error message:

Invalid blueprint:
extra keys not allowed @ data['blueprint']['input']['remotes']['selector']['entity'][0]['filter']. Got None
extra keys not allowed @ data['blueprint']['input']['remotes']['selector']['entity'][0]['multiple']. Got None

My non-working blueprint code

I am new to HA and the syntax is hard for me to get used to. I am simply trying to make my existing/working blueprint support multiple input dimmer switches.

I would be very thankful if you could support me there! :slight_smile:

OK, that’s a device selector. For some reason unknown to me or mankind, the syntax is different for device than entity. This is probably why I seldom if ever personally use devices…

Look a bit further up in the docs for this one:

@Sir_Goodenough Thank you! That fixed the syntax error. However, I am still getting:

Error: UndefinedError: ‘dict object’ has no attribute ‘event’

When setting multiple to false it works. I have read so many tutorials and forum threads now and unfortunately, all are only covering the basics.

Thanks a lot for supporting James!

My code

Did you try this?

    remotes:
      name: Dimmer Switches
      selector:
        device:
          filter:
            - manufacturer: 'Signify Netherlands B.V.'
          entity:
            - domain: sensor
              device_class: battery
          multiple: true

as shown in the device example section:

@Sir_Goodenough Sorry I have put an old link (updated it now in the post before).

I have exactly used this syntax and I am getting the error:

Error: UndefinedError: ‘dict object’ has no attribute ‘event’

So event. The only place you have event is in the trigger. It is likely that the trigger can only handle 1, not a list. I’ve seen that in other places.
You may have to find another way of triggering.
Perhaps trigger more broadly (like any zha event or any zha event with that manufacturer), and then in conditions narrow it down to the ones called out in the input.
Where trigger and trigger variables can only use limited templates, conditions you have the whole template library so you can break up the list of devices and find a match to continue.

It’s more work but you can still get there.

If you need more help than that, I would pop into the configuration topic with a tag of templates and ask the question there of how to trigger monitoring multiple devices using the list in conditions. I’m sure one of the template guru’s can help you out. Not my expertise I’m afraid.

@Alwinator
If you select multiple devices in the selector, the result will be a list of devices.
The trigger will check for this full list, and thus will never trigger as the event will only have one device id in it

You can use a condition to check if the device id is in the list used in the selector

trigger: 
 - platform: event 
   event_type: zha_event 
variables:
  remotes: !input remotes
condition:
  - platform: template
    value_template: "{{ trigger.event.data.device_id in remotes }}"

Also note you can not use the RUN button in the GUI to test your automation when you use trigger variables, as there will be no trigger in that case.

1 Like

@TheFes @Sir_Goodenough Thank you both so much! I was able to fix it and it works fine now.

Here is my working blueprint: https://github.com/Alwinator/homeassistant-blueprints/blob/4ffcf130d0ab03d84ee4e907375eb9d1b396f2b5/Philips_Hue_Dimmer_Switch_Multi.yaml