I’m working on a script to keep track of birds spotted by my BirdNET Pi. I’ve set up a script to process new sightings and add them to a to-do list. I want to prevent duplicates, so I’m using a template condition block in the script. I can’t seem to work out how to use a variable of the script in the value_template of the condition.
I’m getting the existing list and putting it into a response_value. When I search that response value for a static string it works as expected. When I try to use one of the script’s fields it no longer works.
alias: Process Bird Sighting
sequence:
- service: todo.get_items
metadata: {}
data:
status: needs_action
target:
entity_id: todo.identified_birds
response_variable: birds
- condition: template
value_template: >-
{{
birds['todo.identified_birds']['items']|selectattr('summary','search',"{{common_name}}")|list|count
== 0 }}
enabled: true
- service: todo.add_item
metadata: {}
data:
item: "{{common_name}}"
description: "{{scientific_name}}"
target:
entity_id: todo.identified_birds
mode: queued
fields:
scientific_name:
selector:
text: null
name: Scientific Name
required: true
common_name:
selector:
text: null
name: Common Name
required: true
icon: mdi:bird
max: 10
if I change that value_template to a static value like
{{ birds['todo.identified_birds']['items']|selectattr('summary','search',"Eastern Towhee")|list|count == 0 }}
it will correctly keep me from adding multiple “Eastern Towhee” items to the list. But it won’t work if I use the field {{common_name}} as in the selectattr expression instead.
Any thoughts? I’m new to working with repsonse values.