Value template question

Should this work? I could not find any examples of this in the documentation, Specifcially I’m talking about using an input text “{{ states.input_text.door_keypad_1_name.state }}” vs actual text for the if statement.

      garagedoor_code:
        friendly_name: 'Garage Door Code'
        value_template: >
          {% if is_state('sensor.lock_garage_door_lock_alarm_type', '19') or is_state('sensor.lock_garage_door_lock_alarm_type', '18') %}
            {% if is_state('sensor.lock_garage_door_lock_alarm_level', '1') %}
              {{ states.input_text.door_keypad_1_name.state }}
            {% elif is_state('sensor.lock_garage_door_lock_alarm_level', '2') %}
              {{ states.input_text.door_keypad_2_name.state }}
...

So not sure what type of entity this is, and at least in the part you showed you’re missing a couple of {% endif %}'s, but if you’re asking if you can use an expression like {{ states.input_text.door_keypad_1_name.state }} inside the if statement like you show, then the answer is most definitely yes. Although you might want to do {{ states('input_text.door_keypad_1_name') }} instead.

1 Like

Ah ha! This is something that has been bugging me for ages but has never actually ever been an issue for me so I never asked before. But as you bring it up…

what is the difference between:

states('myentity')

and

states.myentity.state

And please, if it is in the docs and I missed it, it is not because I haven’t read them :slight_smile:

1 Like

The former returns ‘unknown’ if the entity doesn’t exist, whereas the latter would cause an error in that case.

It’s documented here:

1 Like