Extractin attribute

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

Actually, this has less do with Jinja2 templating and more to do with finding the JSON path to the desired value.

Tip:

  1. Paste the data into the left hand pane of JSONPathFinder.com.

  2. For the purposes of JSONPathFinder, you will need to replace the single quotes with double quotes because that’s proper JSON format.

  3. The right hand pane will now contain your data as a JSON object.

  4. Click on the value you want x40752 and the path to the value will appear at the top of the left hand pane.

  5. 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

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.

Done!

Jeff

1 Like