/HASS-Machinebox-Classificationbox

Home-Assistant image classification using Machinebox.io

Primary LanguageJupyter NotebookMIT LicenseMIT

Home-Assistant image classification using Classificationbox. Follow this guide to create a model/models on Classificationbox. This component adds an image_processing entity for each model you have created on Classificationbox, where the state of the entity is the most likely classification of an image using that model. An image_processing.image_classification event is fired when the confidence in classification is above the threshold set by confidence, which defaults to 80%.

Place the custom_components folder in your configuration directory (or add its contents to an existing custom_components folder).

Add to your HA config:

image_processing:
  - platform: classificationbox
    ip_address: localhost
    port: 8080
    username: my_username
    password: my_password
    confidence: 50
    source:
      - entity_id: camera.local_file

Configuration variables:

  • ip_address: the ip of your Tagbox instance
  • port: the port of your Tagbox instance
  • username: (Optional) the username if you are using authentication
  • password: (Optional) the password if you are using authentication
  • confidence (Optional): The minimum of confidence in percent to fire an event. Defaults to 80
  • source: must be a camera.

Automations using events

Events can be used as a trigger for automations, and in the example automation below are used to trigger a notification with the image and the classification:

- action:
  - data_template:
      message: Class {{ trigger.event.data.id }} with probability {{ trigger.event.data.confidence
        }}
      title: New image classified
      data:
        file: ' {{states.camera.local_file.attributes.file_path}} '
    service: notify.pushbullet
  alias: Send classification
  condition: []
  id: '1120092824611'
  trigger:
  - event_data:
      id: birds
    event_type: image_processing.image_classification
    platform: event

Classificationbox

Get/update Classificationbox from Dockerhub by running:

sudo docker pull machinebox/classificationbox

Run the container with:

MB_KEY="INSERT-YOUR-KEY-HERE"
sudo docker run -p 8080:8080 -e "MB_KEY=$MB_KEY" machinebox/classificationbox

To run with authentication:

sudo docker run -e "MB_BASICAUTH_USER=my_username" -e "MB_BASICAUTH_PASS=my_password" -p 8080:8080 -e "MB_KEY=$MB_KEY" machinebox/classificationbox

Limiting computation

Image-classifier components process the image from a camera at a fixed period given by the scan_interval. This leads to excessive computation if the image on the camera hasn't changed (for example if you are using a local file camera to display an image captured by a motion triggered system and this doesn't change often). The default scan_interval is 10 seconds. You can override this by adding to your config scan_interval: 10000 (setting the interval to 10,000 seconds), and then call the scan service when you actually want to process a camera image. So in my setup, I use an automation to call scan when a new motion triggered image has been saved and displayed on my local file camera.

Local file camera

Note that for development I am using a file camera.

camera:
  - platform: local_file
    file_path: /images/bird.jpg