[SOLVED] Templated trigger for automation

I’m wanting to make a dynamic automation that acts on a number of sensors, the list of which will change.

I am using the 17track platform, and want to trigger an automation based on whether or not the “info_text” attribute contains a string. That’s easy enough using a template condition (or trigger) of:

{{ 'out for delivery' in state_attr('sensor.17track_package_my_package', 'info_text')|lower }}

The problem is that I don’t want to have to build new or edit my automations every time a new package shows up in 17track. Is there any way to essentially do:

{{ 'out for delivery' in state_attr('sensor.17track_package*', 'info_text')|lower }}

Is there a way to do this kind of wildcard trigger? Should I just give up and use AppDaemon?

1 Like

For a start you should check the breaking changes in v0.85 for this sensor. The entity_ids have changed.

Interesting note, I am on latest and saw that change, but my entities are still named sensor.17track… I think it’s not the entity_id that changed, but the entity name.

Is it the best? Probably not… but it works!

Automation triggers on any entity update but only if the entity_id starts with “sensor.17track_package” AND “out for delivery” OR “delivered” is in the info_text of the sensors attribute.

- alias: "Seventeentrack Update"
  initial_state: 'on'
  trigger:
    platform: event
    event_type: state_changed
  condition:
    condition: and
    conditions:
      - condition: template
        value_template: "{{ trigger.event.data.entity_id.startswith('sensor.17track_package_') }}"
      - condition: or
        conditions:
        - condition: template
          value_template: "{{ 'out for delivery' in trigger.event.data.new_state.attributes.info_text|lower }}"
        - condition: template
          value_template: "{{ 'delivered' in trigger.event.data.new_state.attributes.info_text|lower }}"
  action:
    service: notify.pushover
    data_template:
      message: >
        {{ trigger.event.data.new_state.attributes.friendly_name | replace("Seventeentrack Package: ","") }}: {{ trigger.event.data.new_state.attributes.info_text }}

@aneisch This is pretty creative! I want to do something similar. Could you please tell me, where you know the “startswith” from?