HTML5 Notifications with template images

Hi ! I’m trying to send a notification with a local image, whose path is based on a template.
This is the script I use :

notify:
  alias: Notification with template image
  sequence:
  - data:
      data:
        data_template:
          image: "local/inside_{{ as_timestamp(states.automation.alarm_motion_trigger.attributes.last_triggered) | timestamp_custom('%Y-%m-%d_%H-%M-%S') }}.jpg"
      message: "local/inside_{{ as_timestamp(states.automation.alarm_motion_trigger.attributes.last_triggered) | timestamp_custom('%Y-%m-%d_%H-%M-%S') }}.jpg"
      title: Test 1 !
    service: notify.notify_rn5
  - data:
      data:
        image: "local/inside_2019-04-15_10-32-04.jpg"
      message: "local/inside_2019-04-15_10-32-04.jpg"
      title: Test 2 !
    service: notify.notify_rn5

On the above example, Test 1 sends the notification without the image while Test 2 sends the picture without any problem. Pathes seem to be resolved correctly.

What mistake did I make ?

Thank you.

What happens if you try this:

  sequence:
  - data_template:
      data:
        data:
          image: "local/inside_{{ as_timestamp(states.automation.alarm_motion_trigger.attributes.last_triggered) | timestamp_custom('%Y-%m-%d_%H-%M-%S') }}.jpg"
      message: "local/inside_{{ as_timestamp(states.automation.alarm_motion_trigger.attributes.last_triggered) | timestamp_custom('%Y-%m-%d_%H-%M-%S') }}.jpg"
      title: Test 1 !
    service: notify.notify_rn5
1 Like

Unfortunately, the notification arrives without image…

Do you get the template text in the message?

Yes, I do.

But the “message” is always correct, even outside the “data_template” (see my screenshot).

You put me on the right track ! It’s working as expected now.

notify:
  alias: Notification with template image
  sequence:
  - data_template:
      data:
        image: "local/inside_{{ as_timestamp(states.automation.alarm_motion_trigger.attributes.last_triggered) | timestamp_custom('%Y-%m-%d_%H-%M-%S') }}.jpg"
      message: Finally
    service: notify.notify_rn5

Thanks

1 Like

Hi 2t0m,

I am trying to create an automation similar to yours. I’d like to take a “camera.snapshot” of my “entity_id: camera.generic_camera” with an individual timestamp of the last tripped time of my “states.binary_sensor.cctv_01_line_crossing”

I’d then like to include this image with my HTML5 notification “notify.google_notify_pixel3”

This is what I have so far…

  action:
  - data:
      entity_id: camera.generic_camera
      filename: /config/www/alerts/front_door_alert_{{ as_timestamp(states.binary_sensor.cctv_01_line_crossing.attributes.last_tripped_time)
        | timestamp_custom('%Y-%m-%d_%H-%M-%S') }}.jpg
    service: camera.snapshot
  - data:
      data:
        image: /config/www/alerts/front_door_alert_{{ as_timestamp(states.binary_sensor.cctv_01_line_crossing.attributes.last_tripped_time)  |
          timestamp_custom('%Y-%m-%d_%H-%M-%S') }}.jpg
      message: Someone is at the front door
      target: Pixel3
    service: notify.google_notify_pixel3

When I manually trigger the automation the camera snapshot image file is created in the desired location with filename “front_door_alert_2019-04-15_14-45-48.jpg”

The notification pops up on my phone without the image though?

If I use a static image “image: /config/www/alerts/front_door_alert.jpg” the notification includes the image file

I see, the image must be a URL not a relative path. Does anyone know how I can add an image to the notification using a wildcard or similar to populate the filename?

Look here:


and here:

  1. You need to use data_template instead of data in your line 7
  2. Your image path have to begin with local instead of /config/www in line 9

Let me know if it works.

Thanks for your reply. I have been doing a bit of reading and am starting to understand the basics of data vs data_tempate

I found another thread HTML5 Push Notifications Data_Template Images which was also useful.

I decided I didn’t need to keep or timestamp each snapshot for archiving. My BlueIris install already records camera footage.

I added ?{{now().second}} to the url of my snapshot to stop the phone caching the image.

It is now working great. When my automation is triggered the first action runs the camera snapshot service and then sends the image in the notification.

This is my code for anyone who is interested

  action:
  - data:
      entity_id: camera.cctv_01
      filename: /config/www/camera/front_door_alert.jpg
    service: camera.snapshot
  - data_template:
      message: "Someone is at the front door"
      target: Pixel
      data:
        image: "https://mydomain.duckdns.org/local/camera/front_door_alert.jpg?{{now().second}}"
        url: "https://mydomain.duckdns.org/local/camera/front_door_alert.jpg?{{now().second}}"
    service: notify.google_pixel

The URL is so I can tap the notification on my phone to view the image full screen. My next step is going to be to try and send notification with the image and link to open the live camera feed.

Hi, also had the cache issue, so I thought your tip would help me, and I also added this to the end of my http image string : ?{{now().second}}

So next automation, I had a new image, not the cache version… It was solved o thought… Until the next time, now I still see the same cached version,…

If I do the test manually in a browser , it’s showing me a non cached version… Any idea?

Otherwise I should go the unique filenaming way