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!