-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcamera_snapshot_full_llm.yaml
More file actions
169 lines (166 loc) · 6.71 KB
/
Copy pathcamera_snapshot_full_llm.yaml
File metadata and controls
169 lines (166 loc) · 6.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
blueprint:
name: Voice - Capture Camera Snapshot
author: TriTue2011 nguồn luuquangvu
description: >
Công cụ chụp ảnh camera cho Voice Assistant.
Yêu cầu template sensor lưu entity aliases trong configuration.yaml.
Hỗ trợ tìm camera theo friendly name và alias.
Nhớ expose camera và script cho Assist sau khi lưu.
domain: script
homeassistant:
min_version: 2024.10.0
input:
entity_aliases_settings:
name: Settings for Entity Aliases
icon: mdi:format-list-bulleted
description: You can use these settings to configure a template sensor that
stores all information about entity aliases.
input:
entity_aliases:
name: Entity Aliases
selector:
entity:
filter:
- domain:
- sensor
integration: template
multiple: false
reorder: false
snapshot_settings:
name: Settings for Snapshot Output
icon: mdi:folder-image
description: Configure where snapshots should be stored and how filenames are
generated.
collapsed: true
input:
snapshot_directory:
name: Snapshot Directory
description: Absolute path where the snapshot will be stored (default is
`/media`).
selector:
text:
multiple: false
multiline: false
default: /media
snapshot_filename_prefix:
name: Snapshot Filename Prefix
description: Prefix used when generating the snapshot filename.
selector:
text:
multiple: false
multiline: false
default: camera_snapshot_
snapshot_file_extension:
name: Snapshot File Extension
description: File extension to use for the snapshot (for example jpg or
png).
selector:
text:
multiple: false
multiline: false
default: jpg
prompt_settings:
name: Prompt settings for the LLM
icon: mdi:robot
description: You can use these settings to finetune the prompts for your specific
LLM (model). In most cases the defaults should be fine.
collapsed: true
input:
camera_name_prompt:
name: Camera Name Prompt
description: The prompt which will be used for the LLM can provide the camera
name.
selector:
text:
multiline: true
multiple: false
default: 'This argument is mandatory and must always be included.
Specify the camera name to capture the snapshot from.
Use the friendly name that appears in Home Assistant (for example "Front
Door Camera").
The tool will return a local file path to the generated snapshot.'
source_url: https://github.com/TriTue2011/Blueprint/blob/main/camera_snapshot_full_llm.yaml
mode: parallel
max_exceeded: silent
description: Takes a snapshot from a specified camera.
variables:
version: 20251116
fields:
camera_name:
name: Camera Name
description: !input camera_name_prompt
selector:
text:
required: true
sequence:
- variables:
entity_aliases: !input entity_aliases
camera_name: '{{ camera_name | default('''') | trim }}'
snapshot_directory_input: !input snapshot_directory
snapshot_directory: '{{ snapshot_directory_input | default(''/media'', true) |
trim }}'
snapshot_prefix_input: !input snapshot_filename_prefix
snapshot_prefix: '{{ snapshot_prefix_input | default(''camera_snapshot_'', true)
| trim }}'
snapshot_extension_input: !input snapshot_file_extension
snapshot_extension: '{{ snapshot_extension_input | default(''jpg'', true) | trim
| lower }}'
- alias: Validate camera name
if:
- condition: template
value_template: '{% set friendly_match = states.camera | selectattr(''attributes.friendly_name'',
''=='', camera_name) | list %} {% set alias_match = state_attr(entity_aliases,
''entities'') | default([]) | selectattr(''entity_id'', ''match'', ''camera\.'')
| selectattr(''aliases'', ''contains'', camera_name) | list %} {{ not camera_name
or (friendly_match | length == 0 and alias_match | length == 0) }}'
then:
- alias: Set variable for error message
variables:
response:
error: Unable to capture a snapshot because the camera name is invalid.
- alias: Stop the script
stop: Unable to capture a snapshot because the camera name is invalid.
response_variable: response
- alias: Validate snapshot settings
if:
- condition: template
value_template: '{{ not snapshot_directory }}'
then:
- alias: Set variable for error message
variables:
response:
error: Unable to capture a snapshot because the snapshot directory is missing.
- alias: Stop the script
stop: Unable to capture a snapshot because the snapshot directory is missing.
response_variable: response
- variables:
camera_entity_id: "{% set friendly_match = states.camera | selectattr('attributes.friendly_name',
'==', camera_name) | map(attribute='entity_id') | first %} {% if friendly_match
%}\n {{ friendly_match }}\n{% else %}\n {{ state_attr(entity_aliases, 'entities')
| default([]) | selectattr('entity_id', 'match', 'camera\\.') | selectattr('aliases',
'contains', camera_name) | map(attribute='entity_id') | first }}\n{% endif %}"
sanitized_prefix: "{% if snapshot_prefix %}\n {{ snapshot_prefix | regex_replace('[^0-9A-Za-z_-]',
'_') }}\n{% else %}\n camera_snapshot_\n{% endif %}"
sanitized_extension: "{% if snapshot_extension %}\n {% set ext = snapshot_extension
| regex_replace('[^0-9a-z]', '') %}\n {{ '.' ~ (ext if ext else 'jpg') }}\n{%
else %}\n .jpg\n{% endif %}"
snapshot_directory_normalized: "{% if snapshot_directory %}\n {{ snapshot_directory.rstrip('/\\\\')
}}\n{% else %}\n /media\n{% endif %}"
snapshot_random_suffix: '{{ ''%05d'' | format(range(0, 100000) | random) }}'
snapshot_filename: '{{ sanitized_prefix ~ now().strftime(''%Y%m%d%H%M%S%f'') ~
''_'' ~ snapshot_random_suffix ~ sanitized_extension }}'
snapshot_full_path: '{{ snapshot_directory_normalized ~ ''/'' ~ snapshot_filename
}}'
returned_image_path: "{% set prefix = '/media/' %} {% if snapshot_full_path.startswith(prefix)
%}\n {{ 'local/' ~ snapshot_full_path[prefix | length:] }}\n{% else %}\n {{
snapshot_full_path }}\n{% endif %}"
- action: camera.snapshot
target:
entity_id: '{{ camera_entity_id }}'
data:
filename: '{{ snapshot_full_path }}'
- variables:
response:
image_path: '{{ returned_image_path }}'
- stop: ''
response_variable: response