Blue Iris motion alerts to notification with image in Home Assistant

It looks like you’re using the VSC add-on? Perhaps it is a bug with the editor flagging it as incorrect, or it is out-of-date?

I can confirm that my cameras setup like this are working… I have the configs in a little different ordering, here’s an example:

mqtt:
  camera:
      - topic: BlueIris/sidegate/alert-image
        name: Sidegate Alert
        unique_id: camera.bi_sidegate
        encoding: b64

@wjbeckett, this is fantastic! Love the Live View and View Clip in the notification. Only because I prefer having my notifications in ‘Node-Red’, do you know how to convert your automation into node red?, struggling to get the variables into the notify output.

thanks! yeah I am. I didn’t think it would let me save it, but it did, and it works…kind of. I get the alert now, but get an error instead of the picture about “HLS stream unavailable”. Not sure what that’s all about.

Edit:
I ended up upgrading from BI4 to BI5.
Now seems like everything is working as far as actually sending the image. I just need to do some tweaking on the HA side to get it how I want it.

Glad you got it working. Yes, BI5 adds a lot of new features!

I found that this setup works for me on my Android phone.

BI sends two MQTT messages on alert:

Topic: BlueIris/&CAM/alert

{ "id":"&ALERT_DB", "object":"&MEMO", "camera":"&CAM", "name":"&NAME" }

Topic: BlueIris/&CAM/alert-image

&ALERT_JPEG

This is how I’m sending the image, all of my cameras are named with a standard “camera.[BI short cam name]_alert:”, e.g. “camera.sidegate_alert”.

image: '/api/camera_proxy/camera.{{ trigger.payload_json.camera }}_alert

I get the picture whether on my home WiFi or away from home on cellular data (4G/5G). I do subscribe to Nabu Casa, which is how I think this works when off-net (?) as neither HA or BI is exposed to the Internet.

Here’s the full automation I use (based on @wjbeckett previous post), which in my case I only want to trigger between 1 hour after sunset and sunrise. I also use a specific notification channel “BlueIris” so that I can set a different notification sound for BI alerts on the HA Companion app (an annoying one that will wake me up if AI detects a person in the back yard late at night, for example):

- id: blueiris_notification
  alias: Blue Iris Notification
  description: ''
  trigger:
  - platform: mqtt
    topic: BlueIris/+/alert
  condition:
  - condition: sun
    after: sunset
    after_offset: 01:00:00
    before: sunrise
  action:
  - delay: 1
  - service: notify.mobile_app_[DEVICE NAME]
    data:
      message: A {{ trigger.payload_json.object.split(":")[0].strip('%') }} was detected
        on the {{ trigger.payload_json.name }} camera.
      data:
        channel: BlueIris
        ttl: 0
        priority: high
        clickAction: http://[NVR IP]:81/ui3.htm?maximize=1&tab=alerts&cam={{
          trigger.payload_json.camera }}&rec={{ trigger.payload_json.id }}
        image: '/api/camera_proxy/camera.{{ trigger.payload_json.camera }}_alert'

        actions:
        - action: URI
          title: Live View
          uri: http://[NVR IP]:81/ui3.htm?maximize=1&cam={{ trigger.payload_json.camera
            }}
        - action: URI
          title: View Clip
          uri: http://[NVR IP]:81/ui3.htm?maximize=1&tab=alerts&cam={{ trigger.payload_json.camera
            }}&rec={{ trigger.payload_json.id }}
  mode: queued

Hope this helps.

1 Like

Just sharing this automation in case others find it useful, I’ve got deepstack setup and a hotspot zone marking the path to my front door. This automation then checks if there’s a person in my drive and then sends a TTS message to my phone.

Usually this fires just before my doorbell automation which actually does send a camera snapshot to my phone with another TTS - I shared that somewhere earlier in the thread :slight_smile:

(no image notification in this one but if you want that you can copy-paste one of the example action sequences in this thread)

BI sends an entirely separate MQTT alert from the main camera image alert with the AI info.

BI Alert example:
MQTT Topic: BI/hotspot_info/camera1
Payload: { "alert_db": "&ALERT_DB", "alert_date": "&ALERT_TIME", "json": &JSON, "memo": "&MEMO", "type": "&TYPE" }

HASS Automation example:

alias: "[CameraAlert] Camera1"
description: ""
trigger:
  - platform: mqtt
    topic: BI/hotspot_info/camera1
condition:
  - condition: state
    entity_id: input_boolean.motionalert_front_drive
    state: "on"
action:
  - 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 "person" 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: >-
                      {% set memo_data = 'memo' in trigger.payload_json and trigger.payload_json.memo %}
                      {{ true if memo_data and 'person' in memo_data else false }}
                sequence:
                  - repeat:
                      count: "1"
                      sequence:
                        - service: notify.mobile_app_phone1
                          data:
                            message: TTS
                            title: Someone's coming sir
                            data:
                              media_stream: alarm_stream_max
                              importance: max
                              tts_text: Someone's coming sir
                        - delay:
                            hours: 0
                            minutes: 0
                            seconds: 10
                            milliseconds: 0
            default:
              - repeat:
                  count: "1"
                  sequence:
                    - service: notify.mobile_app_phone1
                      data:
                        message: TTS
                        title: Someone might be coming sir
                        data:
                          media_stream: alarm_stream_max
                          importance: max
                          tts_text: Someone might be coming sir
                    - delay:
                        hours: 0
                        minutes: 0
                        seconds: 10
                        milliseconds: 0
mode: single

thanks!
yeah im doing something similar as @wjbeckett as well. Except I’m sending the image and a caption to telegram

service: telegram_bot.send_photo
data:
  url: http://<bi_ip>:<bi_port>/alerts/{{ trigger.payload_json.id }}&fulljpeg
  caption: >-
    A {{ trigger.payload_json.object.split(":")[0].strip('%') }} was detected on
    the {{ trigger.payload_json.name }} camera.

The other part im trying to figure out would be how to attach a 5 second clip. The old way I was alerting was straight from BI, and attaching 3 pictures and a video clip to an email. I would like to try to replicate that with homeassistant.

1 Like

I ended up getting videos sending to telegram working for anyone else that might be interested.

TL;DR - On alert, send a video to an FTP server that HA has access to (could use HA FTP add-on), use HA folder_watcher add-on to watch when the file has been modified, then use telegram_bot to send the video.

BI supports sending a video file via FTP on alert. The bummer is BI doesn’t support SFTP (although they do support FTPS). I didn’t love the idea of sending the video over plain text FTP (and couldn’t get FTPS working with the BI FTP add-on), so I spun up an FTP server on the BI host, and configure BI to use that local FTP server. Then I network share the FTP directory (on the BI host), and mount that share on my HA host at /bialerts.

Folder Watcher Config
Then I configured HA folder_watcher add-on (configuration.yml) to watch that directory:

folder_watcher:
  - folder: /bialerts
    patterns:
      - "*.mp4"

You will also need to add this to configuration.yml as well:

homeassistant:
  allowlist_external_dirs:
    - "/media"

Camera Alert Config
Then in BI i setup the alert like this:


this will create an mp4 file in the directory with the short name of the camera.

Automation Config
Then I setup my automation like this:

  - wait_for_trigger:
      - platform: event
        event_type: folder_watcher
        event_data:
          event_type: modified
          path: /bialerts/{{ trigger.payload_json.camera }}.mp4
      - platform: event
        event_type: folder_watcher
        event_data:
          event_type: created
          path: /bialerts/{{ trigger.payload_json.camera }}.mp4
    timeout:
      hours: 0
      minutes: 1
      seconds: 0
      milliseconds: 0
  - service: telegram_bot.send_video
    data:
      file: /bialerts/{{ trigger.payload_json.camera }}.mp4

This will watch for if an mp4 file is created or modified with the camera short name, with a timeout of 60 seconds, in my testing it takes my setup around 10 seconds to complete, but you might have to adjust this timeout as needed.

Thoughts
I dont have a lot of cameras, and dont get a lot of alerts, but so far correct video has been attached.

This could be simplified IF BI supported SFTP, OR if you dont care about sending video files over FTP, or setup FTPS server/got HA FTP addon working with FTPS, to be fair I didn’t spend much time on getting FTPS working.

I migrated my deepstack AI alert automation to a blueprint which is now here: BlueIris Deepstack AI Alert Confirmation

Feedback is welcome :wink: I tried to make it configurable for my needs and hopefully others too!

Just tried this with the latest HA and couldn’t get the mqtt camera to load the image until I realized 2 things:

  1. I have to actually trigger the camera instead of just using the test button on the “On Alerts” config dialog to generate an image
  2. the mqtt camera docs state that the camera should be set up with “image_encoding: b64”, not “encoding: b64” so my camera def looks like this:
mqtt:
  camera:
    - topic: BlueIris/gate/alert-image
      name: Gate Alert
      unique_id: camera.gate_alert
      image_encoding: b64
1 Like

Thanks for the update about needing image_encoding: b64 That must have changed since when I set this up, and I was just starting to investigate why my alert images stopped working.

I noticed that this changed when I upgraded to core 2022.12. I suddenly stopped getting images in my HA companion app alerts. I was using encoding: b64 and it was working fine under 2022.11.

Changed those to image_encoding: b64 and all was well again.

Thanks for pointing this out guys. I try to be diligent and read the release notes and breaking changes every single month but it’s easy to miss! Does seem mad to me how quickly hass deprecates and removes features but 🤷

@jbouwh thanks for this Christmas present :wink:

Hi there,

Thank you for sharing this.

The notification with the blue iris link worked perfectly for me, but I didn’t receive the image preview. My automotion is giving me the following error:

Stopped because an error was encountered at December 29, 2022 at 12:30:52 PM (runtime: 1.02 seconds)
Error rendering data template: UndefinedError: ‘dict object’ has no attribute ‘payload_json’

In this topic I can see that other people also got this error and it has something to do with backquotes, but I don’t understand what I did wrong.

this is how i set my blue iris topics config:

BlueIris/&CAM/alert

{ “id”:"&ALERT_DB", “object”:"&MEMO", “camera”:"&CAM", “name”:"&NAME" }

BlueIris/&CAM/alert-image

&ALERT_JPEG

@royle Use MQTT Explorer to inspect each alert event and check if the data is valid JSON.

Valid JSON should look like what’s in screenshot below. I suspect there is something in one of your variables that is breaking the JSON.

For example, don’t use &ALERT_JPEG temporarily to see if your ‘dict object’ error goes away.

1 Like

You’re using the wrong quote mark :slight_smile:

Your quotes: “”

Correct quotes: ""

If you look closely you’ll see yours are slanted, courtesy of Bill Gates :wink: … Never use those slanted ones anywhere :wink:

To disable them permanently:
https://support.microsoft.com/en-us/office/smart-quotes-in-word-702fc92e-b723-4e3d-b2cc-71dedaf2f343

Apparently they’re called “smart quotes”. Not sure what makes them smart though.

Also worth noting that this forum for some stupid reason auto converts quote marks to smart quotes unless you put them in code blocks. @wjbeckett could you edit your post? I think a few people are copying and pasting it and your example is not wrapped in a code block

2 Likes

Thank you for your response,

After following the link, I think I fixed it, but when I paste it here, it gets the wrong quotes again.

The image is still missing.

I tried the MQTT explorer and it appears that everything is working correctly

Could you please give me some suggestions based on the screenshot below?

Looks better there I think, share your mqtt camera config in home assistant now

Use ` on this forum either side of code to stop it changing the quote marks

Thank you so much for helping me with this,
I’m going crazy!
Here is how the camera is configured, i am using BI short name:

mqtt:
  camera:
    - topic: BlueIris/Gate-cam/alert-image
      name: Gate-cam_alert
      unique_id: camera.Gate-cam_alert
      image_encoding: b64
 
    - topic: BlueIris/Backyardcam2/alert-image
      name: Backyardcam2_Alert
      unique_id: camera.Backyardcam2_alert
      image_encoding: b64

    - topic: BlueIris/Backyard_cam/alert-image
      name: Backyard_cam_Alert
      unique_id: camera.Backyard_cam_alert
      image_encoding: b64

Can you show the blue iris config for alert-image now? It’s weird that it says “no record” before the base64 data, that might be the problem…

Are there no errors showing up in home assistant?


This errors not showing up in home assistant