MelleD / lovelace-expander-card

Expander card for HomeAssistant
Apache License 2.0
56 stars 6 forks source link

Possible to template "expanded" state? #212

Closed jabronimus closed 1 day ago

jabronimus commented 2 months ago

This is a great card, so thank you for making this!

The feature I would like is the ability to "template" the "expanded" state. As an example, instead of expanded: true or expanded: false, I would like to be able to do something like the following:

expanded: |
  {% if states('input_boolean.washing_machine_running') == 'on' %}
    true
  {% else %}
    false
  {% endif %}
MelleD commented 2 months ago

This is exactly what is currently not possible and for this you would have to control the HA backend. A good place to start could be the mushroom card. That's where it was implemented.

If anyone has experience with this, I would be happy if someone could contribute this feature.

Maybe it is also possible to set the status via card mod. Haven't tried it myself yet.

jabronimus commented 2 months ago

Yeah, I mean I could use a conditional card, duplicate the expander card info with one version being "expanded: true" and one version being "expanded: false", and set the conditions in the conditional card ... but that's like ... a LOT of work.

A decluttering template might also be an option.

MelleD commented 2 months ago

but that's like ... a LOT of work.

It depends, i'am using the YAML Mode in HA for my UI. There you can move the the complete expander card into one file and then just reuse it in your conditional card with !include. I do this a lot to have only one single place when I have cards in more than one places in my UI.

e.g.

      - type: conditional
        condtions:
          - condition: state
            entity: sensor.waschmaschine
            state: "on"
        card: 
          - type: custom:expander-card
            expanded: true
            cards: !include my-expander.yaml
      - type: conditional
        condtions:
          - condition: state
            entity: sensor.waschmaschine
            state: "off"
        card: 
          - type: custom:expander-card
            expanded: false
            cards: !include my-expander.yaml
jabronimus commented 1 day ago

That's what i ended up doing, so i'm going to consider this closed

MelleD commented 1 day ago

From my point of view it can remain open, the feature definitely makes sense to offer template support :)