This REST sensor is almost where I need it, how do I filter by a specific value?

The goal here is to filter the items section of the attributes to contain items for which the value of responsible_uid matches the UID I want. This will allow me to create a UI card on the dashboard that shows only the tasks that are assigned to a specific user in Todoist.

I tried adding a json_attributes_path to the sensor, but it returned blank results.

Here is the configuration I have that get me close to the result I need:

- platform: rest
  name: Tasks Household
  method: GET
  resource: ""
    project_id: !secret todoist_project_id_3
    Authorization: !secret todoist_api_token
  value_template: "{{ value_json['project']['id'] }}"
    - project
    - items
    - sections
  #json_attributes_path: "$.items[?(@.responsible_uid == '8740868')]"
  scan_interval: 60

This gives me a sensor with the project_id as the state, and three sections of data in the attributes (project / items / sections).

In the items section, we have something like the following, which represents the data from one task (this is one entry of many):

- added_at: '2023-02-25T22:24:49.562780Z'
  added_by_uid: '40849794'
  assigned_by_uid: '8740868'
  checked: false
  child_order: 15
  collapsed: false
  completed_at: null
  content: Cloth Diapers
  description: ''
    date: '2024-02-01'
    is_recurring: false
    lang: en
    string: Feb 1
    timezone: null
  duration: null
  id: '6650543035'
  is_deleted: false
  labels: []
  note_count: 0
  parent_id: null
  priority: 4
  project_id: '2297623587'
  responsible_uid: '40849794'
  section_id: null
  sync_id: '6650543032'
  updated_at: '2024-02-13T17:42:39Z'
  user_id: '8740868'
  v2_id: 68448GR99Pq6jGGJ
  v2_parent_id: null
  v2_project_id: 6JjmjqQMWf86CRjJ
  v2_section_id: null

I woud like to make the items attribute for the sensor only contain items where the responsible_uid is 40849794

Any ideas on how to do this correctly?

The only way I know (which does for sure not mean that is all :slight_smile: ) is via jq…this would mean to rewrite this as a command_line curl and add pipe through jq to filler and possibly recreate (format) the json message. I donot know the todoist json so cannot make more exact statements.

That’s out of my wheelhouse. What of the Todoist JSON would help you with the original problem? Do you need to see the resulting JSON from the GET command?

I can give it a stab but then indeed I need to have a full json output, you can remove most items just leave 2… one you want and one you donot want.
EDIT: to not pollute this post you can open a DM here or in discord (same username)

To my knowledge, you cannot do this (different JSON paths for individual attributes) directly all within one sensor. You could create a template sensor that pulls out those entries from the full list in the REST sensor, or use the REST integration and create two sensors from a single API request where the second one has the json_attributes_path.

  - resource: ""
      project_id: !secret todoist_project_id_3
      Authorization: !secret todoist_api_token
    scan_interval: 60
      - name: Tasks Household
        value_template: "{{ value_json['project']['id'] }}"
          - project
          - sections

      - name: Tasks 8740868
        value_template: "OK"
        json_attributes_path: "$.items[?(@.responsible_uid=='8740868')]"
          - items

I think the jq pre-filtering route is the only way with a REST sensor.

Now if we had json_attributes_template like the MQTT sensor does, it would be easy. Sadly, it’s been tried.

Boo lame. ;). The only workaround I can think of is making a completely separate project in Todoist for each user.

Or, I suppose I could do something like this directly in a Markdown card, but then I lose all of the functionality of the Todoist card in HACS. This below just creates a simple list of all tasks that were completed in Todois for a given day, regardless of the project they’re in. I would have to adjust it to pull from the correct sensor.

{% for group in states.sensor.tasks_completed.attributes['items']| groupby('project_id') %}
{% for item in group[1] | list %}
{% set borf = as_datetime(as_timestamp(strptime(item.completed_at[:19],"%Y-%m-%dT%H:%M:%S"))|int - 25200)|as_local()%}
{% if borf.strftime("%Y-%m-%d") == %}
{% endif %}
{% endfor %} 
{% endfor %}

I suppose I could group the “for item” by “responsible_uid” and that would split up the tasks.

You can construct the curl like this

curl "" -H (...your headers )  | jq '{items: .items[] | select(.responsible_uid == "40849794"), project: .project}'

you can first try it out from the cli …i.e. first make sure you get the json and then add the pipe through jq