jakowenko / double-take

Unified UI and API for processing and training images for facial recognition.
https://hub.docker.com/r/jakowenko/double-take
MIT License
1.21k stars 96 forks source link

[FEAT] Retrieve image without using the API #231

Open totalitarian opened 2 years ago

totalitarian commented 2 years ago

Hi,

I'm trying to send images to my mobile using the automation mentioned here

https://github.com/jakowenko/double-take#home-assistant

While this works locally, I have to open up port 3000 on my router to make it work remotely.

I'd like to not have to punch another hole in my router if possible. Is there anyway to access this file another way? Maybe by copying it into the www folder somehow?

LordNex commented 2 years ago

I believe if your running DT inside Home assistant that you can use it's default port of 8123. Which you probably have open anyway for HA access if you use it.

robchandhok commented 2 years ago

There should be an ingress path, but it appears to me that doubleTake doesn't map something in the config. Something Frigate does correctly, but I can't get it to work with doubleTake.

jakowenko commented 2 years ago

There should be an ingress path, but it appears to me that doubleTake doesn't map something in the config. Something Frigate does correctly, but I can't get it to work with doubleTake.

The addon does support ingress and mine works through the HA port of 8123. If there's something that needs to change can you let me know.

DevTodd commented 2 years ago

Or you can do what I do ... Don't use the API and just use HA to take a snapshot of the camera image when the event is detected, save it locally and push it to mobile.

I'm also pushing to node-red, which runs a script and triggers the google home devices in the house to display the camera feed and I'm announcing it on a thermostat centralized in the house. If I tap on the notification it loads the app for my cameras, but you could load, nest, ring etc. I also changed the icon because I have a million different automations. Modify as needed.

Here's an example:

alias: Gate Person Detection (CATT - MQTT - Frigate - DoubleTake)
description: ""
trigger:
  - platform: state
    entity_id:
      - sensor.double_take_gate_camera
    attribute: id
condition: []
action:
  - service: mqtt.publish
    data:
      topic: node-red/gate-camera-catt
      payload: triggered
      qos: "2"
  - service: notify.alexa_media
    data:
      message: Someone has been detected at the gate!
      target:
        - media_player.ecobee_smart_thermostat_premium
      data:
        type: tts
  - service: camera.snapshot
    data:
      filename: /config/media/object-detection/person-gate.jpg
    target:
      device_id: blahblahblah
  - service: notify.mobile_app_pixel_7_pro
    data:
      data:
        image: /media/local/object-detection/person-gate.jpg
        clickAction: app://com.axis.acs
        notification_icon: mdi:face-recognition
        color: red
      message: >-
        {% if state_attr('sensor.double_take_gate_camera', 'personCount') | int
        == 0 %} 
          Someone was detected at the gate.
        {% else -%}
          {% for name in
            state_attr('sensor.double_take_gate_camera', 'matches')
          -%}
            {% if name.match == true %}{{ name.name | title}}{% if not loop.last %}, {% endif -%}
            {% else %}
              An UNKNOWN face
            {% endif %}
          {%- endfor %} {% if
            state_attr('sensor.double_take_gate_camera', 'personCount') | int > 1 %}were detected at the gate.
            {% else -%}was detected at the gate.
          {% endif %}
        {% endif -%}
      title: Person at Gate
mode: single
robchandhok commented 2 years ago

Thank you @DevTodd . I get your approach, but there are already about 3 copies of the "interesting event" around, so trying not to snapshot another (and possibly miss the interesting part).

@jakowenko Thank you again for DoubleTake! Here are some clarifications:

  1. The syntax in your README for the image path is not easy to understand how to map for ingress. In my case, I had to move the port from 3000 due to a conflict with another add-on. I just could not figure out the syntax for the notification images. Your example shows http://localhost:3000/api/storage/matches/ which I think should just be /api/storage/matches/ or {baseurl}/api/storage/matches/ where {baseurl} is the external base path (for me, my nabu casa blob). Just could not get to work in any permutation if the port wasn't 3000. Don't understand why you don't have double-take anywhere in the URL, for example, the frigate ingress path is of the form {{base_url}}/api/frigate/notifications/{{id}}/{{camera}}/clip.mp4 . So I was expecting something like {{base_url}}/api/double-take/storage/matches Hypothesis: if you allow the configuration to change the port, you have to do something else on the ingress code side, but I have no idea if that's correct. I definitely think an example would be gold. I'm continuing to test.
  2. Before I learned about the "subtags" feature with Frigate (VERY COOL ADDITION!) I was building a parallel notification blueprint for doubletake that handled cool-down, and a bunch of other event processing/state machine stuff (from this lineage. There you have the same issue of wanting to generate an ingress path to the relevant image, so same solution would work for MQTT triggered face recognitions (obvi, I know). While doing that I noticed that every time I restarted home assistant, my MQTT triggers would re-fire....finally figured out that you have the retain flag set on your MQTT. At your preference, I can describe here or open another issue as I think that is an incorrect setting for what you want to do with MQTT.

thank you!