I found a great Idea online to set up number plate recognition in home assistant. I thought I would write it down partially because Australia has number plates starting with a number which caused me issues with a sensor.
First thing first, Most information, including the idea, came from the youtube video found here https://www.youtube.com/watch?v=t-XxCrdj_94, and you can find more great ideas at https://everythingsmarthome.co.uk/
What you will need:
- A free account with https://platerecognizer.com/
- The plate Recognizer add-on found at https://github.com/robmarkcole/HASS-plate-recognizer
- HACS for Home Assistant
Install HASS-plate-recognizer
Open the HACS Store.
- Click on the three dots on the top right
- Click on custom repositories
- Add the custom repository https://github.com/robmarkcole/HASS-plate-recognizer
- Select Integration as the category and click add.
- Open the now-added plugin repository and install
- Once Installed, you will now need to restart Home Assistant for the add-on to activate.
Configuration
I am detecting my wife and my number plate using a Reolink camera. As I do not want to use all my free credit for platerocgnizer.com I have an automation to only activate the camera on motion.
configuration.yaml
#Number Plate Recognition
image_processing:
- platform: platerecognizer
api_token: !secret plate_recognizer_api
regions:
- au-wa #platerecognizer region code
watched_plates:
- 1xxxxx # number Plate
- 1xxxxx #number plate
save_file_folder: /config/www/plates
save_timestamped_file: True
always_save_latest_file: True
mmc: True
source:
- entity_id: camera.garage_sub
sensor.yaml
I put my sensors in a separate yaml file and it is defined in my configurations.yaml file
- platform: template
sensors:
plate_recognizer:
friendly_name: "David's Car 1xxxxx"
value_template: "{{ state_attr('image_processing.platerecognizer_garage_sub', 'watched_plates')['1xxxx'] }}"
unique_id: 'sensor.car_1xxxxxx'
plate_recognizer_3:
friendly_name: "Wife's Car 1xxxxx"
value_template: "{{ state_attr('image_processing.platerecognizer_garage_sub', 'watched_plates')['xxxxx'] }}"
unique_id: 'sensor.car_1xxxx'
You will notice in the git that the value template is different from the watched template. When I was using the number 1 for the license plate, it was not working, and after some research, I had to change the way it was written.
automation config
You will notice I have a delay and run the action again. this is to change the license plate from true to false if it is no longer detected.
alias: "Number plate recognition "
description: ""
trigger:
- platform: state
entity_id:
- binary_sensor.garage_cam_motion
to: "on"
condition: []
action:
- service: image_processing.scan
data: {}
target:
entity_id: image_processing.platerecognizer_garage_sub
- delay:
hours: 0
minutes: 5
seconds: 0
milliseconds: 0
- service: image_processing.scan
data: {}
target:
entity_id: image_processing.platerecognizer_garage_sub
mode: single
Second Automation
Finally, I have a second automation to trigger the garage to open if the number plate is recognised. I have a notification currently enabled for testing.
alias: Vehicle Detected
description: ""
trigger:
- platform: state
entity_id:
- sensor.plate_recognizer_2
from: "False"
to: "True"
condition: []
action:
- type: toggle
device_id: e8f4a030bb004e97b96a1c47cb4a4469
entity_id: switch.garage_control
domain: switch
enabled: true
- service: notify.mobile_app_pixel_7_pro
data:
title: License Plate Detection
message: License Plate Detection
data:
image: /local/plates/platerecognizer_garage_sub_latest.png
attachment:
url: /local/plates/platerecognizer_garage_sub_latest.png
content-type: jpg
hide-thumbnail: false
mode: single
I hope this helps others with their configuration.