REST Sensor JSON parsing help


I have been struggling for a few hours now and can’t seem to get my REST Sensor JSON parsing to work could someone please help?

this is my JSON response

      "name":"Test API",

I would just like to get the following out of it.

id :
name :
macaddress :
inuse :

I think the cause of my problem is the square bracket “[” but I’m not sure.

I have tried the following with no success

value_template: ‘{{ }}’

this results in a blank sensor

here is the error in the log

Error parsing value: ‘list object’ has no attribute ‘state’ (value: [{“id”:4442,“name”:“Test API”,“macaddress”:“f8:f0:05:e5:1b:1a”,“xpercent”:56.432434,“ypercent”:96.63537,“inuse”:false,“standby”:false,“faulty”:false,“registered”:true,“lastocc”:1527105145,“lastonl”:1527362645,“hidden”:false}], template: ‘{{ }}’)

any ideas?

thank you

It’s the first list element aka 0.

so with the information on templating, I came up with this.

value_template: ‘{{ value_json[“”][“id”] }}’

which now gives me unknown as the sensor result and the same error in the log

Error parsing value: ‘list object’ has no attribute ‘’ (value: [{“id”:4442,“name”:“Test API”,“macaddress”:“f8:f0:05:e5:1b:1a”,“xpercent”:56.432434,“ypercent”:96.63537,“inuse”:false,“standby”:false,“faulty”:false,“registered”:true,“lastocc”:1527105145,“lastonl”:1527364172,“hidden”:false}], template: {{ value_json[“”][“id”] }})

I just need some help to get going in the right direction as the templating examples all start with curly brackets not square, I’m not even sure if that’s a problem?

You are getting a list back and you need the first element.


1 Like

Thank you this has helped me sort it out.