Support variables in a Template Trigger

I tried the new trigger_variables feature introduced in 2021.3.0. I converted my original example to this:

- alias: test
  trigger_variables:
    inputs: >
      {{ expand('group.input_booleans') 
         | selectattr('state', 'eq', 'on')
         | map(attribute='name') | list }}
  trigger:
    platform: template
    value_template: "{{ inputs | count > 0 }}"
  action:
    service: persistent_notification.create
    data:
      title: 'Test'
      message: "{{ inputs | join(', ') }}"

Unfortunately, it was rejected for the following reason:

Error rendering trigger variables: TemplateError: str: Use of ‘expand’ is not supported in limited templates

I removed expand and replaced it with a list of state objects:

      {{ [ states.input_boolean.switch_1, states.input_boolean.switch_2 ] 
         | selectattr('state', 'eq', 'on')
         | map(attribute='name') | list }}

However, that was also rejected:

Error rendering trigger variables: UndefinedError: ‘function object’ has no attribute ‘input_boolean’

tl;dr
The new trigger_variables feature is promising but, in its current state, has limited functionality; this Feature Request remains open.

6 Likes