Help with RESTful Sensor

Hi,

im trying to scrape the dep time from my nearest bus stop. But i realy suck att configuring the rest sensor. Usually i can find some similar code but not so far.

This is what i have tried but keep getting errors.

  • platform: rest
    name: Buss avgångar
    resource: https://api.resrobot.se/v2/departureBoard?key=secretapi&id=740007742&maxJourneys=4&format=json
    json_attributes:

    • departure1
    • departure2
    • departure3
    • departure4
      value_template: ‘OK’
  • platform: template
    sensors:
    avgang1:
    value_template: ‘{{ states.sensor.“depTime” :[“departure1”] }}’
    avgang2:
    value_template: ‘{{ states.sensor.“depTime” :[“departure2”] }}’
    avgang3:
    value_template: ‘{{ states.sensor.“depTime” :[“departure3”] }}’
    avgang4:
    value_template: ‘{{ states.sensor.“depTime” :[“departure4”] }}’

I have underlined the times i wan’t to scrape to a sensor(four sensors).

{
“Stop” : [ {
“name” : “Gottsunda Granelidsvägen (Uppsala kn)”,
“id” : “740007742”,
“extId” : “740007742”,
“routeIdx” : 11,
“lon” : 17.615181,
“lat” : 59.799822,
“depTime” : “23:56:00”,
“depDate” : “2019-11-19”
},
{
“Stop” : [ {
“name” : “Gottsunda Granelidsvägen (Uppsala kn)”,
“id” : “740007742”,
“extId” : “740007742”,
“routeIdx” : 17,
“lon” : 17.615181,
“lat” : 59.799822,
“depTime” : “00:02:00”,
“depDate” : “2019-11-20”
},
{
“Stop” : [ {
“name” : “Gottsunda Granelidsvägen (Uppsala kn)”,
“id” : “740007742”,
“extId” : “740007742”,
“routeIdx” : 11,
“lon” : 17.615181,
“lat” : 59.799822,
“depTime” : “00:26:00”,
“depDate” : “2019-11-20”
},
{
“Stop” : [ {
“name” : “Gottsunda Granelidsvägen (Uppsala kn)”,
“id” : “740007742”,
“extId” : “740007742”,
“routeIdx” : 17,
“lon” : 17.615181,
“lat” : 59.799822,
“depTime” : “00:32:00”,
“depDate” : “2019-11-20”
},
appricate all the help i can get.

Please post the full json output from the api call. Also, the json you posted is malformed, there are a few missing end brackets, i.e. ]. Please use the </> button when you post so that your json gets properly formatted.

And you need a value_template for each sensor. Try this instead:

  - platform: rest
    name: First departure
    resource: https://api.resrobot.se/v2/departureBoard?key=secretapi&id=740007742&maxJourneys=4&format=json
    value_template: '{{value_json["Stop"][0].depTime}}'

  - platform: rest
    name: Second departure
    resource: https://api.resrobot.se/v2/departureBoard?key=secretapi&id=740007742&maxJourneys=4&format=json
    value_template: '{{value_json["Stop"][1].depTime}}'

Hi,

Thanks for the help. It’s really appreciated:grinning:

The sensor shows up in ha but i reports unknow in as a value (in swedish okänd).

Im posting all the json code from the api inside the </> . Hopefully it’s right:-)

I tried playing with the rest commands a bit but to no help.

{
  "Departure" : [ {
    "Product" : {
      "name" : "Länstrafik - Buss 11",
      "num" : "11",
      "catCode" : "7",
      "catOutS" : "BLT",
      "catOutL" : "Länstrafik - Buss",
      "operatorCode" : "251",
      "operator" : "UL",
      "operatorUrl" : "http://www.ul.se/"
    },
    "Stops" : {
      "Stop" : [ {
        "name" : "Gottsunda Granelidsvägen (Uppsala kn)",
        "id" : "740007742",
        "extId" : "740007742",
        "routeIdx" : 17,
        "lon" : 17.615181,
        "lat" : 59.799822,
        "depTime" : "19:58:00",
        "depDate" : "2019-11-20"
      }, {
        "name" : "Vårdsätra Slånvägen (Uppsala kn)",
        "id" : "740007741",
        "extId" : "740007741",
        "routeIdx" : 18,
        "lon" : 17.619954,
        "lat" : 59.795265,
        "arrTime" : "19:59:00",
        "arrDate" : "2019-11-20"
      }, {
        "name" : "Vårdsätra Gullvivevägen (Uppsala kn)",
        "id" : "740007739",
        "extId" : "740007739",
        "routeIdx" : 19,
        "lon" : 17.623577,
        "lat" : 59.791651,
        "arrTime" : "20:00:00",
        "arrDate" : "2019-11-20"
      }, {
        "name" : "Uppsala Lyssnavägen",
        "id" : "740007648",
        "extId" : "740007648",
        "routeIdx" : 20,
        "lon" : 17.634364,
        "lat" : 59.786662,
        "arrTime" : "20:02:00",
        "arrDate" : "2019-11-20"
      }, {
        "name" : "Uppsala Granebergsparken",
        "id" : "740007647",
        "extId" : "740007647",
        "routeIdx" : 21,
        "lon" : 17.637546,
        "lat" : 59.787822,
        "arrTime" : "20:02:00",
        "arrDate" : "2019-11-20"
      }, {
        "name" : "Uppsala Trasthagen",
        "id" : "740007728",
        "extId" : "740007728",
        "routeIdx" : 22,
        "lon" : 17.645295,
        "lat" : 59.790204,
        "arrTime" : "20:04:00",
        "arrDate" : "2019-11-20"
      }, {
        "name" : "Uppsala Svankärrsvägen",
        "id" : "740007727",
        "extId" : "740007727",
        "routeIdx" : 23,
        "lon" : 17.643497,
        "lat" : 59.792442,
        "arrTime" : "20:05:00",
        "arrDate" : "2019-11-20"
      }, {
        "name" : "Uppsala Långvägen",
        "id" : "740007438",
        "extId" : "740007438",
        "routeIdx" : 24,
        "lon" : 17.641438,
        "lat" : 59.796802,
        "arrTime" : "20:06:00",
        "arrDate" : "2019-11-20"
      }, {
        "name" : "Uppsala Entitparken",
        "id" : "740007437",
        "extId" : "740007437",
        "routeIdx" : 25,
        "lon" : 17.644027,
        "lat" : 59.799588,
        "arrTime" : "20:07:00",
        "arrDate" : "2019-11-20"
      }, {
        "name" : "Uppsala Morkullevägen",
        "id" : "740007435",
        "extId" : "740007435",
        "routeIdx" : 26,
        "lon" : 17.644045,
        "lat" : 59.803013,
        "arrTime" : "20:07:00",
        "arrDate" : "2019-11-20"
      }, {
        "name" : "Gottsunda Orkestervägen (Uppsala kn)",
        "id" : "740007434",
        "extId" : "740007434",
        "routeIdx" : 27,
        "lon" : 17.63813,
        "lat" : 59.806393,
        "arrTime" : "20:08:00",
        "arrDate" : "2019-11-20"
      }, {
        "name" : "Uppsala Gottsunda torg",
        "id" : "740007367",
        "extId" : "740007367",
        "routeIdx" : 28,
        "lon" : 17.628017,
        "lat" : 59.811391,
        "arrTime" : "20:12:00",
        "arrDate" : "2019-11-20"
      } ]
    },
    "name" : "Länstrafik - Buss 11",
    "type" : "S",
    "stop" : "Gottsunda Granelidsvägen (Uppsala kn)",
    "stopid" : "740007742",
    "stopExtId" : "740007742",
    "time" : "19:58:00",
    "date" : "2019-11-20",
    "direction" : "Uppsala Gottsunda torg",
    "transportNumber" : "11",
    "transportCategory" : "BLT"
  }, {
    "Product" : {
      "name" : "Länstrafik - Buss 11",
      "num" : "11",
      "catCode" : "7",
      "catOutS" : "BLT",
      "catOutL" : "Länstrafik - Buss",
      "operatorCode" : "251",
      "operator" : "UL",
      "operatorUrl" : "http://www.ul.se/"
    },
    "Stops" : {
      "Stop" : [ {
        "name" : "Gottsunda Granelidsvägen (Uppsala kn)",
        "id" : "740007742",
        "extId" : "740007742",
        "routeIdx" : 11,
        "lon" : 17.615181,
        "lat" : 59.799822,
        "depTime" : "20:10:00",
        "depDate" : "2019-11-20"
      }, {
        "name" : "Vårdsätravik (Uppsala kn)",
        "id" : "740007743",
        "extId" : "740007743",
        "routeIdx" : 12,
        "lon" : 17.609509,
        "lat" : 59.801144,
        "arrTime" : "20:11:00",
        "arrDate" : "2019-11-20"
      }, {
        "name" : "Lurbo bro (Uppsala kn)",
        "id" : "740007744",
        "extId" : "740007744",
        "routeIdx" : 13,
        "lon" : 17.60576,
        "lat" : 59.805647,
        "arrTime" : "20:12:00",
        "arrDate" : "2019-11-20"
      }, {
        "name" : "Gottsunda Gottsundavägen (Uppsala kn)",
        "id" : "740007746",
        "extId" : "740007746",
        "routeIdx" : 14,
        "lon" : 17.607648,
        "lat" : 59.808488,
        "arrTime" : "20:12:00",
        "arrDate" : "2019-11-20"
      }, {
        "name" : "Gottsunda Djurgårdsvägen (Uppsala kn)",
        "id" : "740007747",
        "extId" : "740007747",
        "routeIdx" : 15,
        "lon" : 17.610731,
        "lat" : 59.814106,
        "arrTime" : "20:13:00",
        "arrDate" : "2019-11-20"
      }, {
        "name" : "Gottsunda Källbovägen (Uppsala kn)",
        "id" : "740007748",
        "extId" : "740007748",
        "routeIdx" : 16,
        "lon" : 17.612268,
        "lat" : 59.816803,
        "arrTime" : "20:14:00",
        "arrDate" : "2019-11-20"
      }, {
        "name" : "Gottsunda Martallsvägen (Uppsala kn)",
        "id" : "740007749",
        "extId" : "740007749",
        "routeIdx" : 17,
        "lon" : 17.616367,
        "lat" : 59.819706,
        "arrTime" : "20:15:00",
        "arrDate" : "2019-11-20"
      }, {
        "name" : "Uppsala Slädvägen",
        "id" : "740038274",
        "extId" : "740038274",
        "routeIdx" : 18,
        "lon" : 17.625869,
        "lat" : 59.822754,
        "arrTime" : "20:16:00",
        "arrDate" : "2019-11-20"
      }, {
        "name" : "Uppsala Tallbacksvägen",
        "id" : "740007373",
        "extId" : "740007373",
        "routeIdx" : 19,
        "lon" : 17.62968,
        "lat" : 59.826538,
        "arrTime" : "20:17:00",
        "arrDate" : "2019-11-20"
      }, {
        "name" : "Uppsala Rosendal skola",
        "id" : "740007375",
        "extId" : "740007375",
        "routeIdx" : 20,
        "lon" : 17.639784,
        "lat" : 59.832552,
        "arrTime" : "20:19:00",
        "arrDate" : "2019-11-20"
      }, {
        "name" : "Uppsala Grindstugan",
        "id" : "740007374",
        "extId" : "740007374",
        "routeIdx" : 21,
        "lon" : 17.639802,
        "lat" : 59.839995,
        "arrTime" : "20:21:00",
        "arrDate" : "2019-11-20"
      }, {
        "name" : "Uppsala Science Park",
        "id" : "740007825",
        "extId" : "740007825",
        "routeIdx" : 22,
        "lon" : 17.638616,
        "lat" : 59.843168,
        "arrTime" : "20:22:00",
        "arrDate" : "2019-11-20"
      }, {
        "name" : "Uppsala Akademiska sjukhuset västra",
        "id" : "740071739",
        "extId" : "740071739",
        "routeIdx" : 23,
        "lon" : 17.636422,
        "lat" : 59.849371,
        "arrTime" : "20:23:00",
        "arrDate" : "2019-11-20"
      }, {
        "name" : "Uppsala Segerstedthuset",
        "id" : "740007418",
        "extId" : "740007418",
        "routeIdx" : 24,
        "lon" : 17.634031,
        "lat" : 59.852265,
        "arrTime" : "20:24:00",
        "arrDate" : "2019-11-20"
      }, {
        "name" : "Uppsala Slottsbacken",
        "id" : "740007417",
        "extId" : "740007417",
        "routeIdx" : 25,
        "lon" : 17.632368,
        "lat" : 59.854764,
        "arrTime" : "20:25:00",
        "arrDate" : "2019-11-20"
      }, {
        "name" : "Uppsala Trädgårdsgatan",
        "id" : "740007416",
        "extId" : "740007416",
        "routeIdx" : 26,
        "lon" : 17.635523,
        "lat" : 59.856949,
        "arrTime" : "20:25:00",
        "arrDate" : "2019-11-20"
      }, {
        "name" : "Uppsala Stora Torget",
        "id" : "740007354",
        "extId" : "740007354",
        "routeIdx" : 27,
        "lon" : 17.63902,
        "lat" : 59.858549,
        "arrTime" : "20:28:00",
        "arrDate" : "2019-11-20"
      }, {
        "name" : "Uppsala Centralstation",
        "id" : "740000005",
        "extId" : "740000005",
        "routeIdx" : 28,
        "lon" : 17.646086,
        "lat" : 59.858531,
        "arrTime" : "20:30:00",
        "arrDate" : "2019-11-20"
      } ]
    },
    "name" : "Länstrafik - Buss 11",
    "type" : "S",
    "stop" : "Gottsunda Granelidsvägen (Uppsala kn)",
    "stopid" : "740007742",
    "stopExtId" : "740007742",
    "time" : "20:10:00",
    "date" : "2019-11-20",
    "direction" : "Uppsala Centralstation",
    "transportNumber" : "11",
    "transportCategory" : "BLT"
  }, {
    "Product" : {
      "name" : "Länstrafik - Buss 11",
      "num" : "11",
      "catCode" : "7",
      "catOutS" : "BLT",
      "catOutL" : "Länstrafik - Buss",
      "operatorCode" : "251",
      "operator" : "UL",
      "operatorUrl" : "http://www.ul.se/"
    },
    "Stops" : {
      "Stop" : [ {
        "name" : "Gottsunda Granelidsvägen (Uppsala kn)",
        "id" : "740007742",
        "extId" : "740007742",
        "routeIdx" : 17,
        "lon" : 17.615181,
        "lat" : 59.799822,
        "depTime" : "20:13:00",
        "depDate" : "2019-11-20"
      }, {
        "name" : "Vårdsätra Slånvägen (Uppsala kn)",
        "id" : "740007741",
        "extId" : "740007741",
        "routeIdx" : 18,
        "lon" : 17.619954,
        "lat" : 59.795265,
        "arrTime" : "20:14:00",
        "arrDate" : "2019-11-20"
      }, {
        "name" : "Vårdsätra Gullvivevägen (Uppsala kn)",
        "id" : "740007739",
        "extId" : "740007739",
        "routeIdx" : 19,
        "lon" : 17.623577,
        "lat" : 59.791651,
        "arrTime" : "20:15:00",
        "arrDate" : "2019-11-20"
      }, {
        "name" : "Uppsala Lyssnavägen",
        "id" : "740007648",
        "extId" : "740007648",
        "routeIdx" : 20,
        "lon" : 17.634364,
        "lat" : 59.786662,
        "arrTime" : "20:16:00",
        "arrDate" : "2019-11-20"
      }, {
        "name" : "Uppsala Granebergsparken",
        "id" : "740007647",
        "extId" : "740007647",
        "routeIdx" : 21,
        "lon" : 17.637546,
        "lat" : 59.787822,
        "arrTime" : "20:16:00",
        "arrDate" : "2019-11-20"
      }, {
        "name" : "Uppsala Trasthagen",
        "id" : "740007728",
        "extId" : "740007728",
        "routeIdx" : 22,
        "lon" : 17.645295,
        "lat" : 59.790204,
        "arrTime" : "20:18:00",
        "arrDate" : "2019-11-20"
      }, {
        "name" : "Uppsala Svankärrsvägen",
        "id" : "740007727",
        "extId" : "740007727",
        "routeIdx" : 23,
        "lon" : 17.643497,
        "lat" : 59.792442,
        "arrTime" : "20:19:00",
        "arrDate" : "2019-11-20"
      }, {
        "name" : "Uppsala Långvägen",
        "id" : "740007438",
        "extId" : "740007438",
        "routeIdx" : 24,
        "lon" : 17.641438,
        "lat" : 59.796802,
        "arrTime" : "20:20:00",
        "arrDate" : "2019-11-20"
      }, {
        "name" : "Uppsala Entitparken",
        "id" : "740007437",
        "extId" : "740007437",
        "routeIdx" : 25,
        "lon" : 17.644027,
        "lat" : 59.799588,
        "arrTime" : "20:21:00",
        "arrDate" : "2019-11-20"
      }, {
        "name" : "Uppsala Morkullevägen",
        "id" : "740007435",
        "extId" : "740007435",
        "routeIdx" : 26,
        "lon" : 17.644045,
        "lat" : 59.803013,
        "arrTime" : "20:21:00",
        "arrDate" : "2019-11-20"
      }, {
        "name" : "Gottsunda Orkestervägen (Uppsala kn)",
        "id" : "740007434",
        "extId" : "740007434",
        "routeIdx" : 27,
        "lon" : 17.63813,
        "lat" : 59.806393,
        "arrTime" : "20:22:00",
        "arrDate" : "2019-11-20"
      }, {
        "name" : "Uppsala Gottsunda torg",
        "id" : "740007367",
        "extId" : "740007367",
        "routeIdx" : 28,
        "lon" : 17.628017,
        "lat" : 59.811391,
        "arrTime" : "20:26:00",
        "arrDate" : "2019-11-20"
      } ]
    },
    "name" : "Länstrafik - Buss 11",
    "type" : "S",
    "stop" : "Gottsunda Granelidsvägen (Uppsala kn)",
    "stopid" : "740007742",
    "stopExtId" : "740007742",
    "time" : "20:13:00",
    "date" : "2019-11-20",
    "direction" : "Uppsala Gottsunda torg",
    "transportNumber" : "11",
    "transportCategory" : "BLT"
  }, {
    "Product" : {
      "name" : "Länstrafik - Buss 11",
      "num" : "11",
      "catCode" : "7",
      "catOutS" : "BLT",
      "catOutL" : "Länstrafik - Buss",
      "operatorCode" : "251",
      "operator" : "UL",
      "operatorUrl" : "http://www.ul.se/"
    },
    "Stops" : {
      "Stop" : [ {
        "name" : "Gottsunda Granelidsvägen (Uppsala kn)",
        "id" : "740007742",
        "extId" : "740007742",
        "routeIdx" : 11,
        "lon" : 17.615181,
        "lat" : 59.799822,
        "depTime" : "20:30:00",
        "depDate" : "2019-11-20"
      }, {
        "name" : "Vårdsätravik (Uppsala kn)",
        "id" : "740007743",
        "extId" : "740007743",
        "routeIdx" : 12,
        "lon" : 17.609509,
        "lat" : 59.801144,
        "arrTime" : "20:31:00",
        "arrDate" : "2019-11-20"
      }, {
        "name" : "Lurbo bro (Uppsala kn)",
        "id" : "740007744",
        "extId" : "740007744",
        "routeIdx" : 13,
        "lon" : 17.60576,
        "lat" : 59.805647,
        "arrTime" : "20:32:00",
        "arrDate" : "2019-11-20"
      }, {
        "name" : "Gottsunda Gottsundavägen (Uppsala kn)",
        "id" : "740007746",
        "extId" : "740007746",
        "routeIdx" : 14,
        "lon" : 17.607648,
        "lat" : 59.808488,
        "arrTime" : "20:32:00",
        "arrDate" : "2019-11-20"
      }, {
        "name" : "Gottsunda Djurgårdsvägen (Uppsala kn)",
        "id" : "740007747",
        "extId" : "740007747",
        "routeIdx" : 15,
        "lon" : 17.610731,
        "lat" : 59.814106,
        "arrTime" : "20:33:00",
        "arrDate" : "2019-11-20"
      }, {
        "name" : "Gottsunda Källbovägen (Uppsala kn)",
        "id" : "740007748",
        "extId" : "740007748",
        "routeIdx" : 16,
        "lon" : 17.612268,
        "lat" : 59.816803,
        "arrTime" : "20:34:00",
        "arrDate" : "2019-11-20"
      }, {
        "name" : "Gottsunda Martallsvägen (Uppsala kn)",
        "id" : "740007749",
        "extId" : "740007749",
        "routeIdx" : 17,
        "lon" : 17.616367,
        "lat" : 59.819706,
        "arrTime" : "20:35:00",
        "arrDate" : "2019-11-20"
      }, {
        "name" : "Uppsala Slädvägen",
        "id" : "740038274",
        "extId" : "740038274",
        "routeIdx" : 18,
        "lon" : 17.625869,
        "lat" : 59.822754,
        "arrTime" : "20:36:00",
        "arrDate" : "2019-11-20"
      }, {
        "name" : "Uppsala Tallbacksvägen",
        "id" : "740007373",
        "extId" : "740007373",
        "routeIdx" : 19,
        "lon" : 17.62968,
        "lat" : 59.826538,
        "arrTime" : "20:37:00",
        "arrDate" : "2019-11-20"
      }, {
        "name" : "Uppsala Rosendal skola",
        "id" : "740007375",
        "extId" : "740007375",
        "routeIdx" : 20,
        "lon" : 17.639784,
        "lat" : 59.832552,
        "arrTime" : "20:39:00",
        "arrDate" : "2019-11-20"
      }, {
        "name" : "Uppsala Grindstugan",
        "id" : "740007374",
        "extId" : "740007374",
        "routeIdx" : 21,
        "lon" : 17.639802,
        "lat" : 59.839995,
        "arrTime" : "20:41:00",
        "arrDate" : "2019-11-20"
      }, {
        "name" : "Uppsala Science Park",
        "id" : "740007825",
        "extId" : "740007825",
        "routeIdx" : 22,
        "lon" : 17.638616,
        "lat" : 59.843168,
        "arrTime" : "20:42:00",
        "arrDate" : "2019-11-20"
      }, {
        "name" : "Uppsala Akademiska sjukhuset västra",
        "id" : "740071739",
        "extId" : "740071739",
        "routeIdx" : 23,
        "lon" : 17.636422,
        "lat" : 59.849371,
        "arrTime" : "20:43:00",
        "arrDate" : "2019-11-20"
      }, {
        "name" : "Uppsala Segerstedthuset",
        "id" : "740007418",
        "extId" : "740007418",
        "routeIdx" : 24,
        "lon" : 17.634031,
        "lat" : 59.852265,
        "arrTime" : "20:44:00",
        "arrDate" : "2019-11-20"
      }, {
        "name" : "Uppsala Slottsbacken",
        "id" : "740007417",
        "extId" : "740007417",
        "routeIdx" : 25,
        "lon" : 17.632368,
        "lat" : 59.854764,
        "arrTime" : "20:45:00",
        "arrDate" : "2019-11-20"
      }, {
        "name" : "Uppsala Trädgårdsgatan",
        "id" : "740007416",
        "extId" : "740007416",
        "routeIdx" : 26,
        "lon" : 17.635523,
        "lat" : 59.856949,
        "arrTime" : "20:45:00",
        "arrDate" : "2019-11-20"
      }, {
        "name" : "Uppsala Stora Torget",
        "id" : "740007354",
        "extId" : "740007354",
        "routeIdx" : 27,
        "lon" : 17.63902,
        "lat" : 59.858549,
        "arrTime" : "20:48:00",
        "arrDate" : "2019-11-20"
      }, {
        "name" : "Uppsala Centralstation",
        "id" : "740000005",
        "extId" : "740000005",
        "routeIdx" : 28,
        "lon" : 17.646086,
        "lat" : 59.858531,
        "arrTime" : "20:50:00",
        "arrDate" : "2019-11-20"
      } ]
    },
    "name" : "Länstrafik - Buss 11",
    "type" : "S",
    "stop" : "Gottsunda Granelidsvägen (Uppsala kn)",
    "stopid" : "740007742",
    "stopExtId" : "740007742",
    "time" : "20:30:00",
    "date" : "2019-11-20",
    "direction" : "Uppsala Centralstation",
    "transportNumber" : "11",
    "transportCategory" : "BLT"
  } ]
}

I got it working but unfortuantly the memorycard got corrupt and i had no backup.
But i can’t remember what i did to get it working.

value_template: ‘{{value_json[“Departure”][0].name}}’ manage to scrape “Länstrafik - Buss 11”
But i want to scrape the “depTime” one section down and can’t get that to work.

Thanks for the help

Hi @Trampare, did you ever got this to work? Any plans on making an integration/component of it? I want to do the same but don’t have the programming skills :grinning: