thomasloven / lovelace-card-mod

🔹 Add CSS styles to (almost) any lovelace card
MIT License
1.04k stars 169 forks source link

Conditional Update Bug #358

Closed petrij98 closed 4 months ago

petrij98 commented 4 months ago

My Home Assistant version: 0.11.5

My lovelace configuration method (GUI or yaml): yaml

What I am doing: Creating custom animations utilizing mushroom cards. I've programmed the animations to change color based on an RGB bulb's current color.

What I expected to happen: The animation to change color based on the color of the RGB bulb.

What happened instead: The animation will change based on the color of the bulb and will even update if the bulb color is changed from the card. However, there are a number of weird errors created as a result. The two most noticeable is that the background color I set for the icon shape no longer stays applied and the animation won't stop after the light is turned off.

Minimal steps to reproduce:

card_mod:
              style:
                mushroom-shape-icon$: |
                  .shape {
                    background: black !important;
                    {% set light_state = states(config.entity) %}
                    {% if light_state == 'on' %}
                      --shape-animation: ping 2s infinite; 
                    {% else %}
                    {% endif %}
                  }
                  @keyframes ping {
                    0% {box-shadow: 0 0 0 0 rgba({{state_attr(config.entity,'rgb_color') | join(', ')}}, 0.7);}
                    70% {box-shadow: 0 0 0 10px transparent;}
                    100% {box-shadow: 0 0 0 0 transparent;}
                    }

Error messages from the browser console:

N/A

By putting an X in the boxes ([]) below, I indicate that I:

petrij98 commented 4 months ago

Workaround discovered by Mushroom card community. Keyframes need to be defined within the if statement, not after.