thomasloven / lovelace-template-entity-row

🔹 Display whatever you want in an entities card row.
MIT License
210 stars 16 forks source link

Unknown error when using this with auto-entities #32

Closed ghost closed 3 years ago

ghost commented 3 years ago

I have a really strange issue. I have a new HA install on a Raspberry Pi 4. I've added the latest version of these through HACS:

Configuration (anniversaries):

anniversaries:
  sensors:
  - name: Person A
    date: '1980-12-01'
    icon_today: mdi:party-popper

I then try to filter all of the entities and create the card. My goal is to make a list of birthdays that show a sorted list with the age and birthday.

type: custom:auto-entities
card:
  type: entities
  title: Birthdays
  show_header_toggle: false
filter:
  include:
    - entity_id: sensor.anniversary*
      state: < 120
      sort:
        method: state
        numeric: true

That gives you something like this: image

Then I wanted to use "lovelace-template-entity-row" to override "29 days" to "Today/Tommorrow/29 days" depending on the number of days left and also add a secondary_info saying for example: "35 Years old (01.12.1980)".

However whenever I modify the code to something like this:

type: custom:auto-entities
card:
  type: entities
  title: Birthdays
  show_header_toggle: false
filter:
  include:
    - entity_id: sensor.anniversary*
      state: < 120
      options:
        type: custom:template-entity-row
        secondary: >-
          {% if is_state(entity, '0') %}
            {{ state_attr(entity, 'current_years') }} Years
          {% else %}
            {{ state_attr(entity, 'years_at_next_anniversary') }} Years
          {% endif %}
            ({{ as_timestamp(state_attr(entity, 'date')) | timestamp_custom('%d.%m.%Y') }})
      sort:
        method: state
        numeric: true

and hit "Refresh" in HA I get "Unknown error / Reload UI". Hitting F5 brings the cached and working page back... Any ideas on why I keep getting this error?

ghost commented 3 years ago

I'm mistaken. This is a issue with lovelace_gen

Here's a working example. Works in ui-lovelace.yaml, but once moved into its own yaml file it throws a "Unknown error". Doesn't matter what I do or use, once I add the custom:template-entity-row state or secondary code it crashes.

- type: custom:auto-entities
            show_empty: true
            card:
              title: Birthdays
              type: entities
              show_header_toggle: false
            sort:
              method: state
              numeric: true
            filter:
              include:
                - entity_id: "sensor.anniversary_*"
                  state: < 120
                  options:
                    type: custom:template-entity-row
                    state: >-
                      {% if is_state(config.entity, '0') %}
                        Today
                      {% elif is_state(config.entity, '1') %}
                        Tomorrow
                      {% else %}
                        {{ states(config.entity) }} Days
                      {% endif %}
                    secondary: >-
                      {% if is_state(config.entity, '0') %}
                        {{ state_attr(config.entity, 'current_years') }} Years
                      {% else %}
                        {{ state_attr(config.entity, 'years_at_next_anniversary') }} Years
                      {% endif %}
                        ({{ as_timestamp(state_attr(config.entity, 'date')) | timestamp_custom('%d.%m.%Y') }})
thomasloven commented 3 years ago

https://github.com/thomasloven/hass-lovelace_gen#what-if-i-want-jinja-in-my-lovelace-interface