lovelace-mushroom icon indicating copy to clipboard operation
lovelace-mushroom copied to clipboard

[Bug]: Template chips card cannot return 0 when Jinja templating

Open JesseWebDotCom opened this issue 2 years ago • 2 comments

Current Behavior

In the content field, you cannot return a 0 when Jinja templating but you can with any other number:

- type: custom:mushroom-chips-card
  chips:
    - type: template
      entity: sensor.master_bedroom_lights_on
      content: |
        {{ 0 }}
    - type: template
      entity: sensor.master_bedroom_lights_on
      content: |
        {{ '0' }}
    - type: template
      entity: sensor.master_bedroom_lights_on
      content: |
        {% if 1==1 %}
          0
        {% else %}
          0
        {% endif %}

The code above does not return the expected number (0). It doesn't return at all.

Expected Behavior

I expect the number 0 to be returned. Run the code in the current behavior section but replace "0" with any number and it will return correctly.

Steps To Reproduce

Run the code in the current behavior section and nothing will return.

Environment

Version	core-2022.5.3
Docker	true
Python Version	3.9.5
Operating System Family	Linux
Operating System Version	5.13.0-39-generic
CPU Architecture	x86_64

Anything else?

No response

JesseWebDotCom avatar May 22 '22 03:05 JesseWebDotCom

As a work around (instead of using the letter O), you can use single braces: {0}

JesseWebDotCom avatar May 22 '22 14:05 JesseWebDotCom

This is true for a lot of fields, and probably due to the fact that 0 is falsey in JS.

KTibow avatar Jul 01 '22 23:07 KTibow