Skip to content

Commit

Permalink
Merge pull request #78 from valentinfrlch/semantic-index
Browse files Browse the repository at this point in the history
PR for v1.3
  • Loading branch information
valentinfrlch authored Nov 2, 2024
2 parents ec7900d + c304a9a commit 4addebb
Show file tree
Hide file tree
Showing 13 changed files with 549 additions and 131 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
</p>
<p align=center>
<img src=https://img.shields.io/badge/HACS-Custom-orange.svg?style=for-the-badg>
<img src=https://img.shields.io/badge/version-1.2.1-blue>
<img src=https://img.shields.io/badge/version-1.3.0-blue>
<a href="https://github.com/valentinfrlch/ha-llmvision/issues">
<img src="https://img.shields.io/maintenance/yes/2024.svg">
<img alt="Issues" src="https://img.shields.io/github/issues/valentinfrlch/ha-llmvision?color=0088ff"/>
Expand Down
68 changes: 42 additions & 26 deletions blueprints/event_summary.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
blueprint:
name: AI Event Summary (LLM Vision v1.2.1)
name: AI Event Summary (LLM Vision v1.3)
author: valentinfrlch
description: >
AI-powered security event summaries for frigate or camera entities.
Expand All @@ -16,7 +16,13 @@ blueprint:
- 'Camera'
important:
name: Important
description: "Use AI to notify only on important events. Use with caution: AI can make mistakes."
description: "Use AI to detect important events. Notifications will only be sent when important event is detected. Use with caution: AI can make mistakes."
default: false
selector:
boolean:
remember:
name: Remember
description: Remember this event so you can ask about it later. Event Calendar needs to be configured. If 'important' is set to true, only important events will be remembered.
default: false
selector:
boolean:
Expand All @@ -26,25 +32,27 @@ blueprint:
selector:
device:
integration: mobile_app
frigate_url:
name: Frigate URL
description: (Frigate) Frigate's base url to fetch preview
default: "http://localhost:5000"
selector:
text:
multiline: false
camera_entities:
name: Camera Entities
description: (Camera) List of camera entities to monitor
description: (Camera and Frigate mode) List of camera entities to monitor
default: []
selector:
entity:
multiple: true
filter:
domain: camera
preview_mode:
name: Preview Mode
description: (Camera mode only) Choose between a live preview or a snapshot of the event
default: 'Live Preview'
selector:
select:
options:
- 'Live Preview'
- 'Snapshot'
motion_sensors:
name: Motion Sensor
description: (Camera) Set if your cameras don't change state. Use the same order used for camera entities.
description: (Camera mode only) Set if your cameras don't change state. Use the same order used for camera entities.
default: []
selector:
entity:
Expand All @@ -53,43 +61,43 @@ blueprint:
domain: binary_sensor
trigger_state:
name: Trigger State
description: (Camera) Trigger the automation when your cameras change to this state.
description: (Camera mode only) Trigger the automation when your cameras change to this state.
default: 'recording'
selector:
text:
multiline: false
tap_navigate:
name: Tap Navigate
description: Path to navigate to when tapping notification (e.g. /lovelace/cameras)
description: Path to navigate to when notification is opened (e.g. /lovelace/cameras)
default: "/lovelace/0"
selector:
text:
multiline: false
cooldown:
name: Cooldown
description: Time in minutes to wait before running again.
description: Time in minutes to wait before running again. Recommended for busy areas.
default: 10
selector:
number:
min: 0
max: 60
provider:
name: Provider
description: Configuration to use for the video_analyzer service. See docs for additional information.
description: Provider to use for analysis. See docs for additional information.
selector:
config_entry:
integration: llmvision
max_frames:
name: Max Frames
description: How many frames to analyze. Picks frames with the most movement.
description: (Camera and Frigate mode) How many frames to analyze. Picks frames with the most movement.
default: 3
selector:
number:
min: 1
max: 60
duration:
name: Duration
description: (Camera) How long to record for (in seconds)
description: (Camera mode only) How long to record before analyzing (in seconds)
default: 5
selector:
number:
Expand All @@ -105,13 +113,13 @@ blueprint:
message:
name: Prompt
description: Model prompt for the video_analyzer service
default: "Summarize briefly what's happening in the camera feed (one sentence max). Don't describe the scene! If there is a person, describe what they're doing. If nothing is happening, say so."
default: "Summarize what's happening in the camera feed (one sentence max). Don't describe the scene! If there is a person, describe what they're doing and what they look like. If they look like a courier mention that! If nothing is happening, say so."
selector:
text:
multiline: true
target_width:
name: Target Width
description: Width in pixels to downscale (uses less tokens)
description: Downscale images (uses less tokens and speeds up processing)
default: 1280
selector:
number:
Expand All @@ -136,7 +144,7 @@ blueprint:
max: 100
temperature:
name: Temperature
description: Randomness. Lower is more accurate, higher is more creative
description: Randomness. Lower is more accurate, higher is more creative.
default: 0.1
selector:
number:
Expand All @@ -146,9 +154,9 @@ blueprint:

variables:
important: !input important
base_url: !input frigate_url
cooldown: !input cooldown
mode: !input mode
preview_mode: !input preview_mode
camera_entities_list: !input camera_entities
motion_sensors_list: !input motion_sensors
camera_entity: >
Expand Down Expand Up @@ -188,15 +196,19 @@ variables:
{% endif %}
video: >
{% if mode == 'Frigate' %}
{{ base_url }}/api/events/{{ trigger.payload_json['after']['id'] }}/clip.mp4
/api/frigate/notifications/{{ trigger.payload_json['after']['id'] }}/clip.mp4
{% else %}
''
{% endif %}
image: >
{% if mode == 'Frigate' %}
''
{% else %}
{{ '/api/camera_proxy/' + camera_entity }}
{% if preview_mode == 'Live Preview' %}
{{ '/api/camera_proxy/' + camera_entity }}
{% else %}
/www/llmvision/{{camera_entity}}_0.jpg
{% endif %}
{% endif %}
importance_prompt: >
Your job is to decide whether a camera recording is important (so the user gets a notification) or not.
Expand All @@ -220,11 +232,12 @@ condition:
- condition: template
value_template: >
{% if mode == 'Frigate' %}
{{ trigger.payload_json["type"] == "end" and (state_attr(this.entity_id, 'last_triggered') is none or (now() - state_attr(this.entity_id, 'last_triggered')).total_seconds() / 60 > cooldown) }}
{{ trigger.payload_json["type"] == "end" and (state_attr(this.entity_id, 'last_triggered') is none or (now() - state_attr(this.entity_id, 'last_triggered')).total_seconds() / 60 > cooldown) and ('camera.' + trigger.payload_json['after']['camera']|lower) in camera_entities_list }}
{% else %}
{{ state_attr(this.entity_id, 'last_triggered') is none or (now() - state_attr(this.entity_id, 'last_triggered')).total_seconds() / 60 > cooldown }}
{% endif %}
action:
- choose:
- conditions:
Expand Down Expand Up @@ -270,14 +283,14 @@ action:
- choose:
- conditions:
- condition: template
value_template: "{{ importance is defined and importance.response_text == 'no' }}"
value_template: "{{ importance is defined and importance.response_text|lower == 'no' }}"
sequence:
- stop: "Event is not important"

- choose:
- conditions:
- condition: template
value_template: "{{ base_url is not none and base_url != '' }}"
value_template: "{{ image != '' or video != '' }}"
sequence:
- alias: "Send instant notification without summary"
domain: mobile_app
Expand Down Expand Up @@ -306,6 +319,7 @@ action:
provider: !input provider
model: !input model
message: !input message
remember: !input remember
include_filename: true
max_frames: !input max_frames
target_width: !input target_width
Expand All @@ -324,12 +338,14 @@ action:
provider: !input provider
model: !input model
message: !input message
remember: !input remember
include_filename: true
max_frames: !input max_frames
target_width: !input target_width
detail: !input detail
max_tokens: !input max_tokens
temperature: !input temperature
expose_images: "{{true if preview_mode == 'Snapshot'}}"
response_variable: response

- alias: "Send notification with summary"
Expand Down
Loading

0 comments on commit 4addebb

Please sign in to comment.