thomasloven / lovelace-card-mod

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

3.2.2 does not change icon in views via card-mod-theme #268

Closed Mariusthvdb closed 9 months ago

Mariusthvdb commented 1 year ago

My Home Assistant version: 2023.4.6

My lovelace configuration method (GUI or yaml): Yaml

What I am doing:

changing an icon in the view tabs via a template. This has been working up to and including 3.1.4. All updates after that broke this functionality, and there are some other posts in this repo on that. Maybe the syntax was changed, but no reponse in the community either in that, so for now have to consider it an issue. Since 2023.4 forces us to update (or manually edit the resource, whihc I have done, and which does indeed still work...) I figured a new issue was useful

What I expected to happen:

have the icon change

What happened instead:

Icon does not change Minimal steps to reproduce:

# The least amount of code possible to reproduce my error
  card-mod-root-yaml: |

    paper-tab[aria-label='Aanwezigheid'] ha-icon$: |
      ha-svg-icon {
        --card-mod-icon: {{states('sensor.presence_icon')}};
      }

    paper-tab[aria-label='Verwarming'] ha-icon$: |
      ha-svg-icon {
        --card-mod-icon: {%- set action = state_attr('climate.front_room','hvac_action') -%}
                         {%- set icon = {'heating':'radiator','idle':'radiator-disabled'} -%}
                         mdi:{{icon.get(action,'radiator-off')}};
      }

Error messages from the browser console:

No errors, except the ominous double:

Scherm­afbeelding 2023-04-05 om 12 30 02

which appears although I have set the card via the frontend extra_module_url method

Please have a look if this is a user error, or can be fixed. thanks!

related to an earlier issue at https://github.com/thomasloven/lovelace-card-mod/issues/206#issuecomment-1666965412

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

Mariusthvdb commented 1 year ago

just had another check on this, and, I can see this mod:

    paper-tab[aria-label='Beweging'] ha-icon$: |
      ha-svg-icon {
        --card-mod-icon: {{'mdi:motion-sensor' if is_state('binary_sensor.motion_sensors_all','on') else
                           'mdi:motion-sensor-off'}};
        color: {{'red' if is_state('binary_sensor.motion_sensors_all','on')}};
      }

being applied to the sensor in the inspector

on:

Scherm­afbeelding 2023-04-07 om 13 05 23

off:

Scherm­afbeelding 2023-04-07 om 13 05 14

and yes, the color is changing to red when 'on', the icon remains untouched.

Scherm­afbeelding 2023-04-07 om 13 08 21 Scherm­afbeelding 2023-04-07 om 13 08 27

back to edited 3.1.4 + fix

Scherm­afbeelding 2023-04-07 om 18 07 57 Scherm­afbeelding 2023-04-07 om 18 08 09
Mariusthvdb commented 9 months ago

just asking for some consideration here, because today we were confronted with the 2023.10.0b3 and that breaks card_mod (filed an issue on it) and made me remember why I still use 3.1.4 with a fix, and not the latest 3.2.2.

Truly would wish he card_mod icon issue here could be resolved, so we can finally start using 3.2.2 to its full capacity

Mariusthvdb commented 9 months ago

finally made it happen... turns out I the mod above working 3.1.4, had to be changed into the mod I used before we had card-mod-icon...

what works is:

  card-mod-root-yaml: |

    paper-tab[aria-label='Weer'] ha-icon$: |
      ha-svg-icon {
        animation: {{'blink 2s ease infinite' if
                     is_state('binary_sensor.meteoalarm_brabant','on') else 'none'}};
      }
      @keyframes blink {
        50% {opacity: 0.2;}
      }

    .: |

      paper-tab[aria-label='Weer'] {
        --card-mod-icon: {%- if is_state('binary_sensor.meteoalarm_brabant','on') %}
                         {{states('sensor.meteoalarm_icon')}}
                         {%- else %} {{states('sensor.weather_icon')}}
                         {%- endif %};
        color: {{'maroon' if is_state('binary_sensor.meteoalarm_brabant','on')
                  else states('sensor.temperature_color_name')}};
      }

card-mod-icon now is nicely updated again. Reason I split the mod up is that by applying the animation to the ha-svg-icon element, it is only the icon that will be animated.

We can also set the animation in the .: | section, but then anime,ation is applied to the whole icon placeholder of the tav view, and, depending on you background that seems a bit odd.

closing as the issue is no longer an issue ;-)