I posted a “template” automation for this in the BlueIris thread recently but I’ve now migrated it to a blueprint so I thought I’d share it here for others
Allows you to confirm the found object in the BI alert data and perform actions when found or ‘semi’ found
BI Alert example:
MQTT Topic: BI/hotspot_info/cam1
Payload: { "alert_db": "&ALERT_DB", "alert_date": "&ALERT_TIME", "json": &JSON, "memo": "&MEMO", "type": "&TYPE" }
# Blueprint metadata
blueprint:
name: BlueIris - AI Alert
description: |
# BlueIris AI alert processing
domain: automation
input:
MQTT_TOPIC_MAIN:
name: (Required) MQTT Main Topic
default: "BI"
selector:
text:
MQTT_TOPIC_SUB:
name: (Required) MQTT Sub Topic
default: "hotspot_info"
selector:
text:
MQTT_TOPIC_CAMERA:
name: (Required) MQTT Camera Topic
default: "cam1"
selector:
text:
ai_object_to_confirm:
name: (Required) AI Object to confirm
description: The AI object to confirm in the alert e.g. person, car etc
default: "person"
selector:
text:
helper_last_controller_event:
name: (Required) Helper - Last Controller Event
description: Input Text helper used to store the last event fired by the controller.
default: ""
selector:
entity:
domain: input_text
# inputs for custom actions
actions_ai_confirmed_full:
name: (Required) Fully AI Confirmed Actions
description: Actions to run on fully AI confirmed alert.
default: []
selector:
action:
actions_ai_confirmed_semi:
name: (Required) Semi AI Confirmed Actions
description: Actions to run on semi AI confirmed alert.
default: []
selector:
action:
notification_delay:
name: (Optional) Notification Delay
description: Time between notifications firing.
default: 60000
selector:
number:
min: 1000
max: 120000
unit_of_measurement: milliseconds
mode: box
step: 10
toggler_check_1:
name: (Optional) Toggler Check 1
description: Input Boolean to be used to confirm notifications should fire (1)
default: ""
selector:
entity:
domain: input_boolean
integration: input_boolean
toggler_check_2:
name: (Optional) Toggler Check 2
description: Input Boolean to be used to confirm notifications should fire (2)
default: ""
selector:
entity:
domain: input_boolean
integration: input_boolean
# Automation schema
variables:
# convert input tags to variables, to be used in templates
ai_object_to_confirm: !input ai_object_to_confirm
helper_last_controller_event: !input helper_last_controller_event
notification_delay: !input notification_delay
input_toggler_check_1: !input toggler_check_1
input_toggler_check_2: !input toggler_check_2
trigger_variables:
MQTT_TOPIC_MAIN: !input MQTT_TOPIC_MAIN
MQTT_TOPIC_SUB: !input MQTT_TOPIC_SUB
MQTT_TOPIC_CAMERA: !input MQTT_TOPIC_CAMERA
mode: queued
max: 3
trigger:
- platform: mqtt
topic: "{{ MQTT_TOPIC_MAIN ~ '/' ~ MQTT_TOPIC_SUB ~ '/' ~ MQTT_TOPIC_CAMERA }}"
condition: []
action:
- variables:
trigger_delta: '{{ (as_timestamp(now()) - as_timestamp((states(helper_last_controller_event) | from_json).last_triggered if helper_last_controller_event is not none and (states(helper_last_controller_event) | regex_match("^\{(\".*\": \".*\"(, )?)*\}$")) else "1970-01-01 00:00:00")) * 1000 }}'
input_toggler_check: >-
{% set check_1 = ((not (input_toggler_check_1 | length)) or states(input_toggler_check_1) == 'on') %}
{% set check_2 = ((not (input_toggler_check_2 | length)) or states(input_toggler_check_2) == 'on') %}
{{ check_1 and check_2 }}
- choose:
- conditions:
- condition: template
value_template: "{{ trigger_delta | int > notification_delay | int }}"
sequence:
- choose:
- conditions:
- condition: template
value_template: >-
{% set cam_data = 'json' in trigger.payload_json and trigger.payload_json.json %}
{% set ai_data = (cam_data and (cam_data|length)) and cam_data|first %}
{% if ai_data and 'found' in ai_data and 'success' in ai_data.found and ai_data.found.success and 'predictions' in ai_data.found %}
{% if ai_object_to_confirm in (ai_data.found.predictions | map(attribute='label', default="empty") | list) %}
{{ true }}
{% else %}
{{ false }}
{% endif %}
{% else %}
{{ false }}
{% endif %}
sequence:
- choose:
- conditions:
- condition: template
value_template: >-
{{ input_toggler_check }}
sequence:
- choose:
- conditions:
- condition: template
value_template: >-
{% set memo_data = 'memo' in trigger.payload_json and trigger.payload_json.memo %}
{{ true if memo_data and ai_object_to_confirm in memo_data else false }}
sequence: !input actions_ai_confirmed_full
default: !input actions_ai_confirmed_semi
- service: input_text.set_value
data:
entity_id: "{{ helper_last_controller_event }}"
value: >-
{{ {"last_triggered":now() | string} | to_json }}