Help with notification attachments in an automation

I am unable to configure the the snapshot image and show it in the notification on my android with using the media_source as source. It was working using the www folder, but saw in the documentation that media_source is recommended (I also like having the snapshot in the media browser inside HA.).

what am i doing wrong? any help would be appreciated. thank you!

Here is my config:

alias: AI Detect - Delivery
description: ""
triggers:
  - type: turned_on
    device_id: ecd294118f7c02e4666772cff6193335
    entity_id: ab9a5682ec6988623d56248f1c0f2ec4
    domain: binary_sensor
    trigger: device
conditions:
  - condition: sun
    before: sunset
    after: sunrise
actions:
  - action: camera.snapshot
    metadata: {}
    data:
      filename: /media/snapshot-delivery-front-left.jpg
    target:
      entity_id:
        - camera.rlc_frontleft_fluent
    enabled: true
  - action: ai_task.generate_data
    metadata: {}
    data:
      task_name: Analyze the image
      instructions: >-
        Analyze the image for the following two conditions:


        Is there a white van located in the image (only interested in white
        vans?

        Is there a person present anywhere in the image?


        If, and only if, both of these conditions are definitively true, respond
        with a short confirmation sentence and include True in double curly
        braces at the end of the response. Otherwise, respond with False in
        double curly braces at the end of the response.
      attachments:
        media_content_id: media-source://media_source/local/snapshot-delivery-front-left.jpg
        media_content_type: image/jpeg
        metadata:
          title: snapshot-delivery-front-left.jpg
          thumbnail: null
          media_class: image
          children_media_class: null
          navigateIds:
            - {}
            - media_content_type: app
              media_content_id: media-source://media_source
    response_variable: response
  - if:
      - condition: template
        value_template: "{{ '{{True}}' in response.data }}"
    then:
      - action: notify.mobile_app_pixel_6a
        metadata: {}
        data:
          data:
            image: >-
              media-source://media_source/local/snapshot-delivery-front-left.jpg?{{now().timestamp()
              }}
            entity_id: camera.rlc_frontleft_fluent
            actions:
              - action: URI
                title: Open stream
                uri: /lovelace/nvr
          title: Probably a delivery detected
          message: test
  - delay:
      hours: 0
      minutes: 5
      seconds: 0
      milliseconds: 0
mode: single

I had similar with something I was doing and I had to enter this line into my configuration.yaml
Note if you already have the ‘homeassitant’ there already you don’t need that line.

homeassistant:
  allowlist_external_dirs: 
    - /media

Thank you @Steveuk

I managed to correct the config. Realising that the image takes a normal path not a media-source:// url. So the correct way to point to the file saved in local media is /media/local/yourfile.jpg and then it works just fine.

I was confused by the media-source since the AI task has this. my bad!

      - action: notify.mobile_app_pixel_6a
        metadata: {}
        data:
          data:
            image: /media/local/snapshot-front-left.jpg?{{now().timestamp()}}
            entity_id: camera.rlc_frontleft_fluent
            actions:
              - action: URI
                title: Open stream
                uri: /lovelace/nvr
          title: Probably a delivery detected
          message: "{{ response.data }}"
1 Like

Least you got it working.
I was doing a similar automation with ai and my cameras but it was taking so long.
Every time I tested it and went in my garden when the notification came through with the description I read never in frame.
But I think that’s because I was relying on Hikvisions line crossing to detect someone there and then by the time it was a snapshot it was to late :smile:

yeah, happens for me too. Also the delay between trigger and notification is sometimes half an hour for me. Haven’t investigated yet why this happens.

1 Like