šŸ”¹ Card-mod - Add css styles to any lovelace card

Iā€™m aware. It cannot be implemented in the same way anymore. Iā€™ll try to come up with something more useful.

Thanks for letting me know that you can do this with the latest release. Is legacy syntax still supported?

Yes  

Works. thank you

ok this is driving me crazy.

I want to change the icon colour IF the version is not 2.4.2 OR the version is not shown as continuous

              - entity: sensor.artisan_software_version
                style: |
                  :host {
                  --paper-item-icon-color:
                    {% if (states(config.entity) != 'v2.4.2') or (states(config.entity) != 'continuous') %}
                      var(--state-icon-active-color)
                    {% else %}
                      var(--state-icon-color)
                    {% endif %}
                    ;
                  }

But it seems to be ignoring the OR part of the if statement.

What am I screwing up here?

(I also tried the OR part as an elif)

What does it show in the template tab of devtools?

you canā€™t use config.entity in dev-tools. I will try with the real entity name but it should be fine I thinkā€¦

dev-tools says:

UndefinedError: 'sensor' is undefined

however:

                style: |
                  :host {
                  --paper-item-icon-color:
                    {% if states(config.entity) != 'v2.4.2' %}
                      var(--state-icon-active-color)
                    {% elif states(config.entity) != 'continuous' %}
                      var(--state-icon-active-color)
                    {% else %}
                      var(--state-icon-color)
                    {% endif %}
                    ;
                  }

If I leave off the OR condition, it shows correctly in the dashboard too Lovelace)

image

the icon should NOT be yellow

also if I change the first part 2.4.2 to continuous it works correctly.

In devtools, quote the entity name with single quotes, what does it say then?

Interestingly, this works correctly

  - entity: sensor.artisan_software_version
    style: |
      :host {
      --paper-item-icon-color:
        {% if states(sensor.artisan_software_version) != 'v2.4.2' %}
          var(--state-icon-active-color)
        {% elif states(sensor.artisan_software_version) != 'continuous' %}
          var(--state-icon-active-color)
        {% else %}
          var(--state-icon-color)
        {% endif %}
        ;
      }

So this looks like a bug with config.entity?

1 Like

Nope, probably that itā€™s invalid Jinja and is resorting. Use single quotes for the entity. The template tab doesnā€™t have anything lovelace-specific, so config.entity doesnā€™t work in there.

Yeah of courseā€¦
{{ states(ā€˜sensor.artisan_software_versionā€™) }} shows continuous

and youā€™re right. that doesnā€™t actually work.

I just tried:

              - entity: sensor.artisan_software_version
                style: |
                  :host {
                  --paper-item-icon-color:
                    {% if states('sensor.artisan_software_version') != 'v2.4.2' %}
                      var(--state-icon-active-color)
                    {% elif states('sensor.artisan_software_version') != 'continuous' %}
                      var(--state-icon-active-color)
                    {% else %}
                      var(--state-icon-color)
                    {% endif %}
                    ;
                  }

and the icon is yellow which is the var(ā€“state-icon-active-color) which it should not be because the state IS continuous

Which means my original code should also workā€¦

Oh SHIT
Epic logic fail!!
the first condition is of course satisfied. DOH!!! So I need to change my OR to AND DOH!!!

2 Likes

IsnĀ“t it a lovely feeling when the hammer drops on you that you spent hours (in best case minutes) trying and failing in the wrong endā€‹:hammer::sparkles::see_no_evil:.
Happens plenty of times to me when working on HA :roll_eyes::grin:.

1 Like

Interesting, yes this works by going to another view and back again. Although interestingly enough the card height stays the same, so although it takes away the header, you end up with a lot of empty space then at the bottom of the card.

Is there any kind of JS event fired when the history card has loaded its stuff so that card-mod can force a re-render?

I look forward to your wiki articles about how all this works so I can understand whats going on.

You might be able to override cardHeight which is a card JS method for the layout engine.

With help of the wiki I was able to replace almost all functionality of the now deprecated CH module, except for hiding of the chevron buttons ( < and > ). I want them to never be visible, at all.

Does anyone have a snippet that would do that?

Look at all posts on the thread dedicated for card-mod theming by me, somewhere I posted that.

1 Like

Seeing how powerull card mod is, I wonder if itā€™s possible use card mod to make sure a card is sticky as a footer. I have it working with button cards inside a horizontal-stack as a sticky header (that stays in place when scrolling).

I use this code to create a card that is sticky at the top (courtesy of Jimmy)

            style: |
              ha-card {
                --ha-card-background: transparant;
                background: var(--primary-color);
                border-radius: 0px !important;
              }            
              .card-content {
                padding: 0
              }
              :host {
                z-index: 999;
                position: sticky;
                position: -webkit-sticky;
                top: 0;
              }

One would think a reverse should be possible too, to have one at the bottom of the screen always in place?

1 Like

Forgive me my novice question. Is it possible with card-mod to completely hide the sidebar? Iā€™m trying to substitute the CH somehow. There is a div named "contentContainer" outside <partial-panel-resolver> which should be hidden.