Conditional card with > and < as conditions?

Is the a card anywhere that works like conditional but allows, for example,

is_state: >5

Let’s say I have a number of input_booleans all named something like my_boolean_1 up to my_boolean_8 and I have an input_number set to 6.

I want to only show the first six of those input_booleans.

The conditional card only matches state values, no other mathematical operation is available. Though it is an oft requested feature, e.g. Support numeric state for conditional card in Lovelace

Even if you had that you would still have to have 8 conditional cards for the logic you want using this card.

Right now the only way I can think of getting this logic is to make 8 template binary sensors that check if the input select is bigger than each of the integers 1 through 8. Then use those binary sensors in eight conditional cards to show or hide your input booleans.

1 Like

do you want just to see them or to be able to control them as well?

One of straightforward solutions might be an entity card with all your input_booleans modded with card-mod so they have display: none if their number is greater than your input_number.
Shouldn’t be too difficult to implement if I’m not missing something important :wink:

That’s actually quite clever.

My real-life use case for this is a bit more complicated than I described because I didn’t want to get into the nitty-gritty of my specifics here and decided a simple generic description would tell me if there was a ‘simple’ answer.

@AhmadK
Have I missed something? What is display: none?


For the record this is what my UI looks like.
I would like to restrict the number of rows shown based on the input_number

1 Like

it tells browser not to display an HTML element

1 Like

Oh!
Right. Thanks, that is something to play with!

Thank you! It might be a better way to do things than some other methods I’ve been using in other places too!

That should keep me busy for a few hours tomorrow.
Lucky I’m not going anywhere :slight_smile:

This is brilliant.
This one thing opens up a whole avenue of exploration. And yeah, I couldn’t wait until tomorrow.

I have now solved what I wanted to do in the OP so thanks for that, but I am now moving on through other things and for some reason I can’t make it work with a conditional card.

Before I ask in the proper place (i.e. the card_mod post) I thought I’d try here as you seem to know your way around this :wink:

This works if states('input_number.irrigation_number_of_zones') is 8 but if it isn’t or I use something in the form of >= 8 then I get the big red box. I wondered if it didn’t like there being no else but I put something mundane in there and it still failed. Any ideas? Thanks.

  - type: custom:mod-card
    style: |
      ha-card {
        {% raw %}
        {% set zone_count = states('input_number.irrigation_number_of_zones') %}
        {% if (zone_count | int) == 8 %}
          display: none
        {% endif %}
        {% endraw %}
      }
    card:
      type: conditional
      conditions:
         --- and so on

image

yeah. thanks Thomas’s card-mod, it’s a great tool :wink:

Regarding your question - I presume you want to add display: none only when you want to hide it, right?
There are several ways to try. One is to return empty string on else.
Another is to play with none alternatives - usually saying display: unset or inherited or initial means the same as no display: blah-blah at all, pass.
So it can be

- type: custom:mod-card
  style: >
    {% set zone_count = states('input_number.irrigation_number_of_zones') %}
    {% if (zone_count | int) == 8 %}
      ha-card {display: none}
    {% endif %}

or

- type: custom:mod-card
  style: >-
    ha-card {display:
    {% set zone_count = states('input_number.irrigation_number_of_zones') %}
    {% set val = 'none' if (zone_count | int) == 8 else 'unset' %}
    {{ ' {}'.format(val) }}
    }

I think that’s enough to begin with :wink:

p.s I wonder if {%raw%} in your code is copy/paste from somewhere. I’s not necessary as you can see.

1 Like

Thanks for the pointers, I’m going to have a play…
I’ll let you know how I get on.

And,

Yes it was :roll_eyes: (I’ve been using it elsewhere in combination with some lovelace_gen variables passed into an include).

I think you need to invest some time in finding out what happens when you write something like blah: | in yaml :wink:
But it’s not urgent.

Well I still can’t get it to work if the condition is false.
If the condition is true it hides it, but when false it throws an error.

I’ll take it to the card-mod post.
Thanks for your help…
(I’ll tag you so you see it easily and in case you’re interested in following or adding to it)

Guys can you look at this? And add opinion? https://github.com/home-assistant/frontend/pull/7381

1 Like