Wrapping notification text / adding line breaks (data_template)

I’m finding that my notification message text is not wrapping for display on the phone, meaning that some of the message is not displayed. This seems related to sending an image as part of the notification.

I’ve spent a fair amount of time this afternoon trying to use line breaks to workaround the issue however I’m clearly missing something as I cannot find a way to make this work with data_template.

The automation I’m working with uses this notification action block:

    - service: notify.mobile_app_turk
      data_template:
        title: "Driveway Alert"
        message: >
               Driveway camera motion detected at {{ as_timestamp(state_attr('camera.driveway', 'last_tripped_time')) | timestamp_custom('%H:%M') }}.
               Score: {{ state_attr('binary_sensor.unifiprotect_motion_driveway', 'event_score') }}.
               {% set time = ((as_timestamp(now()) - as_timestamp(state_attr('camera.driveway', 'last_tripped_time'))) | int) - 5  %}
               {% set mins = ((time % 3600) / 60) | int %}
               {% set secs = time - (mins * 60) %}
               {% if time < 60 %}Length: {{ secs }}s 
               {% else %}Length: {{ mins }}m {{ secs }}s
               {% endif %}
        data:
          image: "{{ states('sensor.snapshot_remote') }}driveway_motion.jpg"
          actions:
            - action: "URI"
              title: "View Live Feed"
              uri: "/lovelace/camera_driveway"

What I’ve tried:

  • message: | : no difference in the resulting notification text
  • Using {{- ‘\n’ -}} to denote line breaks - works without using data_template, not with.
  • Using a quoted message block with multiple line spacing to donate new line.

Does anyone have a definitive tried and true method for formatting the network message?

According to the PR that implemented the expandable notification this is an android issue when an image is attached.

https://github.com/home-assistant/android/pull/393#issuecomment-585394476

https://developer.android.com/training/notify-user/expanded#large-style

If you take out the image it will load as expected. You will want to consider shortening your message for it to appear properly with an image.

1 Like

Nice to have confirmation of my suspicions, thank you @dshokouhi.

I’ve shortened the notification which will have to do I guess (pending a smarter way of doing it).