New image_processing custom component - HASS-Google-Vision

Got it (Google Vision) working. It’s damn fast and recognizes not only people. I got “person”, “shorts”, “pants” for detection. Had to implement it as “image_processing.google_vision_person_<entity_id>” (person as target).

!Note!: Add “version” to custom_components’ manifest.json and enable payment in Google Console, otherwise component won’t work!

I implemented it in a two step recognition. motionEye recognizes movement first and sends a webhook to Home Assistant, that starts Google Vision object detection.

Configuration: Image processing

image_processing:
  - platform: google_vision
    api_key_file: /config/google_vision_api_key.json
	save_file_folder: /config/www/tmp_google_vision
	source:
	  - entity_id: camera.<entity_id>

Automation: Webhook from MotionEye

alias: "MotionEye movement detected"
description: Start image processing if motionEye detects movement
trigger:
  - platform: webhook
    webhook_id: <entity_id>-motion-detected
action:
  - service: image_processing.scan
    data: {}
    target:
      entity_id: image_processing.google_vision_person_<entity_id>
mode: single

Automation: Mobile phone notification

alias: "Mobile phone movement notification"
description: "Notify mobile phone if Google Vision detects an object"
trigger:
  - platform: event
    event_type: image_processing.object_detected
    event_data: {}
condition:
  - condition: template
    value_template: >-
      {{ trigger.event.data.entity_id ==
      'image_processing.google_vision_person_<entity_id>' }}
action:
  - service: notify.mobile_phone
    data:
      title: "Movement detected"
      message: "{{ trigger.event.data.object }} with confidence {{ trigger.event.data.confidence }}"
mode: parallel
1 Like

Thanks for sharing the details of your setup!

Unfortunately after restarting server and Home Assistant I get the following error:

Logger: homeassistant.loader
Source: custom_components/google_vision/image_processing.py:17
Integration: google_vision (documentation)
First occurred: 09:08:53 (9 occurrences)
Last logged: 09:13:46

Unexpected exception importing platform custom_components.google_vision.image_processing
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/loader.py", line 657, in get_platform
    cache[full_name] = self._import_platform(platform_name)
  File "/usr/src/homeassistant/homeassistant/loader.py", line 674, in _import_platform
    return importlib.import_module(f"{self.pkg_path}.{platform_name}")
  File "/usr/local/lib/python3.10/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 883, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/config/custom_components/google_vision/image_processing.py", line 17, in <module>
    import gvision.core as gv
  File "/usr/local/lib/python3.10/site-packages/gvision/core.py", line 6, in <module>
    from google.cloud import vision
  File "/usr/local/lib/python3.10/site-packages/google/cloud/vision.py", line 17, in <module>
    from google.cloud.vision_v1 import ImageAnnotatorClient
  File "/usr/local/lib/python3.10/site-packages/google/cloud/vision_v1/__init__.py", line 25, in <module>
    from google.cloud.vision_v1.gapic import image_annotator_client as iac
  File "/usr/local/lib/python3.10/site-packages/google/cloud/vision_v1/gapic/image_annotator_client.py", line 41, in <module>
    _GAPIC_LIBRARY_VERSION = pkg_resources.get_distribution("google-cloud-vision").version
  File "/usr/local/lib/python3.10/site-packages/pkg_resources/__init__.py", line 478, in get_distribution
    dist = get_provider(dist)
  File "/usr/local/lib/python3.10/site-packages/pkg_resources/__init__.py", line 354, in get_provider
    return working_set.find(moduleOrReq) or require(str(moduleOrReq))[0]
  File "/usr/local/lib/python3.10/site-packages/pkg_resources/__init__.py", line 909, in require
    needed = self.resolve(parse_requirements(requirements))
  File "/usr/local/lib/python3.10/site-packages/pkg_resources/__init__.py", line 800, in resolve
    raise VersionConflict(dist, req).with_context(dependent_req)
pkg_resources.ContextualVersionConflict: (google-api-core 2.8.2 (/usr/local/lib/python3.10/site-packages), Requirement.parse('google-api-core[grpc]<2.0.0dev,>=1.14.0'), {'google-cloud-vision'})

Would be nice to solve this, because the component is the best I tried with no false alarms.

looks like the dependency https://github.com/robmarkcole/simple-google-vision did not install, possibly due to conflicts due to https://github.com/robmarkcole/simple-google-vision/blob/d035b94a1aa69eec668cbefc04b4a2dce05ac05b/requirements.txt

I disabled component with commenting out, restart, enable component fixes issue. Strange…

1 Like

I am updating the dependencies anyway