blakeblackshear / frigate-hass-integration

Frigate integration for Home Assistant
MIT License
736 stars 113 forks source link

Should automatically remove entities/devices that are no longer live #157

Closed Coolie1101 closed 2 years ago

Coolie1101 commented 3 years ago

Version of the custom_component

v2.1.0

Configuration


mqtt:
  host: 192.168.200.211
  port: 1883
  topic_prefix: frigate
  client_id: frigate
  user: hassos
  password: password
  stats_interval: 30

cameras:
  frontdoor:
    ffmpeg:
      hwaccel_args:
        - -c:v
        - h264_v4l2m2m
      inputs:
        - path: rtsp://admin:password@192.168.200.69:554/streaming/channels/102
          roles:
            - detect
        - path: rtsp://admin:password@192.168.200.69:554/streaming/channels/101
          roles:
            - record
            - rtmp
    detect:
      width: 384
      height: 512
      fps: 5
      max_disappeared: 25
    record:
      enabled: true
      events:
        retain:
          default: 30
          objects:
            person: 60
    objects:
      track:
        - person
        - cat
        - dog
        - bird
        - car
        - backpack
        - handbag
        - suitcase
        - bicycle
    motion:
      mask:
        - 384,298,0,305,0,44,384,40
        - 0,437,77,383,57,278,0,299
        - 66,372,126,373,120,301,54,295
        - 228,388,194,385,197,283,230,284
    best_image_timeout: 30
    zones:
      FrontDoor:
        coordinates: 223,302,49,292,0,311,0,512,225,512
      Steps:
        coordinates: 229,374,329,365,314,312,226,322
      Porch:
        coordinates: 213,512,384,512,384,342,340,362,222,382
    rtmp:
      enabled: true
    snapshots:
      enabled: true
      timestamp: true
      bounding_box: true
      crop: False
      retain:
        default: 30
        objects:
          person: 45
birdseye:
  width: 1536
  height: 2048
  quality: 1
  mode: continuous
detectors:
  cpu1:
    type: cpu
  cpu2:
    type: cpu

Describe the bug

I have duplicated sensors for each specified object, eg:- "sensor.frontdoor_person" and "sensor.frontdoor_person_2"

image

Debug log


2021-10-13 22:29:53 DEBUG (MainThread) [custom_components.frigate] Finished fetching frigate data in 0.028 seconds (success: True)
2021-10-13 22:29:58 DEBUG (MainThread) [custom_components.frigate] Finished fetching frigate data in 0.031 seconds (success: True)
2021-10-13 22:30:03 DEBUG (MainThread) [custom_components.frigate] Finished fetching frigate data in 0.038 seconds (success: True)
dermotduffy commented 3 years ago

I'm guessing this could be because you have a camera name 'frontdoor' and a zone called 'FrontDoor'. One sensor is referring to objects for the camera, the other is referring to objects for the zone. Try renaming one of them.

Coolie1101 commented 3 years ago

camera name 'frontdoor' and a zone called 'FrontDoor'

Indeed I do, had no idea sensors were created for the camera itself, thanks.

Coolie1101 commented 3 years ago

Hey @dermotduffy, any idea how to remove/delete old zones?

image

dermotduffy commented 3 years ago

Review my comments on this issue which give a number of options: https://github.com/blakeblackshear/frigate-hass-integration/issues/140

Coolie1101 commented 3 years ago

Already deleted the entities, but the zones still show up under devices.

dermotduffy commented 3 years ago

Devices with no entities are (IIRC) automatically garbage collected after some time. If you don't want to wait you could manually remove them from .storage/core.device_registry after you take a backup.

Coolie1101 commented 3 years ago

I went with the latter, works so far.

Just out of curiosity, how long does it normally take to be automatically removed?, FYI, been like that since the first day I installed a few weeks ago, and was testing out different options to get an understanding of how things work.

dermotduffy commented 3 years ago

Apologies, not sure. In reality, the real issue is with this integration. It should automatically remove cameras/zone that are associated with the integration but no longer 'live' -- that's just not implemented yet.

dermotduffy commented 3 years ago

... so lets keep this bug to reflect that feature gap.

Coolie1101 commented 3 years ago

No worries, thanks for your help.

Coolie1101 commented 2 years ago

Amazing, would this also take care of the existing unused entities after updating?

dermotduffy commented 2 years ago

@Coolie1101 only unused entities that are associated with a Frigate device. Frigate devices were introduced from v1.1.0 onwards (~July). Crufty entities created prior to that would not be cleaned by this functionality.

Coolie1101 commented 2 years ago

So orpaned entities from within the past couple days would get purged after the new release?

I'm only asking because I disabled (removed from config) a couple zones which still show up as unavailable.

dermotduffy commented 2 years ago

That's a good test. Yes, as long as were running with an integration >= v1.1.0 when you first added those zones, then the next release should clean that up for you without you needing to do anything.

Coolie1101 commented 2 years ago

Awesome, definitely newer than v1.1.0, as I only started using Frigate a couple weeks ago.

Also the link to the doc link in the integration links "https://github.com/blakeblackshear/frigate" as appose to "https://github.com/blakeblackshear/frigate-hass-integration"

Coolie1101 commented 2 years ago

then the next release should clean that up for you without you needing to do anything.

I mite be wrong, but this doesn't seem to be the case, I am now on version 2.2.2/0.11.0-cbf26e0 and still have duplicated entities.

image

image