Lovelace: hide/show entities based on state of other entities, within a card

Trying to find a way to hide/show entities within a card based on the state of another entity.

Reading lovelace docs, I found entity-filter, a type of card. This card supports filtering of entities but it seems to only support filtering entities based on each entity’s own state, not on the state of other entities.

My use case is simple: I have a template switch that runs that enables one-off action and has a timer (input_datettime) that sets the time for the action to start. I want to hide the input_datettime if the template switch is off.

On the legacy UI, CustomUI supports templating the ‘hidden’ attribute of any entity. I was wondering whether to invest time/effort learning and deploying CustomUI or wait for the next-gen UI, hoping it bring the flexibility that the legacy UI was didn’t have.

If the feature does not exist in lovelace I can submit a feature request - thought I would ask the experts first

I can’t think of a way without a custom card.

This is coming in 0.75

1 Like

Is what OP asked for possible now? Can someone give a working example?

This is what I use it for:

I’ve implemented a “conditional entity” using a Conditional Card plus Custom:vertical-stack-in-card. This can hide or show an entity based on the state of a switch in the same “Card”.

It doesn’t look great - due to ‘vertical-stack-in-card’ adding quite a bit of deadspace, but at least it does the job.

Here’s the construct:

  - type: 'custom:vertical-stack-in-card'
    cards:
      - type: entities
        entities:
          - switch.espresso
          - switch.espresso_automatic_control
          - switch.espresso_override
      - type: conditional
        conditions:
          - entity: switch.espresso_override
            state: 'on'
        card:
          type: entities
          entities:
            - input_datetime.espresso_override_start
      - type: entities
        show_header_toggle: false
        entities:
          - sensor.kitchen_sink_water_detector

Here is how it looks like:

(switch off: extra entity hidden)

image

(switch on: extra entity shown)

image

Still hoping that when lovelace matures they will add a better (simpler and better looking) way to achieve this.

You should handle this differently. Make 2 cards, one without the overide time and one with. Make 2 condtional cards for each of them and you wont have whitespace.

      - type: conditional
        conditions:
          - entity: switch.espresso_override
            state: 'on'
        card:
          - type: 'custom:vertical-stack-in-card'
            cards:
              - type: entities
                entities:
                  - switch.espresso
                  - switch.espresso_automatic_control
                  - input_datetime.espresso_override_start
                  - switch.espresso_override
                  - sensor.kitchen_sink_water_detector
      - type: conditional
        conditions:
          - entity: switch.espresso_override
            state: 'off'
        card:
          - type: 'custom:vertical-stack-in-card'
            cards:
              - type: entities
                entities:
                  - switch.espresso
                  - switch.espresso_automatic_control
                  - switch.espresso_override
                  - sensor.kitchen_sink_water_detector

Very smart!
Thanks for the feedback. That will do the job better, will do the change.
Still hoping that in the future we will get support for conditional visibility of entities and cards so we can simplify configuration for this type of use cases.
Then that conditional visibility of cards/entities could also support ‘current_user’ / ‘current_user_not’ / ‘user_group’… but I digress :slight_smile:

Just to report the result: the idea worked very well, but I had to enclose both “on” and “off” conditional cards within a vertical-stack, otherwise turning on the switch would work but the updated card showed up in a different column of the dashboard for some reason.
Enclosing in a vertical stack gave the exact behavior I wanted.
Thanks @petro

1 Like

I have a similar situation, but want to be able independently hide two entities based on states of another two (two input_number and input_boolean respectively).
My understanding is that’s almost impossible with the approach proposed by @petro as I’ll need not two but 6 cards and I’m not quite sure how to juggle them.
Is there any other way to achieve the result?

Not quite. It’s very possible. You need 3 condition cards inside a vertical stack. Each condition is as follows:

condition1 condition2 card to display
input_boolean.1 on input_boolean.2 off input_number.1
input_boolean.1 off input_boolean.2 on input_number.2
input_boolean.1 on input_boolean.2 on input_number.1 and input_number.2

In fact, I use this already here

          - type: conditional
            conditions:
              - entity: switch.zone_1
                state: 'on'
              - entity: switch.zone_2
                state: 'on'
            card:
              type: entities
              entities:
                - entity: input_number.yamaha_receiver
                  name: Zone 1 Volume
                - entity: input_number.yamaha_receiver_zone_2
                  name: Zone 2 Volume
          - type: conditional
            conditions:
              - entity: switch.zone_1
                state: 'on'
              - entity: switch.zone_2
                state: 'off'
            card:
              type: entities
              entities:
                - entity: input_number.yamaha_receiver
                  name: Volume
          - type: conditional
            conditions:
              - entity: switch.zone_1
                state: 'off'
              - entity: switch.zone_2
                state: 'on'
            card:
              type: entities
              entities:
                - entity: input_number.yamaha_receiver_zone_2
                  name: Volume
1 Like

what a monster… 8()
I’ll give it a try, but it’s a very peculiar way of UI design with Lovelace… oh well

Update: in my case I have one permanent entity and it resulted in 4 conditional cards from off/off to on/on. And in all of them I had to disable heading toggle and define the very same title.
It works, but what an overhead… I wish it could be easier and more elegant…

And I doubt it is easy to hide an input_number in ONE of those conditional cards if its value is 0 (tried and failed, but I’m just learning) :wink:

On the other hand, I’m glad it works, let’s hope it will evolve further in the right direction.

I was looking to hide entities and found this thread.
I had better success with this card https://github.com/thomasloven/lovelace-auto-entities. Result is very nice and fairly simple to use!

type: 'custom:auto-entities'
show_empty: false
card:
  type: entities
  title: AC
  show_header_toggle: false
entities:
  - climate.heat_pump
  - input_boolean.heatpump_stop_timer
filter:
  template: >
    {%if is_state('input_boolean.heatpump_stop_timer','on')%}input_number.heatpump_on_time{%endif%}
    {%if is_state('input_boolean.heatpump_stop_timer','on')%}sensor.heatpump_time_left{%endif%}