frigate-hass-integration: Frigate reports incorrect occupancy in Home Assistant after restart

Version of the custom_component

5.1.0

Configuration

garage_camera:
    ffmpeg:
      inputs:
        - path: rtsp://127.0.0.1:8554/garage_camera
          input_args: preset-rtsp-restream
          roles:
            - record
        - path: rtsp://127.0.0.1:8554/garage_camera_sub
          input_args: preset-rtsp-restream
          roles:
            - detect
            - audio
      output_args:
        record: preset-record-generic-audio-aac
    live:
      stream_name: garage_camera_sub
    detect:
      width: 896
      height: 512
      fps: 10
    motion:
      mask:
        - 680,0,680,35,192,35,192,0
    zones:
      garage_zone:
        coordinates: 0,512,896,512,896,0,369,0,379,103,85,279
        filters:
          car:
            min_score: 0.7
            min_area: 50000
      driveway_zone:
        coordinates: 362,104,363,0,236,0,22,88,71,273
    record:
      enabled: True
      retain:
        days: 7
        mode: all 
      events:
        retain:
          default: 30
          mode: all
    snapshots:
      enabled: True
      retain:
        default: 14
    audio:
      enabled:
        true
      listen:
        - engine_starting
        - bark
        - speech
    birdseye:
      order: 4
    ui:
      order: 4
    objects:
      track:
        - person
        - dog
        - car
      filters:
        person:
          min_score: 0.8
        dog:
          min_score: 0.75
        car:
          min_score: 0.76

Describe the bug

The Frigate add on is not reporting the correct occupancy state after Home Assistant is restarted while an object is being tracked. For example, if Frigate is detecting a car in my garage, and then I restart Home Assistant, the occupancy sensor will become clear even though Frigate is still actively detecting the car in the garage. Here’s a video showing the situation.

I think this is related to this issue: https://github.com/blakeblackshear/frigate-hass-integration/issues/376

Debug log

N/A

About this issue

Most upvoted comments

Not sure if I can add this onto here or if I should open my own ticket but ever since 0.14 HA is falsely detecting occupancy in one of my zones while frigate does not have any events at the time stamps.

Only at night it seems. We have our front doorbell camera set to go through our do not disturb if someone is at our front door…so 3+ false positives from HA with no video clips or recorded events is odd.

I reviewed the footage at the timestamps in frigate. Looks like most of the timestamps was a car driving by on the road(it has been raining here so had some weird reflections. What I find odd is frigate did not even see this as a motion or detection event so I am not sure why HA thought is was worthy of an alert.

Change the status messages to be retained in MQTT, this will allow Home Assistant to pick up the correct state even if it misses the initial message, it could just re-check MQTT occasionally.

I don’t think this makes sense because while they can be retained, they are still not necessarily correct if it is Frigate that changed not home assistant. It is just shifting the problem to a separate scenario.

This will allow the integration to properly mark the entities as unavailable if Frigate crashes without being able to update the frigate/available topic.

Frigate does not update this topic when it stops, that is done by MQTT itself as a LWOT

Have Frigate re-publish all of it’s statuses on startup BEFORE updating the frigate/available topic. This will ensure that the integration has all of the current statuses on startup before it marks the entities as available.

this is already the case except it is not done before /available though I don’t think that is important as /available is not used as the source of truth for all of the sensors availability. This would also not help the issue being discussed here where home assistant is restarted but Frigate is not

Either add an API endpoint to Frigate to request re-publishing all of the current statuses which the integration could then hit occasionally to make sure everything is up-to-date

this already exists in Frigate as part of the recent UI rewrite and is most likely the solution that will be implemented as it will follow what the Frigate webUI already has implemented.

Following because I just realized why my occupancy sensor was wrong so often as every restart of HA from a config change is clearing all of these.

These object occupancy and object count sensors are useful but very unreliable.

@lucasteligioridis I changed the way I restart the add-on since I made that MQTT comment. Here’s my current method. The automation triggers every time that Home Assistant starts. The action is “Home Assistant Supervisor: Restart add-on” with the Frigate add-on selected.

alias: Restart Frigate after Home Assistant starts
description: >-
  Frigate occupancy sensors get messed up whenever Home Assistant is restarted.
  The fix is to restart Frigate.
trigger:
  - platform: homeassistant
    event: start
condition: []
action:
  - metadata: {}
    data:
      addon: ccab4aaf_frigate
    enabled: true
    action: hassio.addon_restart
mode: single

If you do want to use the MQTT method, here’s the action section of the automation.

action:
  - data:
      qos: 0
      retain: false
      topic: frigate/restart
    enabled: false
    action: mqtt.publish