Sensor attribute in push notification image url

Hi there,

I’m having trouble with setting up push notifications which send an image using information from a sensor attribute in the url.

It’s for a image based off a camera event so the image event ID needs to be passed into the url so that the correct image is picked up.

Here’s my automation which doesn’t work;

data:
  image: >-
    http://domain.com/?view=image&eid={{state_attr('sensor.front_garden_alerts',
    'eventid')}}&fid=objdetect
message: 'Motion Detected {{state_attr(''sensor.front_garden_alerts'', ''name'')}}'
title: Motion Detected

No the odd thing is, the message section comes through ok, the attribute is resolved correctly and I get the camera info.
Also, If I change the attribute info in the url to a static eventID I get the picture through with the message.
Also, also, in the developer template if I copy my url there with the sensor attribute in, it resolves correctly and give me the correct url which when I visit, gives me the camera image.

So a lot of things are working as they should be, but I get no image when I have the sensor attribute to resolve the eventID in the url. I don’t get any errors in the logs either.

Anyone done something similar and worked around this?

Thanks for the help!
Jon

You need to change “data” with “data_template” if you want to use templates. Otherwise, the template looks good to me.

ah, sorry. I should have been clearer, here’s my full yaml, I was already using data_template:
Seems fine in the developer window, just not in practise;

data_template:
  data:
    image: >-
      http://mydomain/?view=image&eid={{state_attr('sensor.front_garden_alerts',
      'eventid')}}&fid=objdetect
  message: 'Motion Detected {{state_attr(''sensor.front_garden_alerts'', ''name'')}}'
  title: Motion Detected
service: notify.mobile_app_clt_l09

I see. What push notification service are you using? I’ll assume it’s the Android official app (google tells me clt_109 might be a Huawei phone)

Yes that’s right, HA official app on a Huawei p20 pro.
Swapping that sensor attribute in the URL for a static value works great for the image.
The message always works with the attribute though

Is this actually 2 lines in your config? Or an artifact from copy/paste?

    image: >-
      http://mydomain/?view=image&eid={{state_attr('sensor.front_garden_alerts',
      'eventid')}}&fid=objdetect

If it is 2 lines, make it one.

    image: >-
      http://mydomain/?view=image&eid={{state_attr('sensor.front_garden_alerts', 'eventid')}}&fid=objdetect

I’m having no problems with images and templates.

      data_template:
        title: test
        message: "{{ state_attr('vacuum.sir_robie_v', 'status') }}"
        data:
          image: >-
            {% set part="logo-round-192x192.png" %}
            https://github.com/home-assistant/home-assistant-assets/blob/1ee81ec321f1e5f7fcd0f0c844ba59ad7ab0a56b/{{part}}?raw=true

This had really got me stuck, just couldn’t figure out why it wasn’t working.

But, I was editing the YAML in the UI and it all looked fine but when I checked the automations.yaml file it actually wasn’t saving any of my changes!
Used a text editor to make the changes and it worked straight away.

Thanks for the help!