home-assistant.io
home-assistant.io copied to clipboard
TODO list get items
Feedback
Todo list is a neat feature, and one that comes at a fortuitous moment as I'm building out a thermal printer for HA.
However, I can't for the life of me figure out how to get the entities in a todo list into a template, or out into other services. Maybe it's my own inexperience, but this page really doesn't help (and it's a new feature so the forums don't have examples either).
URL
https://www.home-assistant.io/integrations/todo/
Version
2023.12.3
Additional information
No response
Hey there @home-assistant/core, mind taking a look at this feedback as it has been labeled with an integration (todo
) you are listed as a code owner for? Thanks!
Code owner commands
Code owners of todo
can trigger bot actions by commenting:
-
@home-assistant close
Closes the feedback. -
@home-assistant rename Awesome new title
Renames the feedback. -
@home-assistant reopen
Reopen the feedback. -
@home-assistant unassign todo
Removes the current integration label and assignees on the feedback, add the integration domain after the command. -
@home-assistant add-label needs-more-information
Add a label (needs-more-information) to the feedback. -
@home-assistant remove-label needs-more-information
Remove a label (needs-more-information) on the feedback.
Running into this as well
Running into this as well
I found a way to do it. I don't really like it, and it kind of works in some ways:
Here is a script that reads the values from an input todo list, and then puts them out onto mqtt:
I had it also putting it into a text helper, but for some reason that script isn't working anymore (open to suggestions). The MQTT version works well, though, so maybe it's a help to you.
alias: FillTodoListHelper
sequence:
- service: todo.get_items
data:
status:
- needs_action
response_variable: allTasks
target:
entity_id: "{{todolistname}}"
enabled: true
- service: mqtt.publish
data:
qos: 0
retain: false
payload_template: |2-
{{"Here is a list of my current tasks: \n"}}
{%- set ns =namespace(taskCounter=0,tasks=[]) %}
{% set ns.tasks = allTasks.values()| list %}
{% for task in ns.tasks[0]['items'] -%}
{%- set ns.taskCounter = ns.taskCounter + 1 %}
{{ns.taskCounter}}{{": " + task['summary']}}
{%- if task['description'] -%}
{{":\n"}}
{%- set descriptions = task['description'].split("\n") -%}
{% for subtask in descriptions-%}
{{" - "+subtask+'\n'}}
{%- endfor %}
{%- endif%}
{{"\n"}}
{%- endfor %}
topic: robot/addContext
- service: input_text.set_value
data_template:
entity_id: input_text.tasklist
value: >-
{{"Here is a list of my current tasks: \n"}}
{%- set ns =namespace(taskCounter=0,tasks=[]) %}
{% set ns.tasks = allTasks.values()| list %}
{% for task in ns.tasks[0]['items'] -%}
{%- set ns.taskCounter = ns.taskCounter + 1 %}
{{ns.taskCounter}}{{": " + task['summary']}}
{%- if task['description'] -%}
{{":\n"}}
{%- set descriptions = task['description'].split("\n") -%}
{% for subtask in descriptions-%}
{{" - "+subtask+'\n'}}
{%- endfor %}
{%- endif%}
{{"\n"}}
{%- endfor %}
enabled: false
mode: single
fields:
todolistname:
selector:
entity: {}
name: TodoListname
default: todo.my_tasks
@GraffJosh Thanks for the reply. I've also done some digging and have found that there is a character limit for the input_text entity.
This might be the reason it has stopped working for you. I haven't found any alternative solutions sadly
@GraffJosh and use of response_variable should work if you were using it to process and pass the list items onto other services.
@dbeltman what are you trying to with the items in the todo list?
The response variable is fine, but IMHO just. The reason I want to store it is because I often want to use a formatted version of the data, but I don't want to duplicate my formatting code everywhere.
If there were a "get Todo list pretty" service it would be a useful extension. Perhaps I can leverage the scripts to make that happen somehow (I'm new to HA scripts and templates generally so maybe it's more obvious than I imagine.)
Thanks.
I made a template sensor
that reads the items from the todo list and packs them in a comma-separated string. Basically uses what @GraffJosh explained above.
I should admit that service-call-return-values are difficult to parse.
template:
- trigger:
- platform: state
entity_id: todo.bunnings
action:
- service: todo.get_items
data:
status: needs_action
target:
entity_id: todo.bunnings
response_variable: items
sensor:
- name: Bunnings Items
unique_id: bunnings_items
state: "{{ (items.values() | list)[0]['items'] | map(attribute='summary') | list | join(', ') | truncate(255) }}"
Output is something like: Hammer, Pliers, Saw
.
There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved. If this issue is still relevant, please let us know by leaving a comment 👍 This issue has now has been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.
Programmatic interface with todo lists should be improved.
Oh, not stale...
Definitely need guidance on method to reference ToDo list items via template for use in a blueprint.
Thanks
Not only this is a problem, but there is no way to see what was last changed in todo items except the one special case that was created for "shopping_list". Why does shopping list have a special event called shopping_list_updated where I can get the last item added or removed, but regular todo lists and local_todo don't have these events? Doesn't make any sense to make one a special case and the others only fire the "state_changed" event.
Am also looking for a solution and ended up here searching. Based on the previous ideas I created this sensor:
This sensor puts the items in an attributes instead of the state. Attributes don't have the 255 limit and this is (for me at least) the way I would expect the todo.*
domain entities to report back their active items
template:
- trigger:
- platform: state
entity_id: todo.my_list
action:
- service: todo.get_items
data:
status: needs_action
target:
entity_id: todo.my_list
response_variable: items
sensor:
- name: Todo Items - My List
unique_id: bf95920f-27d6-4832-920b-463fcb3954ef
state: "{{ states('todo.my_list') | int }}"
attributes:
items: "{{ (items.values() | list)[0]['items'] | map(attribute='summary') | list }}"