Template dev different than card

Dear all,
I started to use Hassio about a year ago and I am very happy with the system.
I have added the DWD Deutscher Wetterdienst Warnungen and here is where I hit a wall.
I have a value template as follow:

  - platform: template
    sensors: 
      warnung_1:
        friendly_name: Warnung 1
        value_template: "{{ state_attr('sensor.wetterwarnung_em_1_current_warning_level', 'warning_1_headline') }}. Hinweis {{ state_attr('sensor.wetterwarnung_em_1_current_warning_level', 'warning_1_description') }} {{- '\n' -}} Anweisung {{ state_attr('sensor.wetterwarnung_em_1_current_warning_level', 'warning_1_instruction') }} {{- '\n' -}} GĂŒltig bis zum {{ states('sensor.wetter_warnung_1_ende') }}. Klicken auf unteres Element um mehr zu sehen!"

The above code in template-dev(editor) returns the correct results and shows the warning number 1 and a full text as I expected it to be.
However, when I use the sensor in a lovelace card it returns:
Warnung 1: Unbekannt (unknown)
If I click on the relevant sensor, all is good and it shows me the attributes correctly.
Can someone help me identifying my errors.
Home Assistant 0.93.1
Hassio in a docker container
Raspberry Pi 3+

The following errors are reported:
Error doing job: Task exception was never retrieved
17:17 core.py (ERROR) - message first occured at 17:02 and shows up 3 times
Unhandled exception

17:04 /usr/local/lib/python3.7/site-packages/aiohttp/web_protocol.py (ERROR) - message first occured at 17:03 and shows up 2 times
Error doing job: Fatal error on transport

17:04 /usr/local/lib/python3.7/site-packages/homeassistant/core.py (ERROR) - message first occured at 17:03 and shows up 3 times

The attributes I am using are mentioned by the sensor:
attribution: Data provided by DWD region_name: xxxx region_state: BW last_update: 2020-01-30T17:06:41+01:00
warning_count: 1
warning_1_name: SCHWERE STURMBÖEN
warning_1_level: 3
warning_1_type: 1
warning_1_headline: Amtliche WARNUNG vor SCHWEREN STURMBÖEN
warning_1_description: Es treten oberhalb 1000 m schwere Sturmböen mit Geschwindigkeiten zwischen 80 km/h (22m/s, 44kn, Bft 9) und 95 km/h (26m/s, 51kn, Bft 10) aus sĂŒdwestlicher Richtung auf. In exponierten Lagen muss mit orkanartigen Böen bis 105 km/h (29m/s, 56kn, Bft 11) gerechnet werden.
warning_1_instruction: ACHTUNG! Hinweis auf mögliche Gefahren: Vereinzelt können zum Beispiel BĂ€ume entwurzelt und DĂ€cher beschĂ€digt werden. Achten Sie besonders auf herabstĂŒrzende Äste, Dachziegel oder GegenstĂ€nde.
warning_1_start: 2020-01-30T16:00:00+01:00
warning_1_end: 2020-01-31T10:00:00+01:00
friendly_name: wetterwarnung em 1
Current Warning Level icon: mdi:close-octagon-outline

If I put in a manually created sensor only 1 attribute, it seems to work.

Any help greatly appreciated.
Dietger

State values are limited to 255 characters only. Any attempt to set it to a string with more than that many characters will cause an error. In my experience, the state value will be the last valid value. In this case, I would expect it to always be ‘unknown’ since it would never have a valid value.

Attributes have no character limit.

I didn’t count, but I’m pretty certain there are more than 255 characters there.

Also, attempting to preserve newlines in a state has never worked for me. The entire state will be a single line, no matter what you do.

If you want to show attributes on a lovelace card, you’ll have to use a custom card.

1 Like

Bummer,
you are right, I have counted and ended up with 429 characters.
Meanwhile I have bit by bit used the states attributes and it seems to me there is one of the attributes “warning_1_description” which might cause the issue, removing this one it displays everything all right.
I am going to try your suggestion with attributes card.
Thanks for that!
Dietger

Does “{{- ‘\n’ -}}” actually preserve the newlines in your state? Just curious.

Hi JIm,
the “{{- ‘\n’ -}}” doesn’t make any difference, so no new line here.
Cheers
Dietger

Not quite solved, so I leave this one open for now.
But I might have found a bug?

So, what I found is the following:
In the DWD weather attributes, if there is anything after the “warning_1_description:”
such as in the example before, it returns an error as described.
Also in cases where I templated the above as 1 single template.

Playing with the configuration I just had a warning where there was only the “warning_1_description” and nothing following, so no “warning_1_instruction” and then the description shows up. No error message created.

Might be helpful?
Dietger

Hey @dimafemabo, i commented the issue you created on github and don’t think it’s an issue. There’s also no ‘codeowner’ in the manifest.json of the componenet so there’s only a litlle chance that someone looks at it.

But you gave me the idea to show the warnings in a markdown card.
Here’s what i have:

  - type: markdown
    content: |
      {%- for warning in range(1, state_attr('sensor.dwd_weather_warnings_current_warning_level', 'warning_count') +1 ) -%}
      **{{ state_attr('sensor.dwd_weather_warnings_current_warning_level', 'warning_' ~ warning ~ '_headline') }}**
      **Level:** {{ state_attr('sensor.dwd_weather_warnings_current_warning_level', 'warning_' ~ warning ~ '_level') }}
      {{ state_attr('sensor.dwd_weather_warnings_current_warning_level', 'warning_' ~ warning ~ '_description') }}
      {%- if state_attr('sensor.dwd_weather_warnings_current_warning_level', 'warning_' ~ warning ~ '_instruction') -%}
      {{- '\n' -}}{{ state_attr('sensor.dwd_weather_warnings_current_warning_level', 'warning_' ~ warning ~ '_instruction') }}{{- '\n' -}}
      {% else %}
      {{- '\n' -}}
      {%- endif -%}
      **GĂŒltig bis:** {{ as_timestamp(state_attr('sensor.dwd_weather_warnings_current_warning_level', 'warning_' ~ warning ~ '_end')) | timestamp_custom('%d.%m.%Y %H:%M') }}{{- '\n' -}}{{- '\n' -}}
      {%- endfor -%}
      Zuletzt aktualisiert: {{ as_timestamp(state_attr('sensor.dwd_weather_warnings_current_warning_level', 'last_update')) | timestamp_custom('%d.%m.%Y %H:%M') }}

20200204_11:29:17_001
You need to edit the entity_id of your dwd sensor for it to work

Thanks Rainer,
I changed the sensor name and used what you provided.
I am banging my head against the wall here, because I seem to miss some important thing.
My card looks like below:

In the UI for the markdown card the other editor doesn’t accept the hyphen in front of type and so my code looks like this:

type: markdown
content: |
  {%- for warning in range(1,
  state_attr('sensor.wetterwarnung_em_1_current_warning_level', 'warning_count')
  +1 ) -%}
  **{{ state_attr('sensor.wetterwarnung_em_1_current_warning_level', 'warning_'
  ~ warning ~ '_headline') }}**
  **Level:** {{ state_attr('sensor.wetterwarnung_em_1_current_warning_level',
  'warning_' ~ warning ~ '_level') }}
  {{ state_attr('sensor.wetterwarnung_em_1_current_warning_level', 'warning_' ~
  warning ~ '_description') }}
  {%- if state_attr('sensor.wetterwarnung_em_1_current_warning_level',
  'warning_' ~ warning ~ '_instruction') -%}
  {{- '\n' -}}{{ state_attr('sensor.wetterwarnung_em_1_current_warning_level',
  'warning_' ~ warning ~ '_instruction') }}{{- '\n' -}}
  {% else %}
  {{- '\n' -}}
  {%- endif -%}
  **GĂŒltig bis:** {{
  as_timestamp(state_attr('sensor.wetterwarnung_em_1_current_warning_level',
  'warning_' ~ warning ~ '_end')) | timestamp_custom('%d.%m.%Y %H:%M') }}{{-
  '\n' -}}{{- '\n' -}}
  {%- endfor -%}
  Zuletzt aktualisiert: {{
  as_timestamp(state_attr('sensor.wetterwarnung_em_1_current_warning_level',
  'last_update')) | timestamp_custom('%d.%m.%Y %H:%M') }}

I am using the Lovelace frontend to generate the card and choose “markdown”, switched to the dev-template editor everything shows up perfectly.
Somehow it doesn’t pick up the template values from within the card.
Do I have to add things to the config yaml?

Many thanks for having a look at it, really appreciated!
Cheers

Strange, i’m not using the UI Editor for LL.
I think the linebreaks in your pasted code are the problem.
Maybe try to paste it in the Raw editor?

Tried it in my play HA with a region that has really fu
ing weather at the moment. :slightly_smiling_face:
You have to paste the code without the

type: markdown
content: |

in the UI markdown editor.

EDIT: region_name: Kreis Garmisch-Partenkirchen, if you need something to play with.

I assume that’s short for “kung fu 
 ing weather” ? :rofl:

1 Like

Thanks for all your effort,
I tried as you suggested,

  1. I checked is that I didn’t copy the - type: markdown and content: |: I didn’t
  2. So I tried the Frontend according to your pasted pic.
  3. Then I tried the raw editor and to my dismay, I got exactly the same results, whatever and whereever I tried.

It seems it just doesn’t pull the templated information there.

When I have a quiet moment I migth upgrade to the latest version, see if this solves the issue then.
Might take me a while to get this done.
Thanks so far.

:joy: :joy: I like that!

Which version are you on?

0.93.1
RasĂŒberry pi 3+
Docker container

Ouuch! Thats the problem i think.
Don’t know exactly when the markdown has become template support.

Found it:

Brilliant and many thanks!
I got a good reason to update, at least to version .99
See what effect it will have on my well established, working environment :wink:
Thanks for all your help, great job!

Upgraded now to the latest version and all works like a charm!
:blush: thanks to everyone here.
Dietger

1 Like