Quantcast
Channel: Configuration - Home Assistant Community
Viewing all articles
Browse latest Browse all 95919

Garbage sensor from API json help

$
0
0

@jkkarlberg wrote:

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

Posts: 4

Participants: 2

Read full topic


Viewing all articles
Browse latest Browse all 95919

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>