i have a template that looks like this. is there a newline character or something that forces linebreaks between day_0 and day_1, etc.? as it is now, the lines just wrap and break according to polymer rules or whatever.
Bump, I would like to know too. I have a sonarr sensor for the day’s tv episodes and would like have a line break after each.
- platform: template
sensors:
tv_schedule:
value_template: >-
{% for attr in states.sensor.sonarr_upcoming.attributes %}
{% if not attr=="friendly_name" and not attr=="icon" and not attr=="unit_of_measurement" %}
{{attr}}
{%- endif %}
{%- endfor -%}
I’m also looking for this. Hopefully this message get the attention of someone who has already figured this out.
I found this page which I thought was the solution. Using {{ '\n' -}} where you want the line break does work in the dev tools template editor but it doesn’t seem to have an effect in an actual template sensor. Here is the sensor that I’m trying to use…
template_ha_version_display:
friendly_name: 'HA Version'
value_template: >-
{%- if states.sensor.current_installed_ha_version.state == states.sensor.current_release_ha_version.state -%}
- Up To Date -
{{- '\n' -}}
Version {{states.sensor.current_release_ha_version.state}}
{%- else -%}
Installed {{states.sensor.current_installed_ha_version.state}}
{{- '\n' -}}
Available {{states.sensor.current_release_ha_version.state}}
{%- endif -%}
Hrmm, trying to do the same, and as others have said, it seems to work in the template editor but not in the actual sensor.
Anyone come across new ideas?
- platform: template
sensors:
neweps:
value_template: >
{%- for attr in states.sensor.sonarr_upcoming.attributes -%}
{%- if not attr=="friendly_name" and not attr=="icon" and not attr=="unit_of_measurement" and not attr=="hidden" %}
{{attr}}:{{states.sensor.sonarr_upcoming.attributes[attr]}}
{{- '\n' -}}
{%- endif -%}
{%- endfor -%}
Does anyone find a solution?
I log some sensors states on a txt file but cannot achieve the new line.
As discussed aboce I’ve tried {- '\n' -} but it works only in the template.
I realize this is a little old, but I was looking for the same solution. In case others are looking:
This answer worked for me. Note that the dashes and spaces were literally rendered so if you don’t want extra spaces and the dashes, just use {{\n}}. Btw, I used this in an email message.
Possibly related: I created an automation which gets triggered by messages on a specific mqtt topic and sends “{{ trigger.payload }}” to the logbook. In the payload I can see formatting like “\n” and “\t” but these seem to get stripped out from the logbook messages.
I went to a lot of trouble to create nicely formatted status reports ! Is there no way to preserve these characters in logbook entries ?
Actually just now I have found a workaround, it is not perfect, but if you precede the first word of each line with something like “…” then the line gets broken before the dots and the word. It might work in the case of templates also. Just make sure not put enough dots to force a linebreak and not leave whitespace betweem the dots and the first word of the line.
So something like “line of text one …line of text two”
Edit: actually it is not very good. If you change the font size you lose the word wrap…