Notification with action URL Dynamic

Hello, I’m trying to send a notification with an action when the login fails, but I’m not able to put the dynamic URL, my code is:

            - service: notify.daniel
              data_template:              
                  title: "🛡️ Tentativa de Login"
                  #{{ states.persistent_notification.http_login.attributes.message }} 
                  message: >
                    Tentativa em {{ now().strftime('%H:%m') }} 
                          IP: {{ states.persistent_notification.http_login.attributes.message.split("from ")[1] }}
                    https://ip-api.com/#{{ states.persistent_notification.http_login.attributes.message.split("from ")[1] }}
                  data:
                    actions:
                    - action: "URI"
                      title: "Informações do IP"
                      uri: https://ip-api.com/#{{ states.persistent_notification.http_login.attributes.message.split("from ")[1] }}

But when you open the link it will

  • https://ip-api.com/#{{ states.persistent_notification.http_login.attributes.message.split("from ")[1] }}

Dont replace {{ states.persistent_notification.http_login.attributes.message.split("from ")[1] }} with correct value!

Any help?

Thanks

wrap the uri in quotation marks because it is a single line template

uri: 'https://ip-api.com/#{{ states.persistent_notification.http_login.attributes.message.split("from ")[1] }}'

I am using single quotes here becuase you have double quotes inside the template.

Thanks Works :stuck_out_tongue:

When i try this to my android phone with a google maps uri i cant get it to work.
The template seems to translate fine in VScode, but when i click the link on my android phone it seems to have not translated the template.


(Screenshot from VScode)


(Screenshot from android phone)

can you show the full YAML example?

- id: 0024e98e-c7d4-4155-8929-cf107c2c088c
    alias: 'Notify on car move'
    trigger:
      platform: state
      entity_id: binary_sensor.car_motion
      from: "off"
      to: "on"
      for: 00:00:10
    condition:
      - condition: state
        entity_id: input_boolean.car_move
        state: "on"
    action:
      - service: notify.mobile_app_oneplus_a6013
        data:
          message: "Car started to move"
          title: "{{ as_timestamp(now()) | timestamp_custom('%H:%M:%S') }} Car is moving"
          data:
            ttl: 0
            priority: 'high'
            actions:
              - action: "URI"
                title: "Show Map"
                uri: 'https://www.google.com/maps/search/?api=1&query={{ states.device_tracker.bilen.attributes.latitude }},{{ states.device_tracker.bilen.attributes.longitude }}'

Try change to

- id: 0024e98e-c7d4-4155-8929-cf107c2c088c
    alias: 'Notify on car move'
    trigger:
      platform: state
      entity_id: binary_sensor.car_motion
      from: "off"
      to: "on"
      for: 00:00:10
    condition:
      - condition: state
        entity_id: input_boolean.car_move
        state: "on"
    action:
      - service: notify.mobile_app_oneplus_a6013
        data_template:
          message: "Car started to move"
          title: "{{ as_timestamp(now()) | timestamp_custom('%H:%M:%S') }} Car is moving"
          data:
            ttl: 0
            priority: 'high'
            actions:
              - action: "URI"
                title: "Show Map"
                uri: 'https://www.google.com/maps/search/?api=1&query={{ states.device_tracker.bilen.attributes.latitude }},{{ states.device_tracker.bilen.attributes.longitude }}'
2 Likes

Thanx, not the first time i missed that _template