I have created a REST sensor that saves this date in the sensor state.
{
"StatusCode": 0,
"Message": null,
"ExecutionTime": 95,
"ResponseData": {
"LatestUpdate": "2017-08-24T14:05:39",
"DataAge": 33,
"Metros": [],
"Buses": [
{
"GroupOfLine": null,
"TransportMode": "BUS",
"LineNumber": "828",
"Destination": "Farsta centrum",
"JourneyDirection": 2,
"StopAreaName": "Odonbacken",
"StopAreaNumber": 70874,
"StopPointNumber": 70874,
"StopPointDesignation": null,
"TimeTabledDateTime": "2017-08-24T14:10:31",
"ExpectedDateTime": "2017-08-24T14:11:40",
"DisplayTime": "5 min",
"JourneyNumber": 36,
"Deviations": null
},
{
"GroupOfLine": null,
"TransportMode": "BUS",
"LineNumber": "828",
"Destination": "Östra Skogås",
"JourneyDirection": 1,
"StopAreaName": "Odonbacken",
"StopAreaNumber": 70874,
"StopPointNumber": 70875,
"StopPointDesignation": null,
"TimeTabledDateTime": "2017-08-24T14:19:32",
"ExpectedDateTime": "2017-08-24T14:19:32",
"DisplayTime": "13 min",
"JourneyNumber": 33,
"Deviations": null
},
{
"GroupOfLine": null,
"TransportMode": "BUS",
"LineNumber": "831",
"Destination": "Farsta centrum",
"JourneyDirection": 2,
"StopAreaName": "Odonbacken",
"StopAreaNumber": 70874,
"StopPointNumber": 70874,
"StopPointDesignation": null,
"TimeTabledDateTime": "2017-08-24T14:25:31",
"ExpectedDateTime": "2017-08-24T14:25:31",
"DisplayTime": "14:25",
"JourneyNumber": 40,
"Deviations": null
},
{
"GroupOfLine": null,
"TransportMode": "BUS",
"LineNumber": "831",
"Destination": "Länna industriområde",
"JourneyDirection": 1,
"StopAreaName": "Odonbacken",
"StopAreaNumber": 70874,
"StopPointNumber": 70875,
"StopPointDesignation": null,
"TimeTabledDateTime": "2017-08-24T14:34:32",
"ExpectedDateTime": "2017-08-24T14:34:32",
"DisplayTime": "28 min",
"JourneyNumber": 37,
"Deviations": null
},
{
"GroupOfLine": null,
"TransportMode": "BUS",
"LineNumber": "828",
"Destination": "Farsta centrum",
"JourneyDirection": 2,
"StopAreaName": "Odonbacken",
"StopAreaNumber": 70874,
"StopPointNumber": 70874,
"StopPointDesignation": null,
"TimeTabledDateTime": "2017-08-24T14:40:31",
"ExpectedDateTime": "2017-08-24T14:40:31",
"DisplayTime": "14:40",
"JourneyNumber": 38,
"Deviations": null
},
{
"GroupOfLine": null,
"TransportMode": "BUS",
"LineNumber": "828",
"Destination": "Östra Skogås",
"JourneyDirection": 1,
"StopAreaName": "Odonbacken",
"StopAreaNumber": 70874,
"StopPointNumber": 70875,
"StopPointDesignation": null,
"TimeTabledDateTime": "2017-08-24T14:49:32",
"ExpectedDateTime": "2017-08-24T14:49:32",
"DisplayTime": "14:49",
"JourneyNumber": 35,
"Deviations": null
}
],
"Trains": [],
"Trams": [],
"Ships": [],
"StopPointDeviations": []
}
}
I try to parse this date in a template with
{% set sl = states.sensor.sl_odonbacken.state %}
{{sl.StatusCode}}
I get a blank. If I look at {{sl}} it shows the json object.
If I paste the JSON from the sensor state and run this code
{% set sl ={
"StatusCode": 0,
"Message": null,
"ExecutionTime": 95,
"ResponseData": {
"LatestUpdate": "2017-08-24T14:05:39",
"DataAge": 33,
"Metros": [],
"Buses": [
{
"GroupOfLine": null,
"TransportMode": "BUS",
"LineNumber": "828",
"Destination": "Farsta centrum",
"JourneyDirection": 2,
"StopAreaName": "Odonbacken",
"StopAreaNumber": 70874,
"StopPointNumber": 70874,
"StopPointDesignation": null,
"TimeTabledDateTime": "2017-08-24T14:10:31",
"ExpectedDateTime": "2017-08-24T14:11:40",
"DisplayTime": "5 min",
"JourneyNumber": 36,
"Deviations": null
},
{
"GroupOfLine": null,
"TransportMode": "BUS",
"LineNumber": "828",
"Destination": "Östra Skogås",
"JourneyDirection": 1,
"StopAreaName": "Odonbacken",
"StopAreaNumber": 70874,
"StopPointNumber": 70875,
"StopPointDesignation": null,
"TimeTabledDateTime": "2017-08-24T14:19:32",
"ExpectedDateTime": "2017-08-24T14:19:32",
"DisplayTime": "13 min",
"JourneyNumber": 33,
"Deviations": null
},
{
"GroupOfLine": null,
"TransportMode": "BUS",
"LineNumber": "831",
"Destination": "Farsta centrum",
"JourneyDirection": 2,
"StopAreaName": "Odonbacken",
"StopAreaNumber": 70874,
"StopPointNumber": 70874,
"StopPointDesignation": null,
"TimeTabledDateTime": "2017-08-24T14:25:31",
"ExpectedDateTime": "2017-08-24T14:25:31",
"DisplayTime": "14:25",
"JourneyNumber": 40,
"Deviations": null
},
{
"GroupOfLine": null,
"TransportMode": "BUS",
"LineNumber": "831",
"Destination": "Länna industriområde",
"JourneyDirection": 1,
"StopAreaName": "Odonbacken",
"StopAreaNumber": 70874,
"StopPointNumber": 70875,
"StopPointDesignation": null,
"TimeTabledDateTime": "2017-08-24T14:34:32",
"ExpectedDateTime": "2017-08-24T14:34:32",
"DisplayTime": "28 min",
"JourneyNumber": 37,
"Deviations": null
},
{
"GroupOfLine": null,
"TransportMode": "BUS",
"LineNumber": "828",
"Destination": "Farsta centrum",
"JourneyDirection": 2,
"StopAreaName": "Odonbacken",
"StopAreaNumber": 70874,
"StopPointNumber": 70874,
"StopPointDesignation": null,
"TimeTabledDateTime": "2017-08-24T14:40:31",
"ExpectedDateTime": "2017-08-24T14:40:31",
"DisplayTime": "14:40",
"JourneyNumber": 38,
"Deviations": null
},
{
"GroupOfLine": null,
"TransportMode": "BUS",
"LineNumber": "828",
"Destination": "Östra Skogås",
"JourneyDirection": 1,
"StopAreaName": "Odonbacken",
"StopAreaNumber": 70874,
"StopPointNumber": 70875,
"StopPointDesignation": null,
"TimeTabledDateTime": "2017-08-24T14:49:32",
"ExpectedDateTime": "2017-08-24T14:49:32",
"DisplayTime": "14:49",
"JourneyNumber": 35,
"Deviations": null
}
],
"Trains": [],
"Trams": [],
"Ships": [],
"StopPointDeviations": []
}
} %}
{{sl.StatusCode}}
I can extract any value from the object.
There is no problem accessing the sensor attributes.
I have a feeling that the issue is caused by this code in the REST sensor
self.data = response.text
It appears that state data is being stored as text, rather than a json object.
Is there any way of parsing JSON that is stored in an entities state field?