Sign inSign up

dielee/local-todo-card

By dielee

Updated over 5 years ago

Python backend for https://github.com/Dielee/localToDo-card

Image
0

303

dielee/local-todo-card repository overview

Local ToDo Card

Thanks to @grinstantin for the base js card.

Local ToDo card for Home Assistant Lovelace UI. This card displays items from local SQLite database.

Preview of todoist-card

Installing

JS Card
  1. Download localtodo-card.js file from the latest release.
  2. Put localtodo-card.js file into your config/www folder.
  3. Add a reference to localtodo-card.js in Lovelace. There's two way to do that:
    1. Using UI: ConfigurationLovelace DashboardsResources → Click Plus button → Set Url as /local/localtodo-card.js → Set Resource type as JavaScript Module.
    2. Using YAML: Add the following code to lovelace section.
      resources:
        - url: /local/localtodo-card.js
          type: module
      
  4. Add custom:localtodo-card to Lovelace UI as any other card (using either editor or YAML configuration).
Setup DB Server

i. Docker

docker pull dielee/local-todo-card:latest
docker run -d -p ExternalPort:5556 --name "localToDo" -e toDoLanguage="yourLanguage" -e toDoPersons="Person1,Person2,Person3" dielee/local-todo-card:latest

ii. Manual

  1. Change settings in config.yaml to your needs
  2. Install flask pip3 install flask, PyYAML
  3. Run main.py from /src python3 __init__.py

Using the card

This card can be configured using Lovelace UI editor.

  1. Add the following code to configuration.yaml:

    sensor:
      - platform: rest
        name: To-do List
        method: GET
        resource: 'http://ipServerRuns:port/getToDoListItems'
        value_template: '{{value_json[''project''][''id'']}}'
        json_attributes:
          - items
          - settings
        scan_interval: 30
    
    rest_command:
      todoist:
        method: post
        url: 'http://ipServerRuns:port/setToDoListItems'
        payload: commands={{commands}}
        content_type: 'application/x-www-form-urlencoded'
    
  2. Reload configs or restart Home Assistant.

  3. In Lovelace UI, click 3 dots in top left corner.

  4. Click Edit Dashboard.

  5. Click Add Card button in the bottom right corner to add a new card.

  6. Find Custom: Todoist Card in the list.

  7. Choose entity.

  8. Now you should see the preview of the card!

Typical example of using this card in YAML config would look like this:

type: 'custom:localtodo-card'
entity: sensor.to_do_list
name: 'Aufgaben'
done_tasks: 2
show_header: true
show_item_add: true
show_item_close: true
show_item_delete: true
show_item_edit: true

Here is what every option means:

NameTypeDefaultDescription
typestringrequiredcustom:todoist-card
entitystringrequiredAn entity_id within the sensor domain.
namestringTop card Name.
done_tasksintShow done tasks in days
show_headerbooleantrueShow friendly name of the selected sensor in the card header.
show_item_addbooleantrueShow text input element for adding new items to the list.
show_item_closebooleantrueShow close/complete buttons.
show_item_deletebooleantrueShow delete buttons.
show_item_editbooleantrueShow edit buttons.
show_item_editbooleantrueShow pin buttons.

Adding tasks via HomeAssistant Automation/Script

rest_command:
  todoistmanualadd:
    method: post
    url: 'http://192.168.50.2:5556/setToDoListItems'
    payload: 'commands=[{"type":"item_add","temp_id":"{{ now() | as_timestamp()}}","args":{"content":"{{content}}", "responsePerson":"{{responsePerson}}"}}]'
    content_type: 'application/x-www-form-urlencoded'

Automation/script action:

    - service: rest_command.todoistmanualadd
      data:
        content: "Task name here"
        responsePerson: "Person name here" #optional

Notify people about new tasks

 sensors:
   - platform: template
     sensors:
         OneNameFromConfigYaml_tasks:
           value_template: >-
              {% set value_json = state_attr('sensor.to_do_list','items') %}
              {% set tasks = value_json | selectattr ('responsePerson', 'eq', '<OneNameFromConfigYaml>') | selectattr ('checked', 'eq', 0) | map(attribute='content') | list %}
              {% set values = namespace(content=[]) %}

              {% for task in tasks %}
              {% set values.content = values.content + [task] %}
              {% endfor %}

              {% set cnt = {'tasks':values.content | count  } %}
              {{ cnt.tasks }}
           attribute_templates:
             tasks: >-
              {% set value_json = state_attr('sensor.to_do_list','items') %}
              {% set tasks = value_json | selectattr ('responsePerson', 'eq', '<OneNameFromConfigYaml>') | selectattr ('checked', 'eq', 0) | map(attribute='content') | list %}
              {% set values = namespace(content=[]) %}

              {% for task in tasks %}
              {% set values.content = values.content + [task] %}
              {% endfor %}

              {{ {'tasks':values.content} }}

automation:
   alias: Notify_linus_newTask
   description: ''
   trigger:
     - platform: state
       entity_id: sensor.<OneNameFromConfigYaml_tasks>
   condition:
     - condition: template
       value_template: '{{ trigger.from_state.state | int < trigger.to_state.state | int  }}'
   action:
     - service: notify.mobile_app_ac2003
       data:
         title: Dir wurde eine neue Aufgabe zugewiesen!
         message: >-
           {% set aufgaben = state_attr('sensor.<OneNameFromConfigYaml_tasks>', 'tasks')['tasks'] %}
           Folgende Aufgaben sind dir aktuell zugewiesen: 

           {{ aufgaben | replace('[','') | replace (']','') | replace ("'","") }}
         data:
           actions:
             - action: URI
               title: Aufgaben ansehen
               uri: /lovelace-temp/6
   mode: single

Actions

  • Circle marks selected task as completed.
  • Click on Text marks selected task as completed..
  • Trash bin deletes selected task.
  • Pencil Edit selected task
  • Pin Pins the item on top of the card.
  • Input adds new item to the list after pressing button Save.

Tag summary

Content type

Image

Digest

Size

342.3 MB

Last updated

over 5 years ago

docker pull dielee/local-todo-card