gadgetchnnel / lovelace-card-templater

Custom Lovelace card which allows Jinja2 templates to be applied to other cards
121 stars 6 forks source link

Template that should return a string is returning as '[object Object]': null #47

Closed WERUreo closed 2 years ago

WERUreo commented 2 years ago

I made a RESTful sensor that gets the url for NASA's Astronomy Picture of the Day and was hoping to use a template to use that sensor's state as the image. I set up my card like this:

type: custom:card-templater
card:
  type: picture
  image_template: {{ states.sensor.nasa_apod.state }}
entities:
  - sensor.nasa_apod

After I save it and go back to edit the card, my template has been replaced with '[object Object]': null. I've tested the template and it returns the correct string.

gadgetchnnel commented 2 years ago

You need to eiother wrap the template in quotes, like:

type: custom:card-templater
card:
  type: picture
  image_template: '{{ states.sensor.nasa_apod.state }}'
entities:
  - sensor.nasa_apod

or use one of the YAML multi-line operators (aka "block scalar headers") like >- like this:

type: custom:card-templater
card:
  type: picture
  image_template: >-
    {{ states.sensor.nasa_apod.state }}
entities:
  - sensor.nasa_apod
WERUreo commented 2 years ago

oh man, rookie mistake. thanks for the insight!