Android notification with line breaks

I am trying to get a multi-line notification on my Android Home Assistant app. I can not do it. I have tried all sorts of variants of {{- ‘\n’ -}} - but without luck. Is this possible to do? Here’s my automation notification I want to separate into multiple lines:

# Morning Message ##

- alias: morning_message
  trigger:
    - platform: time
      at: '07:00:00'
  action:
    service: notify.mobile_app_my_mobile
    data_template:
      title: "Good Morning!"
      message: "Temperatures:
                Living Room: {{states.sensor.living_room_temperature.state}} °C
                Kitchen: {{states.sensor.kitchen_temperature.state}} °C
                Office: {{states.sensor.office_temperature.state}} °C"

Any ideas?

It’s to do with the way that whitespace is handled, it’s the same in markdown. Try adding an extra line between each one…

# Morning Message ##

- alias: morning_message
  trigger:
    - platform: time
      at: '07:00:00'
  action:
    service: notify.mobile_app_my_mobile
    data_template:
      title: "Good Morning!"
      message: "Temperatures:

                Living Room: {{states.sensor.living_room_temperature.state}} °C

                Kitchen: {{states.sensor.kitchen_temperature.state}} °C

                Office: {{states.sensor.office_temperature.state}} °C"

I just tried it, but it doesn’t seem to change anything. Whitespace seems to be ignored?

It’s not that it’s ignored, it’s removed for convenience for display.

It’s the same with pretty much all the messaging platforms/notifications. If you go to WhatsApp and type

L

I

N

E

R

E

A

K

S

And send it to someone, both their notification and the ‘last message’ displayed in your list of conversations will appear as

L I N E B R E A K S

But it will appear as you typed it in the actual conversation itself.

It’s just kinda the way it is. I don’t think it’s a limitation specifically of android/ios, but it’s probably a limitation of Firebase Cloud Messaging.

Ah I see, thanks for the explanation, I guess I’ll have to dismiss this type of formatting for notifications.

1 Like

Have you tried HTML formatting?

message: "Temperatures:<br>
                Living Room: {{states.sensor.living_room_temperature.state}} °C<br>
                Kitchen: {{states.sensor.kitchen_temperature.state}} °C<br>
                Office: {{states.sensor.office_temperature.state}} °C"<br>

One problem may be the notification style in Android itself. You may need to expand the notification in order to see the styling.

2 Likes

Hey, that actually worked, I just have to pull down the notification to see all of it and then it has line breaks! Thanks!