@flyinglow Running current version - 2022.8.7. I have now managed to get deepstack images showing for each mqtt camera entity so the encoding appears to be working. The error is still showing up for each camera in yaml though. Don’t really know if this is an issue or not but all seems to work. Using your automation.yaml example I have been able to get notifications working on my android for each camera, however I only see the message text, not the deepstack image.
Strange, running same version of HASS here and everything fine. Suggest checking camera config syntax:
Config example:
mqtt:
camera:
- unique_id: mq_alerts_cam1
topic: BI/alerts/cam1
encoding: b64
name: Alerts Cam1
Thanks @TheHolyRoger. I think I have it down correctly. My MQTT Camera is…
mqtt:
camera:
- unique_id: CAM1_person_detected
topic: BI/CAM1/person-detected-b64
encoding: b64
name: CAM1 Person Detected
(new to these forums so don’t know how to paste the config correctly)
My picture card entity for this refreshes perfectly each time with a new deepstack image. So from what I can tell the encoding is working. Do I need to implement something to delete images in the background as you have done above or will this entity only save the most current image?
I’ve used flyinglow’s example for my notification automation. This works but no image in the notification. I am using an android so I have been trying to implement @ronaldjeremy’s replacement for the entity ID line with little success. New to this so not sure how/if I need to alter this line for my setup.
“image”: “/api/camera_proxy/camera.” & $split(topic,’/’,3)[1] & “_alert”
A camera entity saves no images by default so you don’t need to worry about any cleanup there.
There’s a couple of different options in this thread and they work differently, I’m doing the simple route myself and just sending the image to a notification, spalexander has a method that makes the notifications links to the blueiris web UI alert which is quite cool
flyinglow is doing it differently to me, my method is here:
Note that this is a script
and not an automation
so either make a script like I do and trigger the script inside your automation or copy the actions into your automation.
The script steps are:
- Take a snapshot of the camera entity, save to file with timestamp in the filename
- Notify the mobile app + persistent notifications with the snapshot image
Then I have a separate automation detailed here:
Which deletes the old snapshots as a daily task
I can’t seem to get this to work on my home assistant and when the autimation runs when i check the trace i have this error message
Error: Error rendering data template: UndefinedError: ‘dict object’ has no attribute ‘payload_json’
My code for the automation is below
id: '1663062728004'
alias: 'Blue Iris: Front Porch Notification'
description: ''
trigger:
- platform: mqtt
topic: BI/frontporch/alert-data
condition: []
action:
- service: camera.snapshot
data:
filename: /config/www/frontporchalert.jpg
target:
entity_id: camera.front_porch_alert
- service: notify.mobile_app_pixel_6
data:
message: 'A person was testing '
title: Person Detected on Front Porch
data:
ttl: 0
priority: high
clickAction: >-
http://192.168.1.2:81/ui3.htm?maximize=1&tab=alerts&cam={{trigger.payload_json.cam}}
&rec={{trigger.payload_json.db}}
image: /local/frontporchalert.jpg
variables:
file_time: '{{ now().strftime(''%Y%m%d_%H%M%S'') }}'
mode: queued
I’ve got two camera MQTT sensors set up. One is for the camera image from BlueIris which accepts B64 and that is camera.front_porch_alert and that is working fine on another automation.
I’ve then got another one which is camera.front_porch_alert_data and that is set up the same way as @spalexander
That receives the same MQTT topic data as above.
has anyone got any idea where i’m going wrong?
Yep, a like for like copy
If you inspect the trace I think it gives you the trigger data, if it does paste that here
So here’s the payload HA is receiving
payload: ‘{“db”:"@140939087",“cam”:“Front Porch”,“time”:“07:02:45”}’
hmm looks like you want payload
instead of payload_json
maybe something changed between HA versions?
Just tried that and whilst that allows the automation to run the link to BlueIris is only this
clickAction: http://192.168.1.2:81/ui3.htm?maximize=1&tab=alerts&cam= &rec=
How strange, is the trigger data still the same syntax for that trace?
Maybe try this syntax too for both db
and cam
variables and see if it makes a difference:
Instead of:
trigger.payload_json.db
trigger['payload_json']['db']
trigger.payload['db']
Maybe also send a notification to your phone or a logbook message with the full trigger data it sends so you can see what’s going on:
action:
...
- service: notify.mobile_app_pixel_6
data:
message: >-
{{trigger}}
{{trigger.payload_json.db}}
{{trigger.payload_json.cam}}
{{trigger.payload.cam}}
{{trigger.payload['cam']}}
title: Debug
Ahhh I can see what’s going on now, you’re sending invalid json which is why it doesn’t get parsed to payload_json
The problem is the quote marks you’e using in your BlueIris alert setup
Instead of ”
Use "
That’s got it working!!
Excellent, thank you very much
I discovered that Blue Iris has URLs that you can access directly to pull images from. This means I no longer need to use a camera entity and I can pass the image from the BI URL directly into the notification.
Just thought I’d share my solution for this.
Each camera is configured like this for alerts:
MQTT Topic: BlueIris/&CAM/alert
Post/payload: {“id”:"&ALERT_DB",“object”:"&MEMO",“camera”:"&CAM",“name”:"&NAME"}
I then created an automation in Home Assistant that grabs the variables, attaches the image and sends the notification. Bonus is that clicking on the notification will open the BI URL to a clip of the alert as well.
- id: 'blueiris_notification'
alias: 'Blue Iris Notification'
description: ''
trigger:
- platform: mqtt
topic: BlueIris/+/alert
variables:
camera_name: "{{ trigger.topic.split('/')[1] }}"
condition: []
action:
- service: notify.mobile_app_pixel_7_pro
data:
message: >-
A {{ trigger.payload_json.object.split(":")[0].strip('%') }} was detected on the {{ trigger.payload_json.name }} camera.
data:
ttl: 0
priority: high
clickAction: "http://<BI_IP>:81/ui3.htm?maximize=1&tab=alerts&cam={{ trigger.payload_json.camera }}&rec={{ trigger.payload_json.id }}"
image: "http://<BI_IP>:81/alerts/{{ trigger.payload_json.id }}&fulljpeg"
actions:
- action: "URI"
title: "Live View"
uri: http://<BI_IP>:81/ui3.htm?maximize=1&cam={{ trigger.payload_json.camera }}
- action: "URI"
title: "View Clip"
uri: http://<BI_IP>:81/ui3.htm?maximize=1&tab=alerts&cam={{ trigger.payload_json.camera }}&rec={{ trigger.payload_json.id }}
mode: queued
@wjbeckett, thanks for sharing this!!
However, I’m not getting the alerts in the app (Android), and I’ve been pulling my hair out trying to figure out why I’m seeing this error in the trace (I’m on HA 2022.10.5):
Error rendering data template: UndefinedError: 'dict object' has no attribute 'payload_json'
I cut-and-pasted your BI payload, and your automation (with the necessary changes to the “notify” mobile app and added the necessary “<BI_IP>” settings, of course).
I’ve verified the BI is sending the MQTT string using MQTT.fx, so that is all working:
{“id”:"@182539285",“object”:"person:63%",“camera”:"sidegate",“name”:"Side Gate"}
I’ve done a search for this error, but only found an issue on Github regarding Shelly autodiscovery, not really anything more.
Any ideas?
SOLVED: Somehow the quotes around the names (e.g. “id”) were backquotes. I fixed those to normal quotation marks, and it is now working. Found this by using an online JSON validation tool, which kept failing until my mental lightbulb went off. Apparently ‘payload_json’ is only an attribute if there is valid JSON. Thanks again for sharing this!
Error in my log, camera works and the notification work however my log file gets filled up. I’ve truncated the message. My mqtt.yaml file is
camera:
-
name: Garage_Inside Alert
unique_id: camera.garage_in_alert
image_encoding: b64
topic: BI/alert/Gar_Inside -
name: Driveway Night Alert
unique_id: camera.driveway_night_in_alert
image_encoding: b64
topic: BI/alert/Driveway_Night -
name: Lower Patio Alert
unique_id: camera.lower_patio_in_alert
image_encoding: b64
topic: BI/alert/Lower_Patio -
name: Front Door Alert
unique_id: camera.front_door_in_alert
image_encoding: b64
topic: BI/alert/Front_Door
Logger: homeassistant.util.logging
Source: util/logging.py:168
First occurred: 12:24:30 PM (2 occurrences)
Last logged: 12:24:54 PM
Exception in message_received when handling msg on ‘BI/alert/Gar_Inside’: ‘b’{"_events":{},"_eventsCount":0,“bitmap”:{“width”:1280,“height”:720,“exifBuffer”:{“0”:0,“1”:77,“2”:77,“3”:0,“4”:42,“5”:0,“6”…255,13,1,1,255,16,0,3,255,16,0,1,255]}},"_background":0,"_originalMime":“image/jpeg”,"_exif":{“startMarker”:{“offset”:0},“tags”:{“Software”:“Blue Iris”,“DateTimeOriginal”:1653853537},“imageSize”:{“height”:720,“width”:1280},“app1Offset”:24},"_rgba":true}’’ Traceback (most recent call last): File “/usr/src/homeassistant/homeassistant/components/mqtt/debug_info.py”, line 44, in wrapper msg_callback(msg) File “/usr/src/homeassistant/homeassistant/components/mqtt/camera.py”, line 150, in message_received self._last_image = b64decode(msg.payload) File “/usr/local/lib/python3.10/base64.py”, line 87, in b64decode return binascii.a2b_base64(s) binascii.Error: Incorrect padding
Really loving this! But I wonder how to make it work with sending picture to telegram instead of to mobile phone.
I got it working to send message with camera id but cant figure out how to get the photo also.
Would be really glad if anyone has advise on this.
I just used this in yaml for automation:
alias: Blue Iris camera alert test
description: ""
trigger:
- platform: mqtt
topic: BI/+/alert-image-b64
variables:
camera_name: "{{ trigger.topic.split('/')[1] }}"
condition: []
action:
- service: notify.telegram_main
data:
message: "Person detected: {{ camera_name }}"
data:
entity_id: camera.{{ camera_name }}_alert
mode: queued
I read that on telegram integration page there is this example. But how to get the photo attached?
...
action:
service: notify.NOTIFIER_NAME
data:
title: Send an images
message: "That's an example that sends an image."
data:
photo:
- url: http://192.168.1.28/camera.jpg
username: admin
password: secret
- file: /tmp/picture.jpg
caption: Picture Title xy
- url: http://somebla.ie/video.png
caption: i.e., for a Title
Did you create an MQTT camera as I described in this message?
For me, that’s how I get the images to my notification on my iPhone. Basically that MQTT camera holds the alert image, and the notification I send to the iPhone sends the image with entity_id: camera.{{ camera_name }}_alert
I don’t use Telegram, and I don’t know if their integration supports sending an image straight from a camera. The example you posted shows getting the image from a URL or file. There are some other replies on this thread where people are storing the images to something like /tmp/picture.jpg
which may be what you need to do to make it work for Telegram.