Files
HomeAssistantVS/session-ai-camera-optimizations.md

9.2 KiB

AI Camera Motion Automations - Optimization Session

Date: 2026-07-24 (updated) Automations Modified:

  • Motion Backyard - AI Description - Version 2
  • Motion Front Door - AI Description - Version 2
  • Motion Shed - AI Description - Version 2
  • Motion Garage - AI Description - Version 2

Session 1 (Earlier today)

1. Added Snapshot Cleanup (shell_command)

File: configuration.yaml

shell_command:
  cleanup_blink_snapshots: "find /media -name 'blink_*.jpg' -mmin +60 -delete"

2. Removed Duplicate Snapshot

Removed the second camera.snapshot to /config/www/ from all 4 automations.

3. Added Snapshot Cleanup Action

Added shell_command.cleanup_blink_snapshots as first action in each automation.

4. Removed Empty data: {} from Switch Actions

Cleaned up unnecessary empty data: {} blocks.

5. Added 60-Second Cooldown Condition

Added rate-limiting condition using hardcoded entity references:

value_template: "{{ (now() - state_attr('automation.<entity_id>', 'last_triggered')).total_seconds() > 60 }}"

Session 2 (This session)

1. Fixed Spook Warnings - Hardcoded Entity References

File: automations.yaml (all 4 automations)

Before:

value_template: "{{ (now() - state_attr('automation.motion_backyard_ai_description_version_2', 'last_triggered')).total_seconds() > 60 }}"

After:

value_template: "{{ (now() - state_attr(this.entity_id, 'last_triggered')).total_seconds() > 60 }}"

Reason: Spook reported unknown entities because the automation referenced itself by hardcoded entity ID. Using this.entity_id resolves this.


2. Re-added Second Snapshot to /config/www/

File: automations.yaml (all 4 automations)

Reverted the Session 1 change. Added back the second camera.snapshot to /config/www/ for each automation. This is needed because persistent notifications use /local/ which maps to /config/www/, not /media/.

- action: camera.snapshot
  target:
    entity_id: camera.blink_backyard
  data:
    filename: /media/{{ snapshot_filename }}
- action: camera.snapshot
  target:
    entity_id: camera.blink_backyard
  data:
    filename: /config/www/{{ snapshot_filename }}

3. Updated Shell Command Cleanup

File: configuration.yaml

Before:

cleanup_blink_snapshots: "find /media -name 'blink_*.jpg' -mmin +60 -delete"

After:

cleanup_blink_snapshots: "find /media /config/www -name 'blink_*.jpg' -mmin +60 -delete"

Reason: Now that we save to both /media/ and /config/www/, both directories need cleanup. Requires HA restart to take effect.


4. Created /config/www/ Directory

The directory did not exist, so camera.snapshot to /config/www/ was silently failing.


5. Added Images Back to Persistent Notifications

File: automations.yaml (Front Door, Shed, Garage)

Added ![Snapshot](/local/{{ snapshot_filename }}) to the persistent notification message for all 3 automations. The Backyard automation already had this.


6. Fixed Front Door Persistent Notification

File: automations.yaml

Before: Used broken notify.persistent_notification action (with duplicate data: keys) AND a separate persistent_notification.create without image.

After: Single persistent_notification.create with image in message, matching the working Backyard pattern.


7. Fixed Camera Targets (Critical Bug)

File: automations.yaml

Automation Before (WRONG) After (CORRECT)
Front Door camera.blink_backyard camera.blink_front
Shed camera.blink_backyard camera.blink_backyard_shed
Backyard camera.blink_backyard camera.blink_backyard (correct)
Garage camera.blink_backyard_tree camera.blink_backyard_tree (correct)

Reason: Front Door and Shed were both snapshotting the backyard camera instead of their own cameras.


8. Updated Front Door AI Task Name

Before: Nest Front Camera Analysis After: Blink Front Camera Analysis

Reason: This is a Blink camera, not a Nest camera.


Final State of All 4 Automations

Automation Camera Filename Prefix Snapshot Paths Persistent Notification
Backyard camera.blink_backyard blink_backyard_ /media/ + /config/www/ ![Snapshot] included
Front Door camera.blink_front blink_Front_ /media/ + /config/www/ ![Snapshot] included
Shed camera.blink_backyard_shed blink_shed_ /media/ + /config/www/ ![Snapshot] included
Garage camera.blink_backyard_tree blink_Inshed_ /media/ + /config/www/ ![Snapshot] included

Critical Context: Blink cameras are exposed to Home Assistant via Homebridge, NOT the native Blink integration.

Why: The built-in Blink integration stopped working. The user reverted to Homebridge which exposes the cameras again. However, there are 2 Homebridge plugins - one does NOT have the "force snapshot" capability.

Homebridge Plugin: Homebridge Blink Cameras New API F12C (confirmed via entity button.homebridge_blink_cameras_new_api_f12c_identify)

Camera Entities (all via Homebridge):

  • camera.blink_backyard - Backyard
  • camera.blink_front - Front
  • camera.blink_backyard_shed - Shed
  • camera.blink_backyard_tree - Garage (mislabeled - physically monitors garage area)
  • camera.blink_garage_side - Garage Side
  • camera.blink_thermopump - Thermopump

Refresh Snapshot Switches:

  • switch.backyard_refresh_snapshot
  • switch.front_refresh_snapshot
  • switch.backyard_shed_refresh_snapshot
  • switch.backyard_tree_refresh_snapshot
  • switch.garage_side_refresh_snapshot
  • switch.thermopump_refresh_snapshot

Known Limitations

Homebridge Integration Limitations (CRITICAL)

  1. No Force Refresh Capability - The Homebridge Blink integration exposes cameras as basic entities with supported_features: 0. This means:

    • No blink.trigger_camera service (old Blink integration feature - DISABLED in automations)
    • No way to force the camera to take a fresh snapshot on demand
    • camera.snapshot action simply saves whatever image is currently cached by the integration
  2. Stale Image Problem - When automation triggers:

    • switch.*_refresh_snapshot is turned on (purpose unclear - may not actually work)
    • Delays (30s + 5s) are used to give Blink time to update
    • homeassistant.update_entity is called to poll
    • camera.snapshot saves the current cached image (which may be OLD)
  3. Image Cache Timing - Blink cameras cache images and update them periodically. There's no guaranteed way to force a fresh capture through Homebridge.

Other Limitations

  • Blink API throttling may cause stale snapshots when multiple automations run in quick succession
  • camera.snapshot returns success but may not write file if Blink hasn't refreshed its image cache
  • shell_command cleanup update requires HA restart to take effect
  • The switch.*_refresh_snapshot switches may be non-functional remnants from the old Blink integration

Testing Results (2026-07-24)

  • Front Door: GOLD STANDARD - Most reliable automation. Gets the latest image almost every time. Image processing via Ollama works correctly. This is the reference implementation the others should match.
  • Backyard: Working correctly - correct image, Ollama processing successful
  • Shed: Working correctly - correct image, Ollama processing successful
  • Garage: ISSUE - Sometimes uses stale/old image. The Homebridge integration may not have refreshed the camera's cached image before snapshot is taken.

Note: All 4 automations ran and captured the correct camera images. However, the Garage automation has been observed using old/stale images. This is a known limitation of the Homebridge integration - there's no guaranteed way to force a fresh snapshot. Long-term observation needed to determine if this is a timing issue or a hard limitation.


Session 3 (Current - 2026-07-24)

Issue Reported: Garage Automation Using Stale Image

Problem: User ran the garage automation and it used an old/cached image from the Blink camera instead of a fresh snapshot.

Investigation Findings:

  1. The blink.trigger_camera action in the automation is DISABLED (line 2880-2884) - this is old code from when the built-in Blink integration was working
  2. The built-in Blink integration stopped working, so the user reverted to Homebridge to expose cameras
  3. The Homebridge Blink integration (Homebridge Blink Cameras New API F12C) does NOT provide a "force snapshot" capability
  4. Camera entities have supported_features: 0 - no special capabilities exposed
  5. The switch.*_refresh_snapshot switches may not actually trigger a fresh capture

Root Cause: This is a hard limitation of the Homebridge integration. The camera.snapshot action saves whatever image is currently cached by the integration. There's no way to force the camera to take a new photo on demand.

Resolution: User will monitor for a few days to see if the issue persists. The 30s + 5s delays in the automation are intended to give Blink time to update its cache, but this is not guaranteed to work.