Can someone show me how to decrypt what some variables are doing by using the developer templates area?

I have the below code and I am having a difficult time understanding how to use the developer templates area of HA in order to show me what each part is doing. I can get “doors” to report to me the array/ list but can’t figure out how to get the others to spit out their values to the developer templates results panel.

Thank you all for showing me how to do this!

variables:
  doors: |
    {{ states.lock | rejectattr('object_id', 'match', 'boltchecked')
      | map(attribute='object_id')
      | map('regex_replace', '(^.*)_lock$', 'binary_sensor.\\1') | list }}
  open_doors: |
    {{ expand(doors) | selectattr('state', 'eq', 'on')
      | map(attribute='name') | list }}
  closed_doors_unlocked: |
    {{ expand(expand(doors) | selectattr('state', 'eq', 'off')
      | map(attribute='object_id')
      | map('regex_replace', '(^.*$)', 'lock.\\1_lock') | list)
      | selectattr('state', 'eq', 'unlocked')
      | map(attribute='entity_id') | list }}

That’s because doors is not a Jinja variable unless you define it that way by setting the variable:

{% set doors =  states.lock | rejectattr('object_id', 'match', 'boltchecked')
      | map(attribute='object_id')
      | map('regex_replace', '(^.*)_lock$', 'binary_sensor.\\1') | list %}
Doors = {{doors}}

Then you can use the other two templates that reference the created variable.

@finity Thank you for showing me how to do this. I’m not very familiar with templating yet and that was gifted code from a few months ago that I didn’t know how to troubleshoot myself.

Thank you again for your help!!

1 Like