Notify automation with "variables" does not remember the content

I have an automation triggered by an event doing AI on video images and then triggers a HTML5 notification. Just to test the new automation editor I have been trying to use it when developing this automation. The problem is that I want to attach an image to the notification and the image file name changes for each trigger. Therefor I am trying to find the image file name through the trigger.event and then feed that result into the url: and image: parts of the data:. When I put this into the message: part it shows up correctly, but not in the data. Does it loose the “variable” when it moves from message: to data:? Is there some way I can do this?

Here is my automation:

- id: '1601385011168'
  alias: Person Detected
  description: ''
  trigger:
  - platform: event
    event_type: deepstack.object_detected
  condition: []
  action:
  - service: notify.html5_stians_mobil
    data:
      title: Person detected!
      message: '{% set time = trigger.event.time_fired %}
                {% set timestamp_custom = as_timestamp(time) | timestamp_custom("%Y-%m-%d_%H-%M-%S") %}
                {% set entity_id = trigger.event.data.entity_id | regex_findall_index("\.(.*)") %}
                {% set url = ''/local/snapshots/'' + entity_id + ''_'' + timestamp_custom + ''.jpg'' %}
                This works: {{ url }}'
      data:
        url: '{{ url }}'
        image: '{{ url }}'
  mode: single

Herer is a screenshot of the same:

The URL shows fine in the message part but not in the url or image parts of the data tag. Do I have to repeat the code for each tag? Does anyone have any tips for meg on this? I have tried to remove the ’ ', replace them with " " etc, but nothing seems to work. For me it looks like it just loose the content of the set variable between the data tags …

Since recently this was the only option, becasue the variable only exists inside the template for one field.
However in 0.115 variables got introduced, take a look here.

1 Like

Thanks @Burningstone, I will check this out! :slight_smile:

Just for completeness, I got the automation working!

- id: '1601385011168'
  alias: Person Detected
  description: ''
  trigger:
    platform: event
    event_type: deepstack.object_detected
  variables:
    url: >     
        {% set time = trigger.event.time_fired %}
        {% set timestamp_custom = as_timestamp(time) | timestamp_custom("%Y-%m-%d_%H-%M-%S") %}
        {% set entity_id = trigger.event.data.entity_id | regex_findall_index("\.(.*)") %}
        {{ "/local/snapshots/" + entity_id + "_" + timestamp_custom + ".jpg" }}
  action:
    - service: notify.html5_stians_mobil
      data:
        title: Person oppdaget!
        message: En {{ trigger.event.data.name }} er oppdaget med {{ trigger.event.data.confidence }} sikkerhet 
        data:
          url: '{{ url }}'
          image: '{{ url }}'

Thanks for the support!

1 Like