Variable in Template

Hello,

I am trying to reference two variables in a template with the intent to check if an item in a to do list is already present when an identical is added. The end goal is to prevent duplicates in my to do list.

I have the following:

alias: "To Do: Prevent Duplicates"
description: ""
triggers:
  - event_type: call_service
    event_data:
      domain: todo
      service: add_item
    variables:
      list_name: "{{ trigger.event.data.service_data.entity_id }}"
      task: "{{ trigger.event.data.service_data.item }}"
    trigger: event
conditions: []
actions:
  - target:
      entity_id: "{{list_name}}"
    data:
      status: needs_action
    response_variable: todo
    action: todo.get_items
    enabled: true
  - if:
      - condition: template
        value_template: >-
          {{
          todo['"{{list_name}}"']['items']|selectattr('summary','search','"{{task}}"')|list|count
          > 1 }}
        enabled: true
    then:
      - action: notify.mobile_app_pixel_5
        metadata: {}
        data:
          message: "yes"
    else:
      - action: notify.mobile_app_pixel_5
        metadata: {}
        data:
          message: "no"
mode: single

I am able to use the list_name variable to correctly get the entity id when using the get_items action however I am unable to use the same variable in my template condition for the if statement. I get the error:
Error: In 'template' condition: UndefinedError: 'dict object' has no attribute '{{list_name}}'

I assume that I am formatting the variable incorrectly when I am trying to reference it. Any clarity into what I am doing wrong would be appreciated.

Thank you!

Untested: try “todo[list_name]”

Thanks for the quick response.
When I try:

{{ todo[list_name]['items']|selectattr('summary','search',task)|list|count > 1 }}

I get the following error:

Error: In 'template' condition: UndefinedError: dict object has no element ['todo.before_bed']

The error does look more promising than what I was getting previously.

Hi teadragon7,

Variables do not exist, are not rendered, until after the trigger. Therefore those variables are showing up as empty.
I also don’t see the key variables: listed as a thing for an event trigger.

I’m guessing you have that in the wrong place, and really want it as a key that shows as the same level as conditions: or actions:.

Event Trigger Docs

Thank you for the response. I do not understand your feedback. The list_name as I have it set up works when I use the todo.get_items action which contradicts your explanation.

If you take a look at a previous question I posted here you can see the I have proposed formatting the variables in the trigger before and it has worked in other automations.