How to attach image entity to an email

Old snapshot is from the Generic Camera.

If I look in HA GUI on the Generic Camera the picture gets updated on trigger, but the picture generated in /config/www/images/doorbell.jpg is some cached one from an earlier trigger (have also tried to manually deleted the picture, but the new generated is old).

The trigger is:
trigger:

  • platform: state
    entity_id: binary_sensor.doorbell_ringing
    from: ‘off’
    to: ‘on’

Also tried to generate multiple snapshots from the same trigger to see if the 2nd or 3rd snapshot would be an updated one.

Also tried to put delays between the different parts of the automation to see if that would have solved it.

I have a separate automation to create my snapshot. Then i have a different automation to email it to me after a time.

No more ideas from anyone how to not get a snapshot from cache, but a live one instead to be attached?

Are you sure that the picture generated in /config/www/images/doorbell.jpg is an old one? If you are using a browser to look at the picture it is probably caching as well. Can you check a time stamp on the file to determine if it’s old or new?

If you have access to the file system I would copy /config/www/images/doorbell.jpg to /config/www/images/doorbell_1.jpg and then open it in a browser to verify that it is really on old image or not.

Hi vic,

Yes, the timestamp of the picture file generated is the same time as the trigger and the picture itself have a timestamp in the picture itself and those do not match.
The file is sent tom my email, so no browser cache involved here.

It is known issue that home assistant will send a cached copy of the snapshot. I originally experienced this problem and was able to resolve it by adding the html option using the cid keyword to the notify call.

Here is my automation.


alias: Mailbox Opened
description: ""
trigger:
  - platform: state
    entity_id:
      - binary_sensor.mailbox_state
    to: "on"
condition: []
action:
  - service: camera.snapshot
    data:
      filename: www/tmp/mailbox.jpg
    target:
      entity_id: camera.driveway
  - delay:
      hours: 0
      minutes: 0
      seconds: 10
      milliseconds: 0
  - service: notify.mail_xxxxx
    data:
      title: Mailbox Opened
      message: "snapshot:"
      data:
        images:
          - www/tmp/mailbox.jpg
        html: |
          <img src="cid:mailbox.jpg">
mode: single

1 Like

Hi vic4news,

Now I copied exactly your code with the delay as well.
I still get 1 picture before the latest picture (not sure if it is like this every time) attached to the email (In HA GUI I get the latest every time).

The html part was nice, so it is in the mail and not as an attachment anymore.

SOLVED!

I take 2 snapshots with a delay of minimum 5 seconds between, then I only use the second snapshot as the attachment.

Thanks for all help from everyone!

Legend. Thanks for the tip. Finally able to send the Eufy doorbell image to my Android TV. :hugs:

@AseKarlsson
Can I get your updated flow to make it work for mobile notifications?
I have been fighting with this all day with no luck.

@Soulflyzz, It stopped working a long time ago and have not put in the time to solve it. If you are able to solve it again, please come back with info!

action: notify.X
metadata: {}
data:
  title: "ALERT ! : Deurcamera alarm"
  message: Zie snapshot in bijlage
  target:
    - [email protected]
  data:
    images:
      - www/tmp/snapvideo.mp4
      - www/tmp/snapshot.jpg

my tmp map is linke config/www/tmp

in my config.yaml I have

  allowlist_external_dirs:
    - /config
    - www/tmp

I am getting the mail, but no attachement. Where am I going wrong ?