Using a text input on a blueprint template

I’m creating a somewhat complex template blue print and I’m having an issue using the text selector in a template (jinja). I was able to reproduce using a much simpler blueprint.

So I have this blueprint:

blueprint:
  name: Text Input Tester
  description: Testing how to use a text input in a template
  domain: template
  input:
    test_text:
      name: Test Text
      description: The text to text with.
      selector:
        text:
    test_trigger_entity:
      name: Test Trigger Entity
      description: The entity to trigger this test
      selector:
        entity:
          filter:
            domain: input_boolean
variables:
  test_text: !input test_text
trigger:
  - trigger: state
    entity_id: !input test_trigger_entity
    to:
binary_sensor:
  state: >
    {% if trigger.platform == 'state' and test_text in 'this is a test' %}
      on
    {% else %}
      off
    {% endif %}
  attributes:
    testText: >
      {{ test_text }}

Here is my template binary_sensor using that template:

 - use_blueprint:
      path: sirmeili/text_input_tester.yaml # relative to config/blueprints/template/
      input:
        test_text: test
        test_trigger_entity: input_boolean.epic_tv_exception
    name: Text Input Tester
    unique_id: a36ab10b-4b7f-43b4-ad10-3257af47c6b9

When I execute the “input_boolean” I get the following error in the logs:

Error rendering state template for binary_sensor.text_input_tester: TypeError: ‘in ’ requires string as left operand, not LoggingUndefined

I thought the selector: text: was for text input and in the configuration I’m sending in Text, is this not correct?

I did try changing

  input:
    test_text:
      name: Test Text
      description: The text to text with.
      selector:
        text:

to just this:

  input:
    test_text:
      name: Test Text
      description: The text to text with.
      default: ''

Am I not comparing the text correctly in the template it self? if I change test_text with “test” it works just fine.

So just for some more tests, I changed my blueprint to use just “strings” set as variables like this:

binary_sensor:
  state: >
    {% set myText = "test" %}
    {% set textToTest = "this is a test" %}
    {% if trigger.platform == 'state' and myText in textToTest %}
      on
    {% else %}
      off
    {% endif %}

So my guess is that my text input is not being made available to the templating system. Could that be? What would be the point then?

I think this is disappointing. I went and found the code that I think is responsible for parsing the variables for use in a template and it appears, at least from my understanding, that for template blueprints, all variables are assumed to be entities.

    @callback
    def _render_variables(self) -> dict:
        if isinstance(self._run_variables, dict):
            return self._run_variables

        return self._run_variables.async_render(
            self.hass,
            {
                "this": TemplateStateFromEntityId(self.hass, self.entity_id),
            },
        )

This is really disappointing. I guess I’ll go add a feature request to see if this can be added, but for now it completely puts a halt on my blueprint as without the ability to change a text (for filtering calendar entries) it makes it useless.

Template entity blueprints are still basically in beta, but text inputs do work… they are not assumed to be entities. However, template blueprints don’t support triggers yet, so that is a significant impediment for your trigger-based template binary sensor blueprint.

There is currently work being done by Petro to overhaul the template integration. As I understand it,
there are only a few core devs with the knowledge of and/or comfort with the integration to review and approve changes, so progress is likely to be slow.

Ok, but I set one up and in my example above, the trigger does trigger it, even based off an input entity, or am I misunderstanding what you are saying.

Yes, what I am saying is that trigger-based sensors and binary sensors are not currently supported… so you are going to get weird errors and non-functioning sensors whenever you try to use a blueprint to create any trigger-based template entity.

Gotcha. Ok. well that sucks because I was using this to make 3 of the same “binary” sensors and while I have those sensors working without the blueprint, it is really messy in my config file and I wanted to use the blueprint to make my config easier and of course share it.

Thanks for the info. I’ll stop pulling out my hair now :slight_smile: