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

[Bug]: HA State Object (state.state / etc.) not working in Template Card

Open RoepLuke opened this issue 2 years ago • 5 comments

Current Behavior

Configure a Template Card (via GUI or YAML) and setting the optional Entity Parameter. Then trying to use the Home Assistant State Object to make Templating simpler (not having to type out the entity_id every time, etc.) does not seem to work:

grafik

Maybe I'm just doing it wrong, but as far as I can see, it currently doesn't work.

Thank you!

Expected Behavior

Being able to use the State Object and its properties in the Template Card.

Steps To Reproduce

  1. Edit Dashboard
  2. Add new Mushroom-Template-Card
  3. Set Entity Parameter to any available Entity
  4. Enter the following in Primary or Secondary Information: {{ state.state }}
  5. Save the changes and take a look at the new Card on the Dashboard

Example configuration

type: custom:mushroom-template-card
primary: '{{ state.name }}'
secondary: '{{ state.state }}'
entity: zone.home

Environment

- OS: Raspbian 11 (bullseye)
- HA Core Version: 2022.8.6 (container)
- HA Frontend Version: 20220802.0 - latest
- Lovelace-Mushroom Version: v2.1.3 (via HACS)

Anything else?

State Object Documentation: https://www.home-assistant.io/docs/configuration/state_object

Templating Documentation: https://www.home-assistant.io/docs/configuration/templating/

RoepLuke avatar Sep 06 '22 18:09 RoepLuke

You can try with :

type: custom:mushroom-template-card
primary: '{{ entity. friendly_name }}'
secondary: '{{ entity.state }}'
entity: zone.home

piitaya avatar Sep 08 '22 12:09 piitaya

YAML Editor.png

Lovelace View Template Card.png

Does not seem to work.

Now on HA Core 2022.9.0 (container)

RoepLuke avatar Sep 08 '22 12:09 RoepLuke

Oops I suggested wrong code 😅 This one is good :

type: custom:mushroom-template-card
primary: '{{ state_attr(entity, "friendly_name") }}'
secondary: '{{ states(entity) }}'
entity: zone.home

piitaya avatar Sep 08 '22 12:09 piitaya

For some reason it wouldn't display the secondary information (current value = 0). I then changed it to "{{ states(entity) ~ ' Personen' }}" and then it is displayed.

Other than that it works flawlessly. Lovelace success.png

Is this documented somewhere and i just overlooked it? If it isnt, then where should it be documented?

Thank you very much!

RoepLuke avatar Sep 08 '22 13:09 RoepLuke

0 is considered as false by the template system so it doesn't render. I saw workaround for this issue but I can't find her anymore 😅

For templating the doc is here : https://www.home-assistant.io/docs/configuration/templating/ Mushroom expose two additional variables :

  • user (current logged user)
  • entity (defined in the entity field)

I agree, it should be in the template documentation 🙂 https://github.com/piitaya/lovelace-mushroom/blob/main/docs/cards/template.md

piitaya avatar Sep 08 '22 13:09 piitaya