I have an automation that I’ve been using that I want to turn into a blueprint. It uses a response_variable in a for_each loop to process todo list items. It works fine with a hardcoded todo list entity, but I can’t figure out how to have it use an input variable for the the entity id, specifically in the jinja template of the for_each.
Here’s an example of what I’m trying. Appreciate any help with the correct syntax:
automation:
- alias: Process To-Do List Items
trigger:
# Your trigger here (e.g., a button press, a specific time)
action:
- service: todo.get_items
target:
entity_id: !input todo_entity
data:
status: needs_action # Get only items needing action
response_variable: daily_tasks # Name your response variable
- repeat:
for_each: "{{ daily_tasks[todo_entity]['items'] }}" # Reference the specific 'items' list
sequence:
- service: notify.mobile_app
data:
message: "Task summary: {{ repeat.item.summary }}" # Access properties of each item
# Add more actions to perform for each item here
variables:
todo_entity: !input todo_entity
The way you are setting and using the input and variable looks fine, but automations don’t allow the use of !input, so I’m not sure what you are expecting from what you have posted… Without an actual blueprint config, it’s hard to say for sure what the source of any issue is.
FWIW, I would suggest using merge_response(), that will allow you to use more than one todo entity at a time if desired, and has the side effect of eliminating the need for using the input.
Blueprint Sketch
blueprint:
domain: automation
name: Example
description: Example
input:
my_trigger_input:
name: Triggers
selector:
trigger:
todo_entity:
name: ToDo Lists
selector:
entity:
multiple: true
filter:
- integration: todo
further_actions:
name: Actions
selector:
action:
triggers:
- triggers: !input my_trigger_input
actions:
- action: todo.get_items
target:
entity_id: !input todo_entity
data:
status: needs_action
response_variable: daily_tasks
- variables:
tasks: "{{ merge_response(daily_tasks) }}"
- repeat:
for_each: "{{ tasks }}"
sequence:
- service: notify.mobile_app #MAKE SURE TO PUT A REAL NOTIFY ACTION HERE
data:
message: "Task summary: {{ repeat.item.summary }}"
- sequence: !input further_actions
If you can clarify what your goals are for the blueprint we can probably provide a bit more guidance
Yeah, sorry for the confusion. I am working on a blueprint but hastily copied and pasted an automation that had similar code to illustrate the issue. I am able to use input variables to assign todo list entities everywhere except the jinja code below:
When I generate the automation from the blueprint, the input values populate into all of the places they should, except for that jinja string.
I’m fighting a hideous sinus infection right now which is making it hard for me to keep my eyes open for more than a few minutes, but when I’m feeling better I’ll post so more code to demonstrate.
blueprint:
name: Recurring Todo Blueprint Backup
description: Sets the next due date of recurring todo list items based on date completed
domain: automation
input:
todo_entity:
name: Todo List
description: Todo list that contains the recurring items
selector:
entity:
filter:
- domain: todo
calendar_entity:
name: calendar entity
description: The calendar you want to update when items are completed
selector:
entity:
filter:
domain: calendar
variables:
todo_entity: !input todo_entity
triggers:
- trigger: state
entity_id:
- !input todo_entity
- trigger: time_pattern
minutes: /15
conditions: []
actions:
- action: todo.get_items
data:
status:
- completed
target:
entity_id: !input todo_entity
response_variable: mylist
- variables:
todo_items: "{{ mylist[todo_entity]['items'] }}"
- repeat:
for_each: "{{todo_items}}"
sequence:
....
Thanks, that works. But, I realized that my original script was also working with a local variable declared and this…
for_each: "{{ mylist[todo_entity]['items'] }}"
The problem was my troubleshooting. I was generating the automation from the blueprint, taking control, and verifying that the input variable values were populating into the correct places. For some stupid reason I was expecting those values to appear in place of the local variable in the for_each. I blame it on the sinus infection and not utter stupidity Thanks again for all of your help. The merge_response() function will come in handy for a few automations I need.