How to trigger an automation based on a license plate

I followed this tutorial to get license plate recognition in HA. It worked great, I got it to read my plate. But how can I trigger an automation based on the plate reading? for example, if HA sees the license plate “ABC 123” send me a notification.

1 Like

Consider using a State Trigger configured to monitor changes to the last_detection attribute.

  trigger:
    - platform: state
      entity_id: image_processing.plate_recognizer_garage_nw
      attribute: last_detection
1 Like

How would I specify to only run the automation when it sees a specific license plate? It seems the automation you posted would trigger when it sees any license plate.

Add a Template Condition to inspect the vehicles attribute.

Alternately, use a Template Trigger to monitor the vehicles attribute.

In both cases, the challenge will be to devise a template that understands how to handle the value of vehicles. It’s a list, where each item represents a detected vehicle, and the list can be empty.

This should do the trick:

{{ state_attr('image_processing.plate_recognizer_garage_nw', 'vehicles')
| selectattr('plate', 'eq', 'gqx564') | list | count > 0 }}

If it finds at least one list item whose plate value is gqx564 then the count is greater than zero and the template will report true (otherwise false). This is well-suited for a Template Condition.

1 Like

You can still use the “to:” option when checking an attribute trigger.

from the docs:

For example, this trigger only fires when the boiler has been heating for 10 minutes:

automation:
  trigger:
    - platform: state
      entity_id: climate.living_room
      attribute: hvac_action
      to: "heating"
      for: "00:10:00"
1 Like

I agree you can but I don’t know of a way to make it work for this application.

When populated, the vehicles attribute contains a list. Each item in the list is a dictionary. The desired dictionary key is plate. As far as I know, that’s a data structure beyond the abilities of the to option.

Ah, got it. I missed the structure of the attributes.

Too bad the “to:” option doesn’t support templates.

Thanks for the help! I made an automation using this template. I try it out tomorrow.

It looks like you are using the platerecognizer custom component, if you are, you can add watched plates to your config and have separate Boolean attributes for each plate you specify

1 Like