Blue Iris motion alerts to notification with image in Home Assistant

Thank you.

Trying to get @TheHolyRoger simpler method working for Android. Able to get the alert text via Automation but can’t get the image via data

  • Not Node Red
  • Able to display the alert on my dashboard via picture card/entity
  • success in storing alert image in the www folder

Just can’t get the image in the notification, help with the data settings in automation?

Are you able to access the images via the public URL? Try sending a persistent notification in HA and see if that works (both examples here Blue Iris motion alerts to notification with image in Home Assistant - #54 by TheHolyRoger)

If you can’t access the image via the URL it might be a permissions thing on the www folder

sorry i assumed you had it setup to work like the node red configuration which triggers from the MQTT topic and not off the motion events, which was the part i was trying to wrap my head around.

Also took me a bit to figure out you have it running via a script instead of directly in the automation.

Which MQTT topic are you talking about? The trigger can be anything you want.

Also it’s not running in a script, this is a very simple automation. I’m the confused one now :slight_smile:

Edit: Sorry yeah I see my doorbell code above is a script and not an automation but just copy and paste the individual actions you want. I just pasted the whole thing so you could see my example which is triggered by the doorbell instead of the motion alert. Triggering on the MQTT topic should be a simpler automation using the trigger in one of my posts above

1 Like

I have updated my config to take advantage of the base64 handling that @TheHolyRoger added to Home Assistant. NodeRed is no longer required to do the base64 image decoding.

One thing that initially tripped me up as I’m making changes is the MQTT camera configuration format has changed. See the “Configuration” section of MQTT Camera

I changed my configuration from this:

camera:
  - platform: mqtt
  name: Patio Alert
  unique_id: camera.patio_alert
  topic: BI/patio/alert-image

To this:

mqtt:
  camera:
    - topic: BI/patio/alert-image-b64
      name: Patio Alert
      unique_id: camera.patio_alert
      encoding: b64

Notice that I changed the topic name from BI/patio/alert-image to BI/patio/alert-image-b64, because that’s the topic name I’ve used in my BlueIris config to send the base64 encoded image.

Here’s how I added a notification with an image to automations.yaml. This version is hardcoded for one camera to make it easy to understand.

- id: 'some-unique-id'
  alias: Blue Iris camera alert
  trigger:
  - platform: mqtt
    topic: BI/patio/alert-image-b64
  condition: []
  action:
  - service: notify.mobile_app_iphone
    data:
      message: Person detected on Patio
      data:
        entity_id: camera.patio_alert
  mode: queued

And this is how to make it work for any camera without hardcoding the name.

- id: 'some-unique-id'
  alias: Blue Iris camera alert
  trigger:
  - platform: mqtt
    topic: BI/+/alert-image-b64
    variables:
      camera_name: "{{ trigger.topic.split('/')[1] }}"
  condition: []
  action:
  - service: notify.mobile_app_iphone
    data:
      message: "Person detected: {{ camera_name }}"
      data:
        entity_id: camera.{{ camera_name }}_alert
  mode: queued

And now this works without NodeRed! Thanks so much @TheHolyRoger!

6 Likes

First time playing around with images and automation. Got the native b64 image to camera entity working, but how do you do the automation for the image notification using node-red?

I attempted the node-red route and never got it working correctly. I went @TheHolyRoger route with automation. While not 100% it’s very close. For my version, I simplified the file management and created individual automations for my 4 cameras.

My setup is the latest version of HA, android phone.

I can’t seem to get OP’s original Node-RED flow to import “Error: Input not a JSON Array”. Anyone have any ideas?

EDIT: if anyone gets stuck, there are three ‘’’ at the end. Just remove them.

1 Like

@ColfaxUpton Thanks for spotting that error with the three backticks. They were needed to post here in code format, but I needed to move them to the next line of the post so they wouldn’t get included in the Node Red import.

I think the Node Red code in the first post is fixed now and there’s nothing to remove.

@gmow1 I was close but could not get the encoding: b64 method of @TheHolyRoger to work. I kept getting a padding error from the MQTT JSON payload.

But I used some of his methods as well as @ronaldjeremy to finally get it to work on Android with success. I get the notification in the companion app. It saves to the www folder and I can click the notification image to actually view the clip.

Here is what I did:

In my configuration.yaml file, I added:

mqtt:
  camera:
    - topic: BI/porch/alert-image-b64
      name: Porch Alert
      unique_id: camera.porch_alert

In Blue Iris, I added the following topic and payload:

This is what my automation looks like:

- id: '1656252280379'
  alias: Blue Iris camera alert (New)
  variables:
   file_time: '{{ now().strftime(''%Y%m%d_%H%M%S'') }}'
  description: ''
  trigger:
  - platform: mqtt
    topic: BI/porch/alert-image-b64
  condition: []
  action:
  - service: camera.snapshot
    data:
      filename: /config/www/{{ file_time }}_frontporch_ha.jpg
    target:
      entity_id: camera.front_door_cam_sub
  - service: notify.mobile_app_scott_s_s21
    data:
      message: A person was detected on the {{trigger.payload_json.cam}} camera at
        {{trigger.payload_json.time}}.
      title: Person Detected on Front Porch
      data:
        ttl: 0
        priority: high
        clickAction: http://your_remote_link_to_BI:81/ui3.htm?maximize=1&tab=alerts&cam={{trigger.payload_json.cam}}
          &rec={{trigger.payload_json.db}}
        image: /local/{{ file_time }}_frontporch_ha.jpg
  mode: queued

The only thing I have left to do is use @TheHolyRoger method to delete the snapshot images from the www folder.

Hope this helps!

Scott

1 Like

This looks good, thanks for sharing your script. Currently, I am using automation(Not Node-Red) for my notifications. My automation overwrites the image file every new alert. I’ve created individual automation for each camera.

I display the image with the alert.

service: notify.mobile_app_GLM_S21
data:
message: Garage Alert
data:
image: /local/garage_inside_alert.jpg

Not perfect as sometimes I get the alert but no image. I think it may be a timing issue?

Yeah, I ditched the Node Red version too. Every now and then, I do not get an image; about every 1 out of 10. But I do get the db marker where I can watch the alert.

Sometimes, even with the Blue Iris Push notification, I don’t get an alert at all either, so it may be a timing issue.

What version of BI are you using? Sounds like it sends the image unencoded if you’ve got a padding error and it works fine without

The latest version. 5. Something.

Any way to make it so when you actually click the notification it opens the correct clip? Presumably utilising something like here?

Not sure what you mean about clicking the notifications? I haven’t got any links set up in my notifications, it just sticks the image in there.

If you mean your notifications all show the same image then you need to do what I’ve shared above which is to take snapshots with the date/time in the filename, that way each notification shows up separately

Strange! Not sure why you’re able to send the image unencoded but glad it works

This is what I do. When my camera detects motion, it creates a camera snapshot and passes it to HA via a MQTT topic with a MQTT payload that includes camera name, time, and db pointer for the clip.

MQTT Topic:
BI/porch/alert-image-b64

MQTT Payload:
{“db”:"&ALERT_DB",“cam”:"&NAME",“time”:"%X"}

When I click the snapshot notification, it plays the actual clip.

Here is my rule:

alias: 'Blue Iris: Front Porch Notification'
description: ''
trigger:
  - platform: mqtt
    topic: BI/porch/alert-image-b64
condition: []
action:
  - service: camera.snapshot
    data:
      filename: /config/www/{{ file_time }}_frontporch_ha.jpg
    target:
      entity_id: camera.front_door_cam_sub
  - service: notify.mobile_app_scott_s_s21
    data:
      message: >-
        A person was detected on the {{trigger.payload_json.cam}} camera at
        {{trigger.payload_json.time}}.
      title: Person Detected on Front Porch
      data:
        ttl: 0
        priority: high
        clickAction: >-
          http://your_ip_address:81/ui3.htm?maximize=1&tab=alerts&cam={{trigger.payload_json.cam}}
          &rec={{trigger.payload_json.db}}
        image: /local/{{ file_time }}_frontporch_ha.jpg
variables:
  file_time: '{{ now().strftime(''%Y%m%d_%H%M%S'') }}'
mode: queued

I have this in my configuration.yaml file:

mqtt:
  camera:
    - topic: BI/porch/alert-image-b64
      name: Porch Alert
      unique_id: camera.porch_alert

Works like a champ!

Hope this helps.

Scott

4 Likes

Exactly what I was after thank you in terms of what i’m wanting to achieve.

I’m missing a few steps I think though. I have the camera sending mqtt alerts no worries, I have set up the ‘alert’ mqtt camera. But presumably right now it’s toppling over with the actual automation part.

For example this:

So am I right in thinking this part is generating the .jpg file from the camera.snapshot service and naming it accordingly within the /config/www/ folder? And then that same filename is referenced later in the data section to display in the alert?

I also get this error in file editor:
end of the stream or a document separator is expected at line 27, column 1:
variables:
^
(that line is the line ‘variables:’)