I’m trying to extract the ‘plate’ attribute from an object.
{{ state_attr('image_processing.plagerecognizer', 'vehicles') }}
Gives me this:
[{'plate': 'x40752', 'confidence': 0.783, 'region_code': 'us-ny', 'vehicle_type': 'Pickup Truck'}]
I want to use the ‘x40752’ value in a notification but I’m stuck… how do I reference that? GOD, I hate templating…
Jeff
123
(Taras)
February 14, 2021, 4:33pm
2
jazzmonger:
I hate templating…
Actually, this has less do with Jinja2 templating and more to do with finding the JSON path to the desired value.
Tip:
Paste the data into the left hand pane of JSONPathFinder.com .
For the purposes of JSONPathFinder, you will need to replace the single quotes with double quotes because that’s proper JSON format.
The right hand pane will now contain your data as a JSON object.
Click on the value you want x40752
and the path to the value will appear at the top of the left hand pane.
The path is x[0].plate
Putting it all together we get:
{{ state_attr('image_processing.plagerecognizer', 'vehicles')[0].plate }}
Paste that into the Template Editor and see if it works.
1 Like
That did it! Now I know how to get there.
Much appreciated,
Jeff
123
(Taras)
February 14, 2021, 10:12pm
4
You’re welcome!
Please consider marking my post (above) with the Solution tag. It will automatically place a check-mark next the topic’s title which signals to other users that this topic has an accepted solution. Effectively, it indicates your question has been answered and helps users find answers to similar questions.