Blue Iris motion alerts to notification with image in Home Assistant

The automation is triggered by someone ringing my doorbell. But that’s entirely separate to getting a working MQTT camera entity in HA that receives images from the BI alert trigger.

You want to create a create BI alerts and MQTT camera entities as in this post: Blue Iris motion alerts to notification with image in Home Assistant - #48 by TheHolyRoger

That should give you camera entities which show the last triggered image from BI.

Then you set up an automation (completely separate) to snapshot the MQTT camera and send the notification to your phone.

The trigger for that automation is entirely up to you, if you want to trigger it on every BI alert then you’d use a MQTT trigger. In my above examples the MQTT automation trigger would be:

platform: mqtt
topic: BI/alerts/amcam1

Hope that makes sense

I have been able to get the BI>HA(Node red) setup working for Android with an image with one issue. Upon a single alert from BI I get continuous notifications on my phone. The notify node stays on continually sending out notifications.

Any suggestions?

@TheHolyRoger were you able to confirm that your code was added to release 2022.6. If so, excellent news!

Yes sir it’s in the full changelog: Full Changelog for Home Assistant Core 2022.6 - Home Assistant

1 Like

Oh, neat! Thanks for showing me! I had obviously only been reading the mini version of that. Well done, mate!
EDIT: Updated, and immediately it’s working perfectly!

1 Like

I am getting closer. You care to share your automation as to how to delete the old images if possible?

Scott

Sure, I have a shell command for that:

shell_command:
  delete_old_snapshots: 'find /config/www -maxdepth 1 -type f -mtime +1 -name *_ha.JPG -exec rm {} -f \;'

Modify *_ha.JPG to match your file name pattern
-mtime +1 means files older than 1 day, modify to suit

Then I have a daily maintenance automation:

alias: '[Maintenance] Daily Tasks'
description: ''
trigger:
- platform: time
  at: 04:00:00
condition: []
action:
- service: shell_command.delete_old_snapshots
  data: {}
mode: single
1 Like

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.