Wild cards triggers in automation

Hi there.
I am trying to create an automation that is triggered by ANY of my binary sensors whose names end with _opening. I have 9 zigbee window sensors and I want to be notified when any sensor opens. I currently have nine different automations but want to slim this to one automation that is triggered by any sensor opens. I want to be notified WHICH sensor has opened.

I have tried LOTS of different variations and always get an error. I have even tried AI to write the code but also always get an error. It is driving me nuts!

Is it even possible to do this ?

thanks in advance

There’s no wildcard or template allowed, but you can list all entities in the same trigger. If you use the UI, it will let you pick as many as you like. In the automation, the trigger variable tells you which one it was.

For a state trigger that would be: trigger.entity_id

Another option would be to create a group, but you would need to iterate the group to see which ones are open. Only the first one opening will trigger the group, so you won’t get triggered for each one in that case.

On second thought, it should be possible with a template trigger, which somewhat to my surprise also should return the entity_id that casued the template to return true.

But again, same as with the group, once one of the sensors sets the template true then the others after it won’t trigger. So my first suggestion is the only one I know that will trigger each time, for every sensor, not just for the first one.

If you put each entity in a separate trigger of the same automation then you get the advantage of being able to set an id on each trigger. You can use that id further on in the automation. For instance, if each sensor should control a light, you could put the entity for the light in the trigger id.

1 Like

Not directly in the Automation… it requires a template sensor as a intermediary. The method is as follows: Have the Template sensor’s state be a count of the open windows, add an attribute to hold the entity ID of the most recently opened window. Your automation trigger would then be based on the state of the Template sensor. Use the Template conditions to reject decreases in value. The attribute with the entity ID will be available as part of the trigger variable.

There is at least one open PR to make it easier to do this a bit more directly in a Template trigger.

Related FRs:
Add support for wildcards in automation trigger entity id
Trigger condition entity id group entities as list of entities
Reusable shared trigger template variables
Template triggered limiting outcome to true and false instead of comparing old and new state…

1 Like

If the Zigbee uses MQTT then it is much easier to use a wildcard in an automation.

currently using ZHA but waiting for a sonoff with zigbee2mqtt to be delivered

trigger:
  - platform: mqtt
    topic: home/OpenMQTTGateway/RTL_433toMQTT/1/+
    payload: open

This is just an example trigger with + being the wildcard.