Add support for wildcards in automation trigger entity_id

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

2 Likes

Tried your solution but here it doesn’t work:

- alias: "Crypto Selling Buying"
  trigger:
    - platform: event
      event_type: state_changed
      event_data:
        domain: sensor

  condition:
    - condition: template
      value_template: >-
        "{{ trigger.event.data.new_state.attributes.cat == 'crypto sensor' }}"

  action:
    - service: script.mobile_ha_engine
      data:
        title: "TEST"
        message: "TEST"
        thread_id: "crypto_stop_loss"

sensor attributes:
The sensor update every minute with current new buy/sell price.

cat: crypto sensor
ticker: ada
buy: 1.23832
sell: 1.17791
change24h: 14.61
volume24h: 1462816.4217
friendly_name: ADA
templates: 
icon_color: 'if (state === ''on'') return ''rgba(251,214,67,1)''; return ''rgba(71,116,157,1)'';'

icon_color: rgba(71,116,157,1)

Would also like that, to be able to quickly implement such use cases as "If any entity’s current_temperature attribute that has climate.*tuya in goes below 15.5, send message to phone notifying “Warning: Temperature below 15° in [[Room]]”.

Currently I’d have to search and include all those entities manually by hand

You can solve that by creating a template sensor which has a count of sensors below 15.5 degrees as it’s state, and a list of entities which are below 15.5 degrees as an attribute.

Can’t believe this is not possible…
And to be honest… sometimes I can’t hear anymore “it can be solved by template”.
(Yes, templates are cool, but not for everything).

With wildcard you will have WAY less maintenance to do, If gettin a new device you don’t have to update groups, templates (which you may have forget after a few years), automations or something else, you just have to ensure your entities are named properly when creating.

3 Likes