Garbage sensor from API json help

Ok, so I’m trying to make a sensor that shows the type of garbage and the time it will be collected.
The code below I get from a curl or rest sensor

But it seems that I can’t make the sensors for it,
Anyone has any input to give?

[
  {
    "types": [
      {
        "type": "Tunna 1",
        "address": "Slånbärsvägen 1",
        "pickup_date": "2019-12-20",
        "zip_city": "Motala",
        "formatted": "20 dec",
        "has_deviating_date": false,
        "has_deviating_date_real": false,
        "message": "",
        "week_type": "Ordinarie"
      },
      {
        "type": "Tunna 2",
        "address": "Slånbärsvägen 1",
        "pickup_date": "2019-12-27",
        "zip_city": "Motala",
        "formatted": "27 dec",
        "has_deviating_date": false,
        "has_deviating_date_real": false,
        "message": "",
        "week_type": "Ordinarie"
      },
      {
        "type": "Trädgård",
        "address": "Slånbärsvägen 1",
        "pickup_date": "2020-04-07",
        "zip_city": "Motala",
        "formatted": "7 apr",
        "has_deviating_date": false,
        "has_deviating_date_real": false,
        "message": "",
        "week_type": "Ordinarie"
      }
    ],
    "address": "Slånbärsvägen 1",
    "city": "Motala",
    "has_deviating": false
  }
]

i have tried with both command line sensor and restful sensor

sensor:
  - platform: command_line
    command: "curl -XGET -H 'X-App-Identifier: 36202cbd6d9cbd54' 'https://motala.avfallsappen.se/wp-json/app/v1/next-pickup' | jq '.[] | {test:.types[]}'"
    name: test2
    value_template: "{{ value_json[0]['test']['type'] }}"

  - platform: rest
    resource: https://motala.avfallsappen.se/wp-json/app/v1/next-pickup
    headers:
      X-App-Identifier: 36202cbd6d9cbd54
      Content-type: application/json
    name: test4
    value_template: "{{ value_json[0].types[0] }}"
  #value_template: "{{ value_json[0]['type'] }}"
  #value_template: '{{ (value | from_json)[0].types }}'

i´ve tried parsing json response with jq but no luck there either.

It seems that my json respons is weird against the examples ive found by search

First, I would recommend not to share your API keys (X-App-Identifier…) on a public forum.

In this case, I would prefer the rest sensor over fetching the JSON via the command line.

I just tried your rest configuration, and get the following error message: Invalid state encountered for entity id: sensor.test4. State max length is 255 characters.
That means that the response is still too large, i.e. value_json[0].types[0] yields more than 255 characters.

Depending on what you actually want to extract from the JSON data, you should narrow down the template further. A good way to test your template code is to paste the whole JSON into the template editor and then fine-tune the template code there:

{% set value_json = [
  {
    "types": [
      ...
    ],
    "address": "Slånbärsvägen 1",
    "city": "Motala",
    "has_deviating": false
  }
]
%}
{{ value_json[0].types[0] }}

Thx, the api is public so no worries.

The response is to large for the rest sensor and I can’t narrow down the reasons from the api

OK, understood.
What I meant is, you are probably interested in certain aspects of the response. I would imagine in this case you may be interested in the pickup date, so you could change the template to:
{{ value_json[0].types[0]['pickup_date'] }}

And then you could have a second rest sensor for the other bin, etc.
{{ value_json[0].types[1]['pickup_date'] }}

If you only need 3 sensors in this case and only make a call once a day or so (see scan_interval) then making one rest call per sensor isn’t too bad.

Normally, I would use the rest sensor’s feature to store more data as attributes, but this particular JSON structure does not seem to be suitable for that approach - this only works if data is exposed as a top-level JSON attribute, but this JSON response is wrapped in an array.

Better late than never, maybe you have solved this already but here’s one way to do it.

It will work given the following conditions,

  1. If avfallsappen.se API works similiar for all municipalities.
  2. You have downloaded the app, registered your device and added the addresses for which you want to receive notifications for.
  3. The X-App-Identifier is from your registered device.

Where I live we have two bins picked up on different days, thus why I have created two sensors. The name of the bin and the pickup date is stored as attributes to the sensor.
(You have to change the first part of the resource URL to the municipality where you live, which is Motala I assume?)

  - platform: rest
    name: bins_0
    resource: https://knivsta.avfallsappen.se/wp-json/nova/v1/next-pickup/list?
    method: GET
    headers:
      X-App-Identifier: **put_your_identifier_here**
    json_attributes_path: "$.[0].bins[0]"
    json_attributes:
      - type
      - pickup_date
    value_template: '{{ value_json[0].address }}'
    
  - platform: rest
    name: bins_1
    resource: https://knivsta.avfallsappen.se/wp-json/nova/v1/next-pickup/list?
    method: GET
    headers:
      X-App-Identifier: **put_your_identifier_here**
    json_attributes_path: "$.[0].bins[1]"
    json_attributes:
      - type
      - pickup_date
    value_template: '{{ value_json[0].address }}'

You can then create entity cards like this:
image