Camera Snapshot and send it by email

Hello,

This is my first post here :slight_smile:

I have a Xiaomi door sensor and a Wanscam HW0049.
I am trying to send an email (notify_email) when my sensor detect that my door is open. The email should contain 8 snapshot (with 1 second delay) of my camera.

It is not working (some of my snapshot are old ones, sometimes it takes refreshed ones, and sometimes it takes some old snapshot files)

This is my automation.yaml

- id: '1544444441'
  alias: test door
  trigger:
  - entity_id: binary_sensor.door_window_sensor_15858585858
    from: 'off'
    platform: state
    to: 'on'
  condition: []
  action:
  - data:
      entity_id: camera.camera
      filename: /tmp/snapshot1.jpg
    service: camera.snapshot
  - delay:
      seconds: 1
  - data:
      entity_id: camera.camera
      filename: /tmp/snapshot2.jpg
    service: camera.snapshot
  - delay:
      seconds: 1
  - data:
      entity_id: camera.camera
      filename: /tmp/snapshot3.jpg
    service: camera.snapshot
  - delay:
      seconds: 1
  - data:
      entity_id: camera.camera
      filename: /tmp/snapshot4.jpg
    service: camera.snapshot
  - delay:
      seconds: 1
  - data:
      entity_id: camera.camera
      filename: /tmp/snapshot5.jpg
    service: camera.snapshot
  - delay:
      seconds: 1
  - data:
      entity_id: camera.camera
      filename: /tmp/snapshot6.jpg
    service: camera.snapshot
  - delay:
      seconds: 1
  - data:
      entity_id: camera.camera
      filename: /tmp/snapshot7.jpg
    service: camera.snapshot
  - delay:
      seconds: 1
  - data:
      entity_id: camera.camera
      filename: /tmp/snapshot8.jpg
    service: camera.snapshot
  - data:
      data:
        images:
        - /tmp/snapshot1.jpg
        - /tmp/snapshot2.jpg
        - /tmp/snapshot3.jpg
        - /tmp/snapshot4.jpg
        - /tmp/snapshot5.jpg
        - /tmp/snapshot6.jpg
        - /tmp/snapshot7.jpg
        - /tmp/snapshot8.jpg
      message: Who is this ?
      title: Someone has enter!
    service: notify.mail

Thanks for helping me (I am with Hassio 0.82.0) !

1 Like

My first suspicion is you are asking too much too quickly. I would suggest dropping your photo count in half and doubling the time delay between snapshots… just to see if that is the issue.

Hi @Dixey, it seems to work for now, thanks for the tip

Except my problem of delay, is my file optimized? I wasn’t able to make on call like this :
-camera.snapshot (5 times with 2 seconds of delay) in one line.

I can’t think of a better way than what you are doing now… and hey, if it works, it works.

True, true!

Hello,

My problem is still here.
I receive an email with 5 snapshot on my email (jpg files)
The problem is that the 5 pictures are not what they should be (they are 5 old jpg of camera snapshot). It doesn’t update the snapshot. It is very frustrating…
Anyone knows how I can take 5 snapshot (with 1 second of delay) ?
This code is not working properly with my Wanscam HW0049
- data:
entity_id: camera.camera
filename: /tmp/snapshot1.jpg
service: camera.snapshot
- delay:
seconds: 1

Thanks in advance,

Try naming the file with a time stamp.
tmp/{{now().strftime(‘%Y-%m-%d_%H.%M.%S’)}}_LR.jpg"

This may help

Hola @juan11perez,
Thanks for the reply.
Do you know how can I take all the images to my notify email ?

For now I have that, but with the timestamp, I don’t know how to tell Home assistant Automation to take all the files from tmp
And more, I would like then to delete the file from tmp, to clean the tmp.

  • data:
    data:
    images:
    - /tmp/1.jpg
    - /tmp/2.jpg
    - /tmp/3.jpg
    - /tmp/4.jpg
    - /tmp/5.jpg
    - /tmp/6.jpg
    - /tmp/7.jpg
    - /tmp/8.jpg
    message: Who is here?
    title: someone is here
    service: notify.mail_enter

I have a shell command that I run after sending snapshot that deletes all the images. Reduces the “old picture” issues.

in my configuration.yaml

#shell_command:
#  snapshot_frontdoor_gif: /home/homeassistant/.homeassistant/www/tmp/gif.sh
shell_command:
delete_snapshots: 'rm -f /tmp/*.jpg'

at the end of my automation that sends snapshots
  - delay:
      seconds: 10
 - service: shell_command.delete_snapshots

I’ll say that if you are getting old snaps that you probably want to include a delay before the email sending, to allow the snapshots to finish taking

1 Like

I believe so too,

You try to send the mail too early, if you look at script that @juan11perez linked to I have an 10 second delay between taking the picture and sending it and the same goes for @ptdalen and his automation. He also have an 10 second delay. I tried with a shorter time but then I got the same result as you that it sent old pictures instead.

Try to add an 10 seconds delay between the last picture and sending.