the way i’d do the line breaks is to change the >- to | and format the text with the linebreaks where you want them:
alias: Notifications for AndroidTV - Media Player
description: ""
trigger:
- platform: state
entity_id:
- media_player.androidtv_2
from: null
to: playing
condition: []
action:
- service: notify.android_tv
data:
title: ""
message: |
SqueezeBox - {{ states('media_player.androidtv_2') }}
{{ state_attr('media_player.androidtv_2', 'media_content_type') }}
{{ state_attr('media_player.androidtv_2', 'media_title') }}
{{ state_attr('media_player.androidtv_2', 'media_content_id') }}
data:
duration: 30
position: top-right
fontsize: large
transparency: 25%
color: gray
interrupt: 0
icon:
url: >-
http://localhost:8123{{ state_attr('media_player.androidtv_2',
'entity_picture') }}
mode: single
yes, i believe duration can take a template pointing to whatever value you want. you said variable, but you don’t have one here. perhaps you meant attribute? do it like you have in the message.
thanks, but the literal line break doesn’t work for me. neither does double quote method (“1\n2\n3”); it actually converted it to |-. the values in message from state_attr stay on same line. and, yes duration works with variable value from state_attr. am i missing something? new to yaml…
alias: Notifications for AndroidTV - Media Player
description: ""
trigger:
- platform: state
entity_id:
- media_player.androidtv
from: null
to: playing
condition: []
action:
- service: notify.androidtv
data:
title: "{{ state_attr('media_player.androidtv', 'friendly_name') }}"
message: |
{{ state_attr('media_player.androidtv', 'media_title') }}
{{ state_attr('media_player.androidtv', 'media_artist') }}
{{ state_attr('media_player.androidtv', 'media_album_name') }}
data:
duration: "{{ state_attr('media_player.androidtv', 'media_duration') }}"
position: top-right
fontsize: large
transparency: 25%
color: black
interrupt: 0
icon:
url: >-
http://{{ states('sensor.local_ip') }}:8123{{
state_attr('media_player.androidtv', 'entity_picture') }}
mode: single
Using | sends the line breaks. however I suspect your TV is then discarding it for space. I have seen that before. if that’s the case, then I don’t know that there is much you can do
Ok. ill look into it more. i also just noticed that it does not fire if attr doesnt exist; internet radio may not provide artist or album. need to add condition, but how do i say if attribute exist (without specifying value) ?
Ok, i figured it out. this will fire different notifications depending on if they are streams with no artist, album, and duration info. just got to figure out the line break issue.
It all depends on how the characters are interpreted (and not stripped).
I use these in many HTML displays like in flex-table and such to get another line when I want it.
Those above are CR, you might also try LF (linefeed) and a combination like CR LF.
Meaning what HTML tags do work? Can we format each line differently?
I guess so … because this just worked on my Android tablet:
service: notify.mobile_app_tab1
data:
message: >-
{{"This is a message <br> with other <br> stuff.<br>Oh look, multiple
lines! and now a heading? <h4>WOW a Heading</h4>"}}
it is what it is, not a big deal. i have more important issues than this. like trying to figure out how (or if possible) to interrupt current notification, which has duration set by media_duration attribute, when skipping tracks. the automation works fine if you dont skip track; triggered by state changing to playing and when media_content_id changes. but this may be a notifications for android tv app issue, dont see any settings to allow new notifications to interrupt / replace current.
duh, it was in front of my face the whole time - interrupt: 1
spoke to soon not working with notifications for android tv
and yes im missing the icon or image on standard notifications