gadgetchnnel / lovelace-home-feed-card

A custom Lovelace card for displaying a combination of persistent notifications, calendar events, and entities in the style of a feed.
266 stars 22 forks source link

content_template doesnt seem to render {{state}} #41

Closed jaburges closed 4 years ago

jaburges commented 4 years ago

Hi there, so i'm using content_template as per below. Note MQTT devices do not have a friendly_name so using name: in the card config.

- type: 'custom:home-feed-card'
  title: Home Feed
  compact_mode: on
  scrollbars_enabled: false
  max_item_count: 5
  entities:
    - entity: binary_sensor.living_room_motion_sensor
      name: Living Room 
      content_template: '{{state}} in the {{display_name}}'
      state_map:
        on: "Motion"
      exclude_states:
        - "off"

With the above I just get in the displayed, no state information. I have tried using customize.yaml in my configuration to add a friendly_name to these devices, but that doesnt work either. If I comment out content_template I get Living Room @ Detected as expected.

I very easily could be missing something, just doesnt seem to be rendering the templates.

gadgetchnnel commented 4 years ago

Can you try with the template as just '{{state}}' to see if it is the name that is causing the issue?

gadgetchnnel commented 4 years ago

@jaburges In addition to my suggestion above, is there a possibility that you are using a wrapper card around this card which could be doing Jinja2 templating?

If so, it be be mis-interpreting the content_template as an actual Jinja2 template and causing this issue.

A workaround for this would be to put it as:

content_template: '{% raw %}{{state}} in the {{display_name}}{% endraw %}'

That tells the templating engine that it should be treated as regular text and not a template.

jaburges commented 4 years ago

@gadgetchnnel thank you, that indeed was the issue, and your solution solved it!