lovelace-mushroom
lovelace-mushroom copied to clipboard
[Bug]: HA State Object (state.state / etc.) not working in Template Card
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:
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
- Edit Dashboard
- Add new Mushroom-Template-Card
- Set Entity Parameter to any available Entity
- Enter the following in Primary or Secondary Information:
{{ state.state }}
- 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/
You can try with :
type: custom:mushroom-template-card
primary: '{{ entity. friendly_name }}'
secondary: '{{ entity.state }}'
entity: zone.home
Does not seem to work.
Now on HA Core 2022.9.0 (container)
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
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.
Is this documented somewhere and i just overlooked it? If it isnt, then where should it be documented?
Thank you very much!
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