home-assistant.io icon indicating copy to clipboard operation
home-assistant.io copied to clipboard

TODO list get items

Open GraffJosh opened this issue 1 year ago • 11 comments

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

GraffJosh avatar Dec 14 '23 22:12 GraffJosh

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.

home-assistant[bot] avatar Dec 14 '23 22:12 home-assistant[bot]

Running into this as well

dbeltman avatar Dec 20 '23 00:12 dbeltman

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

image

GraffJosh avatar Dec 20 '23 13:12 GraffJosh

@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

dbeltman avatar Dec 20 '23 23:12 dbeltman

@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?

dannytsang avatar Jan 01 '24 12:01 dannytsang

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.

GraffJosh avatar Jan 01 '24 15:01 GraffJosh

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.

manunited10 avatar Jan 17 '24 00:01 manunited10

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.

github-actions[bot] avatar Mar 23 '24 13:03 github-actions[bot]

Programmatic interface with todo lists should be improved.

GraffJosh avatar Mar 23 '24 13:03 GraffJosh

Oh, not stale...

Definitely need guidance on method to reference ToDo list items via template for use in a blueprint.

Thanks

Cybyst avatar Mar 25 '24 18:03 Cybyst

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.

mfed3 avatar May 04 '24 23:05 mfed3

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 }}"

benjamin-dcs avatar Sep 06 '24 06:09 benjamin-dcs