Blueprints: Get your !input value into a template

When you gather data in a blueprint using !inputs, you will need to use that data in the lower parts of the blueprint. All the native Home Assistant places accept the

!input my_data

format for this.

If you are using the value in a template, however, this does not work.

The code inside of the template brackets is all rendered by a jinja2 template engine, not Home Assistant. That engine does not know what the !input tag is. That is looking for a variable.

Therefore in order for template engine to see the value, it needs to be converted to a variable.

...
input:
  notification_id:
    name: Optional Persistent Notification ID
    default: []
    selector:
      text: {}

variables:
    # Get the notification_id into a variable.
  _notification_id: !input notification_id

- choose:
  - conditions: '{{ _notification_id | length > 0 }}'
    sequence: 
    - alias: Notify interested parties WITH notification_id
      service: persistent_notification.create
      data:
        title: '{{ states[trigger.to_state.entity_id].name + '' Status'' }}'
        message: '{{ states[trigger.to_state.entity_id].name + '' is 'home' }} '
        notification_id: '{{ _notification_id }}'

This conversion / translation will work in both the variables: and trigger_variables: sections.


The Home Assistant Cookbook - Index.

3 Likes