Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possible to template "expanded" state? #212

Open
jabronimus opened this issue Jul 21, 2024 · 8 comments
Open

Possible to template "expanded" state? #212

jabronimus opened this issue Jul 21, 2024 · 8 comments

Comments

@jabronimus
Copy link

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
Copy link
Owner

MelleD commented Jul 21, 2024

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
Copy link
Author

jabronimus commented Jul 21, 2024

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
Copy link
Owner

MelleD commented Jul 23, 2024

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
Copy link
Author

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

@MelleD
Copy link
Owner

MelleD commented Oct 2, 2024

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

@MelleD MelleD reopened this Oct 6, 2024
@rodehoed
Copy link

Hi all. And especially @MelleD , the include trick. Can this be used to change the background color of the expand card too based on a sensors state too?

And btw great work! I think it should be include in HA by default, such a handy and space saving function!

@MelleD
Copy link
Owner

MelleD commented Oct 14, 2024

Yes why not you can create 2 cards with different background and check with conditional which you would like to show.
Or you try card mod https://github.com/MelleD/lovelace-expander-card?tab=readme-ov-file#card-mod

@mdagbro
Copy link

mdagbro commented Nov 22, 2024

Hi! I was looking for this feature too to automatically expand the room I'm in.

I understand having a template may be impossible for now.. But how about tying it to a binary_sensor? Would that be possible? Then we could create helper sensors with templates (or use existing sensors)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants