Add support for wildcards in automation trigger entity_id

Tags: #<Tag:0x00007f7c5a6a9400>

Currently I have about 25 automatons that could be reduced into about 3 if there was support for wildcards in the entity_id field in a trigger…
For e.g. if I could go:

  trigger:
  - entity_id: sensor.*_display_app
    from: Google News
    platform: state

and then reference trigger.entity_id in my action I could send the response back to the device without having to have one for every device.

Kris

You can list multiple entity IDs in the automation. So something like this:

  trigger:
    platform: state
    entity_id:
    - sensor.sensor1
    - sensor.sensor2
      ...
    from: Google News

or…

  trigger:
    platform: state
    entity_id: sensor.sensor1, sensor.sensor2, ...
    from: Google News

And then in the action you can reference which entity triggered the automation. Here’s an example of one of mine:

- alias: Notify when Zigbee sensor unavailable
  initial_state: 'on'
  trigger:
  - platform: state
    entity_id:
    - binary_sensor.button_1
    - binary_sensor.button_2
      ...
    to: 'unavailable'
  action:
  - service: notify.notify
    data_template:
      message: "{{ trigger.to_state.attributes.friendly_name }} is unavailable"

Still not ideal when you have a lot of sensors with a common name… also I want it to automatically work when I add new devices so I don’t forget to update the automation.

I have just ended up doing this:

  trigger:
  - event_data: {}
    event_type: state_changed
    platform: event
  condition:
  - condition: template
    value_template: '{{ trigger.event.data.old_state.attributes.app_name == ''Google
      News'' and trigger.event.data.new_state.attributes.app_name == null }}'

Kris