Hi, just want to share my shoppinglist sorter for the store I go at the most.
Since my girlfriend always just throws things randomly on the shoppinglist.
The idea is to read the todo shoppinglist into a csv string then send it to some LLM in my case google gemini since it is free. Ask the LLM to sort it according to a prompt and return it back as csv. Then clear the existing shoppinglist and fill it again from the LLM response.
Works pretty well here.
Change the prompt to your liking offcourse.
Could be a whole lot simpler if there was a native action to move items up or down in a todo list or a clear all items action.
alias: Sort ShoppingList
description: ""
triggers:
- trigger: conversation
command:
- Sort ShoppingList
- sort shopping list
conditions: []
actions:
- sequence:
- variables:
shoppinglist: null
sortedshoppinglist: ""
ai_response: ""
ai_responselist: []
- action: todo.get_items
metadata: {}
data:
status: needs_action
target:
entity_id: todo.shopping_list
response_variable: shoppinglist
- variables:
sortedshoppinglist: >-
{{
shoppinglist['todo.shopping_list']['items']|map(attribute='summary')|join(',
') }}
- action: google_generative_ai_conversation.generate_content
metadata: {}
data:
prompt: >-
Please sort my shoppinglist
below in the following sortorder Fruits, Vegetables, Pasta,
Mealboxes, Meat, Chicken, Cheese, Bread, Yogurth, Butter, Milk,
Eggs, Cereals, Muesli, Coffee, Candy, Soft Drinks, Water, Other. The
result should be a comma seperated answer containing the original
items only in the new sort order. My ShoppingList = {{
sortedshoppinglist }}
response_variable: ai_response
enabled: true
- variables:
ai_responselist: "{{ ai_response.text.split(', ') }}"
- repeat:
count: "{{ shoppinglist['todo.shopping_list']['items'] | length }}"
sequence:
- variables:
item: >-
{{ shoppinglist['todo.shopping_list']['items'][repeat.index
-1].summary }}
- action: todo.remove_item
continue_on_error: true
metadata: {}
data:
item: "{{item}}"
target:
entity_id: todo.shopping_list
- repeat:
count: "{{ shoppinglist['todo.shopping_list']['items'] | length }}"
sequence:
- variables:
item: "{{ ai_responselist[repeat.index - 1] }}"
- action: todo.add_item
continue_on_error: true
metadata: {}
data:
item: "{{item}}"
target:
entity_id: todo.shopping_list
mode: single