Blue Iris motion alerts to notification with image in Home Assistant

tumblr_8498d03cb8f1a9a769604f42b73bf7ab_1616742c_250

Everyone who is also trying to figure this out… stop here…

No need to decode a Base64 string.

No need to save off an image via screenshot to HA first.

Simple Notificaion with Options!!.

Based on the MQTT message… Send a notification with all the reference URLs back to BI!

Brilliant. This community is awesome.

My full Automation script:

alias: BI MQTT - Any Camera Trigger
description: The Blue Iris Notification Replacement
triggers:
  - trigger: mqtt
    topic: BlueIris/+/alert-image
    variables:
      camera_name: "{{ trigger.topic.split('/')[1] }}"
#This part is optional, but i only wanted alerts when the sun was out. 
conditions:
  - condition: sun
    before: sunset
    after: sunrise
    enabled: false
actions:
  - action: notify.james_devices
    data:
      message: >-
        {{ trigger.payload_json.type }} was detected on the {{
        trigger.payload_json.name }} camera.
      data:
        channel: BlueIris
        ttl: 0
        priority: high
        clickAction: >-
          http://<BI_EXTERNAL_IP>:81/ui3.htm?maximize=1&tab=alerts&cam={{trigger.payload_json.camera}}&rec={{trigger.payload_json.db}}
        image: http://<BI_EXTERNAL_IP>:81/alerts/{{trigger.payload_json.id}}
        actions:
          - action: URI
            title: Live View
            uri: >-
              http://<BI_EXTERNAL_IP>:81/ui3.htm?maximize=1&cam={{trigger.payload_json.camera}}
          - action: URI
            title: View Clip
            uri: >-
              http://<BI_EXTERNAL_IP>:81/ui3.htm?maximize=1&tab=alerts&cam={{trigger.payload_json.camera}}&rec={{trigger.payload_json.id}}
      title: Blue Iris
  - action: notify.des_devices
    data:
      message: >-
        {{ trigger.payload_json.type }} was detected on the {{
        trigger.payload_json.name }} camera.
      data:
        channel: BlueIris
        ttl: 0
        priority: high
        clickAction: >-
          http://<BI_EXTERNAL_IP>:81/ui3.htm?maximize=1&tab=alerts&cam={{trigger.payload_json.camera}}&rec={{trigger.payload_json.db}}
        image: http://cams.1930networks.com:1930/alerts/{{ trigger.payload_json.id }}
        actions:
          - action: URI
            title: Live View
            uri: >-
              http://<BI_EXTERNAL_IP>:81/ui3.htm?maximize=1&cam={{
              trigger.payload_json.camera }}
          - action: URI
            title: View Clip
            uri: >-
              http://<BI_EXTERNAL_IP>:81/ui3.htm?maximize=1&tab=alerts&cam={{
              trigger.payload_json.camera }}&rec={{ trigger.payload_json.id }}
      title: Blue Iris
mode: queued
max: 10

Update: Its also worth noting that each device is limited to 500 pushes a day. So if you’re testing and notifications stop working – check on the companion app how many notificaitons you have left…

Great idea and nice it works but blueiris is not hardened for external access, it’s a security risk exposing your instance to the public, especially over plain http

My pfSense router is Proxying for me. However after finding out about the 500 daily message limitation i decided against this route and just use the Push notifications directly from BI – ive reached back out to Support over at BI to see what the Notification issue status was and reported some new ones of my own.

Hi,

thanks for this automation.

Whats the right MQTT message?

Thanks for your answer.

Regards
Armin

Whats your payload from BI?

You sir are a KING! I was couldn’t get the alert screen shot to display when I read your comment about setting up BI to not require authentication from LAN, and BOOM, problem solved! Thank you!

I know this is for Home Assistant but going to offer this as an alternative as it doesn’t need Home Assistant or MQTT or even an app installed on your phone.

https://www.reddit.com/r/BlueIris/comments/1kf3h1m/guide_ntfy_for_notifications_image_included_in/

I too would like to know what you’re using as your payload. Thank you.

I know this is a bit of thread necromancy, but this seemed like the most appropriate place to ask. I am trying to convert over from NodeRed to just using HA automations since this is the only thing I have NodeRed running for.

Pertinent Info:
Is fully functioning with NodeRed hitting both my phone and my wife’s

Blue Iris:

MQTT Topic: BI/&CAM/attributes
Post/Payload: {"memo": "&MEMO","db":"&ALERT_DB"}

MQTT Topic: BI/&CAM/alert-image-b64
Post/Payload: &ALERT_JPEG

MQTT.yaml

  # Backyard Camera
  - topic: BI/Backyard1/alert-image-b64
    name: Backyard1 Alert
    unique_id: camera.backyard1_alert
    image_encoding: b64

sensor:
  # Driveway Camera Attributes
  - state_topic: BI/Backyard1/attributes
    name: Backyard1 Alert Attributes
    unique_id: sensor.backyard1_alert_attributes
    value_template: '{{value_json.memo}}'
    json_attributes_topic: BI/Backyard1/attributes

HA Automation:

alias: BI MQTT - Any Camera Trigger
description: The Blue Iris Notification Replacement
triggers:
  - trigger: mqtt
    topic: BI/+/alert-image-b64
    variables:
      camera_name: "{{ trigger.topic.split('/')[1] }}"
actions:
  - action: notify.mobile_app_my_phone
    data:
      message: >-
        {{ trigger.payload_json.type }} was detected on the {{
        trigger.payload_json.name }} camera.
      data:
        channel: BI
        ttl: 0
        priority: high
        clickAction: >-
          http://xxx.xxx.xxx.xxx:81/ui3.htm?maximize=1&tab=alerts&cam={{trigger.payload_json.camera}}&rec={{trigger.payload_json.db}}
        image:http://xxx.xxx.xxx.xxx:81/alerts/{{trigger.payload_json.id}}
        actions:
          - action: URI
            title: Live View
            uri: >-
              http://xxx.xxx.xxx.xxx:81/ui3.htm?maximize=1&cam={{trigger.payload_json.camera}}
          - action: URI
            title: View Clip
            uri: >-
              http://xxx.xxx.xxx.xxx:81/ui3.htm?maximize=1&tab=alerts&cam={{trigger.payload_json.camera}}&rec={{trigger.payload_json.id}}
      title: Blue Iris
  - action: notify.mobile_app_my_phone
    data:
      message: >-
        {{ trigger.payload_json.type }} was detected on the {{
        trigger.payload_json.name }} camera.
      data:
        channel: BI
        ttl: 0
        priority: high
        clickAction: >-
          http://xxx.xxx.xxx.xxx:81/ui3.htm?maximize=1&tab=alerts&cam={{trigger.payload_json.camera}}&rec={{trigger.payload_json.db}}
        image: http://xxx.xxx.xxx.xxx:81/alerts/{{ trigger.payload_json.id }}
        actions:
          - action: URI
            title: Live View
            uri: >-
              http://xxx.xxx.xxx.xxx:81/ui3.htm?maximize=1&cam={{
              trigger.payload_json.camera }}
          - action: URI
            title: View Clip
            uri: >-
              http://xxx.xxx.xxx.xxx:81/ui3.htm?maximize=1&tab=alerts&cam={{
              trigger.payload_json.camera }}&rec={{ trigger.payload_json.id }}
      title: Blue Iris
mode: queued
max: 10

The automation is triggering, but it’s not sending anything to my phone.
I am not sure if it’s because I have an old payload or if there’s something else I am missing.

Thanks!

I’m not going to be able to be a ton of help because I’ve switched from BlueIris to Frigate. But it sounds like you had things working well in Node Red for this.

Here’s a couple of things to try:

  • Try manually triggering a notification to your phone through Developer tools > Actions > Send a notification via mobile_app_my_phone. Send just a text message with no URL to start with.
  • You’re setting a variable camera_name, but I didn’t see that being used (I may have just missed it).
  • Change your automation to be just to send a text message and include all the items you are using such as {{trigger.payload_json.name }}
  • Post your working NodeRed action that gives the trigger. Maybe someone can help spot what’s wrong with your automation action.

In case anyone else struggles, here’s where I landed in a functional automation on the most recent HA and BI…This is a little redundant from my last post, but I wanted to put everything in a single spot for (hopefully) ease of recreation. This has a few things, one it makes sure there’s actually a detection from my alert, it checks that it hasn’t made an alert on that camera within the last minute, and it prevents clicking the main message from opening the Home Assistant app.

BI Configuration (this needs to be in the Alert Notification for each camera…you also have to have MQTT configured in the main settings

MQTT Topic: BI/&CAM/attributes
Post/Payload: {"memo": "&MEMO","db":"&ALERT_DB"}

MQTT Topic: BI/&CAM/alert-image-b64
Post/Payload: &ALERT_JPEG

I moved away from the MQTT.yaml and went to a package (put in /packages) for all the camera info. I named it cameras.yaml and it looks like this

mqtt:
  camera:
    # Front Yard PTZ
    - topic: BI/Front2/alert-image-b64
      name: Front2 Alert
      unique_id: camera.front2_alert
      image_encoding: b64
   sensor:
    # Front Yard Camera Attributes
    - state_topic: BI/Front2/attributes
      name: Front2 Alert Attributes
      unique_id: sensor.front2_alert_attributes
      value_template: '{{value_json.memo}}'
      json_attributes_topic: BI/Front2/attributes
input_datetime:
  last_alert_front2:
    name: "Last Alert - Front"
    has_date: true
    has_time: true

you will need to #include the cameras.yaml in your configuration.yaml

Here’s the actual automation yaml

alias: Working Final Camera Notification Automation
description: The Blue Iris Notification Replacement
triggers:
  - trigger: mqtt
    topic: BI/+/alert-image-b64
conditions: []
actions:
  - variables:
      camera_name: "{{ trigger.topic.split('/')[1] }}"
      sensor_entity: sensor.{{ camera_name | lower }}_alert_attributes
      last_alert_entity: input_datetime.last_alert_{{ camera_name | lower }}
  - delay:
      milliseconds: 500
  - variables:
      alert_db: "{{ state_attr(sensor_entity, 'db') | replace('@', '') }}"
      memo: "{{ state_attr(sensor_entity, 'memo') }}"
      last_alert_time: "{{ states(last_alert_entity) | as_timestamp | default(0) }}"
      time_since_last: "{{ as_timestamp(now()) - last_alert_time }}"
  - condition: template
    value_template: "{{ memo not in ['none', 'None', none] }}"
  - condition: template
    value_template: "{{ time_since_last >= 60 }}"
  - action: input_datetime.set_datetime
    target:
      entity_id: "{{ last_alert_entity }}"
    data:
      datetime: "{{ now().isoformat() }}"
  - target:
      entity_id: camera.{{ camera_name }}_alert
    data:
      filename: /config/www/{{ camera_name }}.jpg
    action: camera.snapshot
  - action: notify.mobile_app_pixel_7_pro
    data:
      message: "{{ memo }} detected on {{ camera_name }} camera."
      title: Blue Iris Alert
      data:
        ttl: 0
        priority: high
        image: http://<home assistant ip>:8123/local/{{ camera_name }}.jpg
        clickAction: noAction
        vibrationPattern: '[100, 50, 50, 50]'
        actions:
          - action: URI
            title: Live View
            uri: http://<BI IP>/ui3.htm?maximize=1&cam={{camera_name}}
          - action: URI
            title: View Clip
            uri: >-
              http://<BI IP>:81/ui3.htm?maximize=1&tab=alerts&cam={{camera_name}}&rec={{alert_db}}
mode: queued
max: 10