Camera snapshot to notification (ios app) not relaiable

Hi,

I have this automation which is supposed to sent a notification with an image upon detected motion
This only sometimes works, sadly most of the time the image is missing.

The image is locally available and works. The image is just missing in the notification.
Sometimes it’s works, so the automation is not completely failing :wink:

What might be the cause of this?

- id: camera_notificatie_beweging_voordeur
  alias: Stuur notificatie bij beweging voordeur
  trigger:
    platform: state
    entity_id: binary_sensor.camera_oprit_line_crossing
    to: 'on'
  action:
  - service: camera.snapshot
    data:
      entity_id: camera.oprit
      filename: /config/www/snapshots/motion_snapshot_{{ now ().year }}_{{ now ().month }}_{{ now ().day }}_{{ now ().hour }}_{{ now ().minute }}.jpg
  - service: notify.iedereen
    data_template:
      title: Beweging voordeur!
      message: Beweging voordeur om {{now().strftime("%H:%M op %d-%m-%Y")}}
      data:
        persistent: true
        tag: persistent
        push:
          sound: ready.mp3
        attachment:
          content-type: jpeg
          url: https://my_public.url:40443/local/snapshots/motion_snapshot_{{ now ().year }}_{{ now ().month }}_{{ now ().day }}_{{ now ().hour }}_{{ now ().minute }}.jpg

I can see at least two possible issues.

First, the camera.snapshot service may take longer than usual sometimes. You may need to add a delay between the two actions.

Second, and probably the real issue, the filename template is rendered twice. If the minute changes between the two then they two actions will use different file names.

I would suggest adding an initial action that sets (at least the last part of) the filename into an input_text. Then in the other two actions, use the value of the input_text to render the filename.

Thanks Phil! That did the trick.

I feel sooooooo stupid for not catching that one :wink:

For anyone who needs it, this one works :slight_smile:

input_text:
  motion_snapshot:
    name: Datum-tijd motion snapshot
    initial: empty
- id: camera_notificatie_beweging_voordeur
  alias: Stuur notificatie bij beweging voordeur
  trigger:
    platform: state
    entity_id: binary_sensor.camera_oprit_line_crossing
    to: 'on'
  action:
  - service: input_text.set_value
    data_template:
      entity_id: input_text.motion_snapshot
      value: "motion_snapshot_{{ now ().year }}_{{ now ().month }}_{{ now ().day }}_{{ now ().hour }}_{{ now ().minute }}.jpg"
  - service: camera.snapshot
    data:
      entity_id: camera.oprit
      filename: /config/www/snapshots/{{states.input_text.motion_snapshot.state}}
  - service: notify.iedereen
    data_template:
      title: Beweging voordeur!
      message: Beweging voordeur om {{now().strftime("%H:%M op %d-%m-%Y")}}
      data:
        persistent: true
        tag: persistent
        push:
          sound: ready.mp3
        attachment:
          content-type: jpeg
          url: https://my_public_url:40443/local/snapshots/{{states.input_text.motion_snapshot.state}}
2 Likes

Thanks a lot, but on Android I had to replace the following:

attachment:
  content-type: jpeg
  url: https://my_public_url:40443/local/snapshots/{{states.input_text.motion_snapshot.state}}

With:

image: https://my_public_url:40443/local/snapshots/{{states.input_text.motion_snapshot.state}}

And now it’s working smoothly…

Thanks again