Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- alias: Package Detection - Front Door AI delivery person
- description: Uses Gemini AI to detect packages at front door
- triggers:
- - entity_id: binary_sensor.g6_entry_person_detected
- to: "on"
- id: person_detected
- trigger: state
- - hours: /2
- id: timed_check
- trigger: time_pattern
- enabled: false
- conditions:
- - condition: time
- after: "04:00:00"
- before: "00:00:00"
- enabled: false
- actions:
- - choose:
- - conditions:
- - condition: trigger
- id: person_detected
- sequence:
- - delay:
- seconds: 2
- - variables:
- light_was_off: |
- {{ states('light.porch_light_2_2') == 'off'
- and states('binary_sensor.g6_entry_is_dark') == 'on' }}
- - if:
- - condition: template
- value_template: "{{ light_was_off }}"
- then:
- - action: light.turn_on
- target:
- entity_id: light.porch_light_2_2
- - delay: "00:00:05"
- - action: camera.snapshot
- data:
- filename: /config/www/unifi_protect/frontdoor_snapshot.jpg
- target:
- entity_id: camera.g6_entry_high_resolution_channel
- - delay:
- seconds: 2
- - action: llmvision.image_analyzer
- data:
- provider: xxxxxxxxxxxxxxxxxxxxxxxxxxx
- model: gemini-2.5-flash
- message: >-
- You are a package detection sensor. Look at the entire porch area
- including brick pavers, walkway, and welcome mat. Is there a package
- present OR is a person placing or delivering a package? Reply with true
- X or false 0 only where X is the count. Do not add any extra text.
- image_file: /config/www/unifi_protect/frontdoor_snapshot.jpg
- max_tokens: 100
- temperature: 0
- remember: false
- response_variable: gemini_result
- - action: system_log.write
- data:
- message: >-
- Package Detection AI response: {{ gemini_result.response_text |
- default('No response') }}
- level: info
- - if:
- - condition: template
- value_template: "{{ light_was_off }}"
- then:
- - delay: "00:00:20"
- - action: light.turn_off
- target:
- entity_id: light.porch_light_2_2
- - variables:
- count1_raw: |
- {{ gemini_result.response_text | default('false 0') | lower }}
- count1: >
- {% set nums =
- {'one':1,'two':2,'three':3,'four':4,'five':5,'six':6,'seven':7,'eight':8,'nine':9,'ten':10}
- %} {% set digits = count1_raw | regex_findall('true\s*(\d+)') |
- map('int') | list %} {% set words = count1_raw |
- regex_findall('true\s*(\w+)') | map('lower') | list %} {% set
- fallback_digits = count1_raw | regex_findall('(\d+)') | map('int') |
- list %} {% set fallback_words = count1_raw.split() | list %} {% if
- digits %}{{ digits[-1] }} {% elif words and nums.get(words[-1], 0) > 0
- %}{{ nums.get(words[-1]) }} {% elif fallback_digits %}{{
- fallback_digits[-1] }} {% else %}{{ fallback_words | map('lower') |
- select('in', nums) | map('extract', nums) | list | sum }}{% endif %}
- has_package: "{{ count1 | int > 0 }}"
- package_count: "{{ count1 | int }}"
- - choose:
- - conditions:
- - condition: template
- value_template: "{{ has_package }}"
- sequence:
- - action: input_boolean.turn_on
- target:
- entity_id: input_boolean.package_detected_front
- - action: input_number.set_value
- target:
- entity_id: input_number.package_count_front
- data:
- value: "{{ package_count if package_count | int > 0 else 1 }}"
- - conditions:
- - condition: template
- value_template: "{{ not has_package }}"
- sequence:
- - action: input_boolean.turn_off
- target:
- entity_id: input_boolean.package_detected_front
- - action: input_number.set_value
- target:
- entity_id: input_number.package_count_front
- data:
- value: 0
- mode: single
- max_exceeded: silent
Advertisement