DIY Number Plate Recognition System with Home Assistant


Today I’m going to show you a DIY number plate recognition system created thanks to platerecognizer.com a website that allows us to send an image to process number plates, home assistant which is my smart home automation platform of choice and an IP camera from Reolink (which they kindly provided)

 

 

Follow the steps in the video for step by step guide, here you can find the code used in that video:

Links

My Free home assistant course

HASS-plate-recognizer

Plate Recognizer Regions

Reolink Camera Used

Code

secrets.yaml

#secret.yaml
plate_recognizer_token: XXXXXX #replace token
number_plate: AB11ZZZ #replace number plate

configuration.yaml

image_processing:
  - platform: platerecognizer
    api_token: !secret plate_recognizer_token
    regions:
      - gb #replace with your region
    watched_plates:
      - !secret number_plate
    save_file_folder: /config/www/plate_recognizer #replace with your location if you have a different one
    save_timestamped_file: true
    always_save_latest_file: true
    source:
      - entity_id: camera.parking_bay #replace entity id

parking bay sensors

#you can change names, just remember to then change them in the automation files.
#Replace AB11ZZZ with your number plate 
sensor:
  - platform: template
    sensors:
      is_nissan_number_plate_recognised_bay:
        friendly_name: "Nissan leaf number plate detected in the parking bay"
        value_template: "{{ state_attr('image_processing.platerecognizer_parking_bay', 'watched_plates').AB11ZZZ }}"
      plate_recognizer_api_call_remaining:
        friendly_name: "Plate Recognizer API calls remaining"
        value_template: "{{ state_attr('image_processing.platerecognizer_parking_bay', 'statistics').calls_remaining }}"

automation.yaml

- alias: Parking bay motion
  trigger:
    - platform: state
      entity_id: binary_sensor.parking_bay_motion
      from: "off"
      to: "on"
  #This is option as it specific to me only
  condition:
    condition: state
    entity_id: climate.nest
    attribute: hvac_action
    state: "off"
  action:
    - service: image_processing.scan
      target:
        entity_id: image_processing.platerecognizer_parking_bay #replace with your image_processing entity id
  mode: single
#if you have used the same name in the blog or video you should be ok apart from the notify part!
- alias: Car Deteced in bay
  trigger:
    - platform: state
      entity_id: sensor.plate_recognizer_api_call_remaining
  action:
    - alias: "My car and guests"
      choose:
        # My car has been detected, and it wasn't already in the bay!
        - conditions:
            - condition: state
              entity_id: sensor.is_nissan_number_plate_recognised_bay
              state: "True"
            # Car wasn't already in the parking bay
            - condition: template
              value_template: "{{ not (is_state('input_select.nissan_leaf','Parking Bay')) }}"
          sequence:
            - service: notify.mobile_app_giordano_s_iphone_12 #replace with your phone
              data:
                message: "The car has been parked outside"
            # Car flagged as in the parking bay
            - service: input_select.select_option
              target:
                entity_id: input_select.nissan_leaf
              data:
                option: Parking Bay
        - conditions:
            - condition: state
              entity_id: sensor.is_nissan_number_plate_recognised_bay
              state: "False"
            # Car wasn't already in the parking bay, this is for false positives
            - condition: template
              value_template: "{{ not (is_state('input_select.nissan_leaf','Parking Bay')) }}"
            # need to add confidence level
          sequence:
            - service: notify.mobile_app_giordano_s_iphone_12 #replace with your phone
              data:
                message: "Someone has parked their car in the parking bay"
      default:
        - service: notify.mobile_app_giordano_s_iphone_12 #replace with your phone
          data:
            message: "There is motion in the parking bay"
  condition:
    condition: numeric_state
    entity_id: image_processing.platerecognizer_parking_bay
    above: 0
- alias: API Limit reached for Licence Plate
  trigger:
    - platform: numeric_state
      entity_id: sensor.plate_recognizer_api_call_remaining
      below: 1
  action:
    - service: notify.mobile_app_giordano_s_iphone_12 #replace with you mobile phone
      data:
        message: "Number Plate Licence API has been Reached"

 

 

Gio

Gio loves rabbits, smart home tech, WWII, travelling to Thailand & my favourite pizza is margherita with parma ham!

Recent Posts