Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Card-mod cards causes all dashboard cards to flicker after the HA update and when Entity-filter in the same dashboard." #407

Open
RobusX opened this issue Sep 29, 2024 · 38 comments

Comments

@RobusX
Copy link

RobusX commented Sep 29, 2024

My Home Assistant version: 2024.9.3

My lovelace configuration method (GUI or yaml): Yaml

After updating from 2024.6.4 to 2024.9.3, all dashboard cards with modified colors or card-mod hidden buttons are flickering (colors and hidden buttons blink) when an entity-filter card with color-changing mode is also present on the dashboard. The issue cannot be reproduced in safe mode, as no cards are displayed.

Flickering appeared with Firefox, Google Chrome and also within latest HA Android Companion app.
Slider button on the right browser side also blinks.

If the dashboard displays cards in the bottom part, browser due to flickering issue moves to the upper dashboard side, where the right slider also blinks.
As was discovered, issue disappears when entity-filter card is removed from the dashboard or dashboard in edit mode.
The problem is very annoying; please resolve it. The uses of the card-mod card are endless, and it would be a pitty to abandon it.

"Please review the detailed issue description and dashboard card codes (link below), where it was stated from the frontend developer that the problem is caused by card-mod not being updated to follow the latest HA frontend releases."

home-assistant/frontend#22084

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

@RobusX RobusX changed the title Card-mod cards causes all dashboard cards to flicker after the HA update when Entity-filter in the same dashboard." Card-mod cards causes all dashboard cards to flicker after the HA update and when Entity-filter in the same dashboard." Sep 29, 2024
@ildar170975
Copy link
Contributor

ildar170975 commented Sep 29, 2024

Please post a SHORT minimal code to reproduce the issue.
With stock cards only.

@RobusX
Copy link
Author

RobusX commented Sep 30, 2024

Yes, no problem.

Firstly, there are two automations which generate blinking lights for aqara lights (2 fields - columns in the entitiy-filter card -> please accommodate it to your entities and remove alarm/sun conditions, only blinking is needed:

alias: Light Night Blinking RED when Armed
description: Light Night Blinking RED when Armed
trigger:
  - platform: state
    entity_id:
      - switch.alarm_plug
    to: "on"
    id: alarm
  - platform: numeric_state
    entity_id: sun.sun
    value_template: "{{ state_attr('sun.sun', 'elevation') }}"
    below: -3
    id: sunset
  - platform: numeric_state
    entity_id: sun.sun
    value_template: "{{ state_attr('sun.sun', 'elevation') }}"
    above: -3
    id: sunrise
  - platform: time_pattern
    minutes: /3
    id: alarm
condition:
  - condition: or
    conditions:
      - condition: and
        conditions:
          - condition: state
            entity_id: switch.alarm_plug
            state: "on"
          - condition: trigger
            id: sunset
          - condition: time
            after: "18:00:00"
            before: "07:00:00"
      - condition: and
        conditions:
          - condition: state
            entity_id: switch.alarm_plug
            state: "on"
          - condition: trigger
            id: sunrise
          - condition: time
            after: "06:30:00"
            before: "18:00:00"
      - condition: and
        conditions:
          - condition: state
            entity_id: switch.alarm_plug
            state: "on"
          - condition: trigger
            id: alarm
action:
  - choose:
      - conditions:
          - condition: trigger
            id: sunset
        sequence:
          - repeat:
              sequence:
                - target:
                    entity_id:
                      - light.aqara_hub_m1s_5fc8_lightbulb
                      - light.aqara_hub_m1s_64d3_lightbulb
                  data:
                    color_name: red
                    brightness_pct: 70
                  action: light.turn_on
                - delay: "00:00:00.6"
                - target:
                    entity_id:
                      - light.aqara_hub_m1s_5fc8_lightbulb
                      - light.aqara_hub_m1s_64d3_lightbulb
                  data:
                    brightness_pct: 3
                    kelvin: 3800
                  action: light.turn_on
                - delay: "00:00:05"
              until:
                - condition: state
                  entity_id: switch.alarm_plug
                  state: "off"
      - conditions:
          - condition: trigger
            id: sunrise
        sequence:
          - repeat:
              sequence:
                - target:
                    entity_id:
                      - light.aqara_hub_m1s_5fc8_lightbulb
                      - light.aqara_hub_m1s_64d3_lightbulb
                  data:
                    color_name: red
                    brightness_pct: 70
                  action: light.turn_on
                - delay: "00:00:00.6"
                - target:
                    entity_id:
                      - light.aqara_hub_m1s_5fc8_lightbulb
                      - light.aqara_hub_m1s_64d3_lightbulb
                  data:
                    brightness_pct: 3
                    kelvin: 3800
                  action: light.turn_on
                - delay: "00:00:05"
              until:
                - condition: state
                  entity_id: switch.alarm_plug
                  state: "off"
      - conditions:
          - condition: trigger
            id: alarm
        sequence:
          - repeat:
              sequence:
                - target:
                    entity_id:
                      - light.aqara_hub_m1s_64d3_lightbulb
                      - light.aqara_hub_m1s_5fc8_lightbulb
                  data:
                    color_name: red
                    brightness_pct: 70
                  action: light.turn_on
                - delay: "00:00:00.6"
                - target:
                    entity_id:
                      - light.aqara_hub_m1s_64d3_lightbulb
                      - light.aqara_hub_m1s_5fc8_lightbulb
                  data:
                    brightness_pct: 3
                    kelvin: 3800
                  action: light.turn_on
                - delay: "00:00:05"
              until:
                - condition: state
                  entity_id: switch.alarm_plug
                  state: "off"
mode: restart

And here is other automation needed which blinks additionally two kuril bulbs in the entity-filter card (when those bulbs blink, there are four columns in the entity-filter card (2 for aqara+2x kuril), so entity-filter card is stretching from 2 to 4 fields:


alias: Light Kuril Blinking RED when Armed
description: Light Kuril Blinking RED when Armed
trigger:
  - platform: state
    entity_id:
      - switch.alarm_plug
    to: "on"
    id: day
  - platform: time_pattern
    minutes: /3
    id: day
condition:
  - condition: state
    entity_id: switch.alarm_plug
    state: "on"
action:
  - choose:
      - conditions:
          - condition: trigger
            id: day
        sequence:
          - repeat:
              sequence:
                - target:
                    entity_id:
                      - light.kurilbulb1
                      - light.kurilbulb2
                  data:
                    color_name: red
                    brightness_pct: 2
                  action: light.turn_on
                - delay: "00:00:00.1"
                - target:
                    entity_id:
                      - light.kurilbulb1
                      - light.kurilbulb2
                  data: {}
                  action: light.turn_off
                - delay: "00:00:00.1"
                - target:
                    entity_id:
                      - light.kurilbulb1
                      - light.kurilbulb2
                  data:
                    color_name: white
                    brightness: 2
                  action: light.turn_on
                - delay: "00:00:00.1"
                - target:
                    entity_id:
                      - light.kurilbulb1
                      - light.kurilbulb2
                  data: {}
                  action: light.turn_off
                - delay: "00:00:06"
              until:
                - condition: state
                  entity_id: switch.alarm_plug
                  state: "off"
          - data:
              brightness_pct: 20
              kelvin: 3500
            target:
              entity_id:
                - light.kurilbulb1
                - light.kurilbulb2
            action: light.turn_on
          - delay: "00:00:01"
          - data: {}
            target:
              entity_id:
                - light.kurilbulb1
                - light.kurilbulb2
            action: light.turn_off
mode: single


And here is entity-filter card for the dashboard which contains those four bulbs:

type: entity-filter
title: Lights/Sensors ON
show_header_toggle: false
entities:
  - entity: light.aqara_hub_m1s_5fc8_lightbulb
    name: AqSFlL
    tap_action:
      action: toggle
  - entity: light.aqara_hub_m1s_64d3_lightbulb
    name: AqStrL
    tap_action:
      action: toggle
  - entity: light.kurilbulb1
    name: Kur_1
    tap_action:
      action: toggle
  - entity: light.kurilbulb2
    name: Kur_2
    tap_action:
      action: toggle
state_filter:
  - 'on'
  - open
  - detected
  - operator: '>'
    value: 4
show_empty: false
sort:
  method: domain
card:
  type: glance
  title: ' '

And finally, here we have other (two for example) entities card in the same dashboard, which contains some car-mod code and are flickering (NOK):
1. Here on-off switch on the right near "Main Door" text, which is hidden by  card-mod, flickers:

type: entities
entities:
  - type: custom:template-entity-row
    entity: binary_sensor.contact_sensor
    name: Main Door State
    toggle: false
    secondary_info: last-updated
    secondary: >
      {% set state = states('binary_sensor.contact_sensor') %} {% if state ==
      'off' %}
        Closed
      {% elif state == 'on' %}
        Open
      {% else %}
        {{ state }}
      {% endif %} | Last: {{
      states.binary_sensor.contact_sensor.last_updated.astimezone().strftime('%m-%d
      %H:%M:%S') }}
    card_mod:
      style: |
        :host {
          --mdc-icon-size: 40px;    
          --paper-item-icon-color: {%
            if is_state('binary_sensor.contact_sensor', 'off') %}
            green;
          {%- elif is_state('binary_sensor.contact_sensor', 'on') or
              is_state('switch.shelly_main_door_12v_switch_0', 'on') %}
            red;
          {%- else %}
            grey;
          {%- endif %};
              }
  - type: custom:fold-entity-row
    head:
      entity: switch.shelly_main_door_12v_switch_0
      name: Main Door
      toggle: false
      state_color: true
      card_mod:
        style: |
          :host {
            --card-mod-icon-color: 
            {% if is_state(config.entity, 'on') %}
              orange;
            {% else %}
              grey;
            {% endif %};
          }
          .entities .state-card-toggle .state-card {
            display: none !important;
          }
          ha-entity-toggle {
            display: none !important;
          }
    entities:
      - type: custom:template-entity-row
        entity: switch.shelly_main_door_12v_switch_0
        name: Main Door 12V Switch
        tap_action:
          action: toggle
        toggle: true
        secondary_info: last-updated
        secondary: >
          Last: {{
          states.switch.shelly_main_door_12v_switch_0.last_updated.astimezone().strftime('%m-%d
          %H:%M:%S') }}
      - type: custom:template-entity-row
        entity: switch.2pm_main_door_switch_1
        name: Main Door 230V Supply
        tap_action:
          action: toggle
        toggle: true
        secondary_info: last-updated
        secondary: >
          Power: {{ states('sensor.2pm_main_door_switch_1_power') }} W |  Last:
          {{
    states.switch.shelly_main_door_12v_switch_0.last_updated.astimezone().strftime('%m-%d
          %H:%M:%S') }} 
title: ''
state_color: true
show_header_toggle: false


2. And in this entities card on the same dashboard all three doors, colored with green when closed (car-mod) are flickering:

type: entities
title: ' '
show_header_toggle: false
state_color: true
entities:
  - type: custom:template-entity-row
    entity: binary_sensor.contact_sensor
    name: Main Door
    icon: mdi:door
    style: |
      :host {
        --mdc-icon-size: 30px;
        --card-mod-icon-color: 
          {% if is_state(config.entity, 'on') %}
            red
          {% elif is_state(config.entity, 'unavailable') or is_state(config.entity, 'unknown') %}
            yellow
          {% else %}
            green
          {% endif %};
      }
    secondary: |
      {% if is_state(config.entity, 'on') %}
        Door Open
      {% elif is_state(config.entity, 'off') %}
        Door Closed
      {% elif is_state(config.entity, 'unavailable') %}
        Sensor Unavailable
      {% elif is_state(config.entity, 'unknown') %}
        Sensor State Unknown
      {% endif %}
  - type: custom:template-entity-row
    entity: binary_sensor.contact_sensor_3
    name: App Door
    icon: mdi:door
    style: |
      :host {
        --mdc-icon-size: 30px;
        --card-mod-icon-color: 
          {% if is_state(config.entity, 'on') %}
            red
          {% elif is_state(config.entity, 'unavailable') or is_state(config.entity, 'unknown') %}
            yellow
          {% else %}
            green
          {% endif %};
      }
    secondary: |
      {% if is_state(config.entity, 'on') %}
        Door Open
      {% elif is_state(config.entity, 'off') %}
        Door Closed
      {% elif is_state(config.entity, 'unavailable') %}
        Sensor Unavailable
      {% elif is_state(config.entity, 'unknown') %}
        Sensor State Unknown
      {% endif %}
  - type: custom:template-entity-row
    entity: binary_sensor.contact_sensor_2
    name: Cellar Door
    icon: mdi:door
    style: |
      :host {
        --mdc-icon-size: 30px;
        --card-mod-icon-color: 
          {% if is_state(config.entity, 'on') %}
            red
          {% elif is_state(config.entity, 'unavailable') or is_state(config.entity, 'unknown') %}
            yellow
          {% else %}
            green
          {% endif %};
      }
    secondary: |
      {% if is_state(config.entity, 'on') %}
        Door Open
      {% elif is_state(config.entity, 'off') %}
        Door Closed
      {% elif is_state(config.entity, 'unavailable') %}
        Sensor Unavailable
      {% elif is_state(config.entity, 'unknown') %}
        Sensor State Unknown
      {% endif %}   

I hope it is more clear now. Thanks for looking into it !

@ildar170975
Copy link
Contributor

Sorry, this is not a short MWE.

@ildar170975
Copy link
Contributor

Also, the posted code is not formatted and cannot be analyzed.

@RobusX
Copy link
Author

RobusX commented Sep 30, 2024

I shorted code as much i could..but entities for blinking should be present in the dashboard and in both automations. And also in the flickering cards.
I pasted yaml code for both automations, entity-filter card and both entities cards (flickering) and save it into notepad (.yaml file not supported to enclose). AS i see formatting is preserved, although txt format. I hope, this is ok.
Thank you for your effort.

cards.txt

@RobusX
Copy link
Author

RobusX commented Sep 30, 2024

I uploaded "flickering" video from the test dashboard to Youtube.

Link is here:
https://youtu.be/a7kE-vaaDT4

IN original dashboard with much more cards, flickering is much more intenstive (with sliders up down flickering) and as i noticed also tab with mini graphic cards flickers:

In video below i switched between two tabs to show flickering on both:
https://www.youtube.com/watch?v=t6JGUY2BK_0

@pickonedev
Copy link

pickonedev commented Oct 1, 2024

Here you are :-D

I have a sample as well.

2024-10-01.18-41-35-1.mp4

@RobusX
Copy link
Author

RobusX commented Oct 1, 2024

Thanks @ pickonedev .
Can you confirm too that in dashboard editing mode it is no flickering at all ?
Thanks for the info.

@pickonedev
Copy link

pickonedev commented Oct 1, 2024

That is right.

Edit: I was wrong, it is happening in editing mode as well.

@RobusX
Copy link
Author

RobusX commented Oct 2, 2024

Yes, today i also tried your case. I turned one switch to ON in the entities card and all cards that use card-mod code flickered at the same time.
So problem appears not connected with the entity-filter card, if this is the same cause, as my other issue when entity-filter is present.

@pickonedev
Copy link

I converted all my dashboards to Sections and the issue partially dissapeared...
Now it is only happening to the entity-filter cards, in the past (when I was not using Sections), it would flicker all the cards where card_mod was being used

Btw ... does someone care about this issue?
I see no improvement or not even an official answer about this, for almost two months....

Anyway, even with an answer, I don't think this can be repaired, because this is the functionality way of the card_mod... After element was loaded, card_mod is applied, so... there is a gap of time till card_mod can be applied (depends of the performance of the device). For my old tablets, I can wait even 2-4 secunds... luckly that I change them and now the time is reduced to few ms... but still... it is very annoying to see that flicker... This is the same as loading a popup with elements modified by card_mod, time gap till everything appear properly...

@RobusX
Copy link
Author

RobusX commented Nov 22, 2024

I am still experiencing the same issue with entity-filter, and yes, apparently nobody cares about it. Maybe most people no longer use entities cards. Partly, I replaced entity-filter with the custom:auto-entities card, and on those tabs, the situation is better.
In the meantime, I reported another issue related to the custom fold-entity-row card not opening its instances here:
GitHub Issue.
A similar situation applies - no one seems capable or willing to solve issues with "old" cards. It seems like we old-timers have to modify our dashboards to newer formats every year or two due to such issues (like how you transitioned your dash to "Sections.") While this may be a comprehensive update, it's likely not easy.
Did you use any converter tool to perform this transformation? Where did you find good instructions, for instance?
I am currently avoiding modifying my dashboards to use "Sections" due to the increased space they require (especially in the Android phone companion app, where I use the custom fold-entity-row to hide similar entities under a main one).
Another concern is how to display all secondary information (e.g., power, states, etc.) using "Sections." Currently, I use card-mod for this purpose.
Thanks in advance for any useful information!

@ildar170975
Copy link
Contributor

ildar170975 commented Nov 22, 2024

no one seems capable or willing to solve issues with "old" cards

Custom fold-entity-row, stock entity-filter - not "old cards".

As for custom cards which have issues:

  1. Particularly for f-e-r: this is about a particular Android browser (or webview, whatever) which may not be updated; similar things happen to old iOS devices which stop getting updates from Apple (not to mention that Safari is buggy & does not follow some conventions by default).
  2. For some custom cards: their authors may be rather tired to follow changes in HA frontend & give up updating their cards (ofc some authors stop updating due to other personal reasons).

In my experience, most of issues with custom cards may be either "workarounded" or fixed by card-mod etc.

As for stock cards, particularly entity-filter - imho like some other cards it is not usable for Sections. It just can be shown/not shown; can have height 100px or 200px. And these things are not according to "fancy sections way". That is why many experienced users do not use Sections - it is mainly a toy for beginners. Or, experienced users may use sections instead of a custom grid layout-card (i.e. for particular views which should be grids).
Since you are facing issues with entity-filter - you should be 100% sure that it is really caused by card-mod. Otherwise - this is a HA issue.
And actually YOU = one of a reason why this entity-filter-issue is not investigated by other users (like me in particular) - because YOU have not provided a minimal working example (MWE) yet - your long code is not MWE, with my all due respect.

@RobusX
Copy link
Author

RobusX commented Nov 22, 2024

@ildar170975
Thank you for the information regarding sections. It seems they might not be suitable for my use case, so I’ll stick with entities for as long as they work acceptable.

Regarding the Android issue with the fold entity row:
My phone always runs the latest version of Android. This issue appears inconsistently-sometimes it happens, and other times it does not. Therefore, I don’t believe it’s related to an outdated or buggy Android version. I suspect it’s related to recent Home Assistant changes affecting dashboards, including in the Companion App.

Regarding the entity filter card:
As I mentioned earlier, I can’t provide a more minimal working example than the one I already shared.
The issue occurs when two lights (named "kuril bulb1/2" in the automation) are blinking rapidly. In this case, the entity filter should expand and contract at the same rhythm as the blinking appeared (100ms delay above, many times interchangeable (one bulb or another or both bulbs displayed). This behavior used to work fine in previous versions of Home Assistant.

The "kuril blinking" automation is integral; without it, the lights wouldn’t blink.
As a result of blinking, the entitiy filter card stretches and contracts . The entity filter also displays other bulbs, so it’s not entirely empty at the moment when the "kuril bulbs" are not shown.
Other entity cards, which are flickering due to the enitiy filter issue have only entities with card-mod which causes flickering. Unfortunately, I do not know, how to present this behaviour in a shorter way.

@pickonedev: Do you perhaps have a more appropriate "minimal working example" to help @ildar170975 investigate this issue with the entity filter card?

@ildar170975
Copy link
Contributor

Well, ofc I may try with a huge example - it is just a matter of time & a user's persistence... Providing a short MWE highly increases chances to localize the issue; also, there is a high probability that it will be YOU who localizes the issue while finding an MWE.
Ofc this is not just about the particular @ildar170975 - it is about all other users who may have a desire & spare time to investigate.

@RobusX
Copy link
Author

RobusX commented Nov 23, 2024

Thank you very much! And yes, the entity-filter card is much more responsive when lights are blinking quickly compared to auto-entities card. Therefore, it would be great if this issue could be resolved.

@pickonedev
Copy link

pickonedev commented Nov 23, 2024

About sections, was not so hard to do, at least not for me, and imagine that I have 7 similar dashboards (one per each room, with no layout differences, only the switches/sensors were different).
In the old dashboards, I used a horizontal three columns layout and converting to sections, I only had one issue of displaying something, I will show you below.
I just went to the original dashboard, click convert to sections and HA made a different tab/view converted to sections, then I just needed to modify some card_mod things, to make it identical like in the past.

Look, this was the original dashboard

image

And after the conversion, I had only one issue, you can see in the image below, but I solve it easy and it was even better

image

Edit1: I would not use lovelace-auto-entities because of the same reason of this issue, I fear that no one cares about issues with that addon as well 👎 you know what I say....

Edit2: About space needed for sections, yes, but you can modify the theme to look exactly how you want. I needed to do this as well... but not so hard, I only added this ha-view-sections-column-gap: 8px to my theme

Edit3: You can use sections with your past layout, you don't need to change all the cards.. As you can see I keept my three columns layout and all the old cards, I didn't change anything else.

Edit4: As I said before, it is not an issue with filter card, it is not an issue with nothing, the "issue" is the functionality of card_mod, which cannot be different. As card_mod applies css after the elements are loaded, it is more than normal to be a time gap till the css it is shown properly, depending of the device performance. This card_mod it is similar with css/javascript addons for browsers, they apply after elements are loaded, and if performance is bad, the time gap of loading things is bigger... At lease for my case, I saw that the "flicker" occur as card_mod is applied, it is wrong called a flicker, it is more a pass from standard css to card_mod css... As you can see in my past video from above, that "flicker" is just the time gap in applying card_mod css, it is not just a flicker, it seems to be a flicker, but is not. When I don't use card_mod, there is no "flicker" becaue the css it is not changing... So... the only solution I see in order to solve this "issue" is the mode of how card_mod is implemented... If it could be integrated as a "kernel" addon, to load the css in the same time with the used card, could solve it, but I am not such a good programmer to know too much. In my case, this is the "issue", look again to that video I posted above (on 1 october), when I change the switch, the filter card, it is going through his standard display, then changes to card_mod, through that time gap I was talking about... Card_mod cannot load in the same time with the card... I saw this because I have a popup with so many sensors, all modified with card_mod, and If I see that popup on a low performance device, I can see that card_mod loads after... Let me check if I can make a video to show you all, about this...

This is the video test, I made it in slowmotion, to see it better
https://github.com/user-attachments/assets/81cc397a-eede-4134-842e-1025e837cd0b

It is clear that the "flicker" is that time gap of applying the card mod css....
The same is happening when you refresh/reload the dashboard. All the modified css cards will first load as standard, then css is applied...

Edit5: Oh, wait, I think that the "issue" could be solved somehow... As far as card_mod is applied to the entire dashboard after the elements are loaded (one by one), only the filter card does "not keep" the last css...In fact, it is not about keeping the css, card mod could not be applied to something which has not been loaded yet...so filter card, will load(show/hide) the entity, after the state changes, till then, all those elements does "not exists" in the dashboard... All other cards, are already loaded with the dashboard, this is why are not "flickering". The same is happening with the popup cards of browser mod, popups are not loaded with the dashboard, same as card filter entities. Popups will only load after requested. Filter cards have this "issue" because they load the element when the states are changed, never before (similar with popups, if you can see the similarity)... If filter card could load all the elements from the start, then hide/show the elements with a different approach, maybe this could solve the problem... Popups could have a similar solution...

Edit6: By the way, there is only one card which applies css "before" loading the element, is the markdown card. Even if you refresh the page, this card will shown as card_mod modified css from the start, no loading gap, no nothing, which is great....

@RobusX
Copy link
Author

RobusX commented Nov 24, 2024

Thank you for interesting research. Probably this info will help @ildar170975 to have more detailed info about the annoying flicker issue. We keep our fingers crossed that this issue will be investigated and resolved.
@ildar170975 if you need any additional info, just let us know. Thank you !

@pickonedev
Copy link

pickonedev commented Nov 24, 2024

Thanks @ pickonedev . Can you confirm too that in dashboard editing mode it is no flickering at all ? Thanks for the info.

Sorry, by reading all the past comments, I have now understood what exactly you asked me here and I cannot confirm this.
It is happening in edit mode as well.

100% the fault of "flickering" is that the entity-filter uses a script which loads (not hide/show) the elements regarding the states of entities... Entify-filter card could work if is using something like css, to hide/show entities, something like "display: none" or "visibility: none". Because javascript makes the entities appear only by the condition meet from the code, this makes the entities loads or "removes" everytime when states are changed. If the filter entity card could "show" all the entities and uses css to hide/show them by following the filter conditions, this could make card mod apply the css, then only show/hide entities. I hope you all could understand what I say here :)))

@RobusX
Copy link
Author

RobusX commented Nov 24, 2024

OK, then we do not have similar issues in this case.
In my situation, there is no flickering in other cards containing card mod when the dashboard edit mode is enabled (gray strip at the top, pencil pressed).
However, as soon as I press the DONE button, flickering in other cards resumes, synchronized with the bulbs appearing and disappearing within the entity-filter card.

@ildar170975
Copy link
Contributor

Is anyone going to provide an MWE ? )))

@pickonedev
Copy link

pickonedev commented Nov 26, 2024

Can you please tell me what MWE is and how can I provide it?

Edit: If is about a minimal code to use in order to see the issue, here is it:

This is the filter entity card

type: entity-filter
entities:
  - entity: switch.sonoff_computer_light_1
    name: Room Light 1
    card_mod:
      style:
        hui-generic-entity-row$: |
          .info, .value{font-size:6px}
  - entity: switch.sonoff_computer_light_2
    name: Room Light 2
    card_mod:
      style:
        hui-generic-entity-row$: |
          .info, .value{font-size:6px}
state_filter:
  - "on"
show_empty: false
card:
  type: entities

It is very important to have at least two entities in the entity filter and one of them to be already shown (state on), in order to replicate the issue properly.

And this is the button I used to make filter entity react

show_name: true
show_icon: true
type: button
tap_action:
  action: toggle
entity: switch.sonoff_computer_light_1

@ildar170975
Copy link
Contributor

ildar170975 commented Nov 26, 2024

@pickonedev
Tested your case here:

  - title: 22x
    path: 22x
    type: custom:horizontal-layout
    cards:
      - type: entity-filter
        entities:
          - entity: switch.test_switch
            name: Room Light 1
            card_mod:
              style:
                hui-generic-entity-row$: |
                  .info, .value{font-size:6px}
          - entity: switch.test_switch_2
            name: Room Light 2
            card_mod:
              style:
                hui-generic-entity-row$: |
                  .info, .value{font-size:6px}
        state_filter:
          - 'on'
        show_empty: false
        card:
          type: entities
      - type: entities
        entities:
          - entity: switch.test_switch
          - entity: switch.test_switch_2
        title: static

fil

If you mean "font-size changes from normal to small" - this is called "transition".
It is observed not only with entity-filter.
Consider it as "normal": sometimes styles are applied after some period.
In some cases it may be decreased by adding transition: none to card-mod code, sometimes not )).
More complex styles, more complex cards (like mushrooms - note that the author is not maintaining card-mod-related issues, so these guys come here; and here I totally agree with Paul) -> more transition effects.

@pickonedev
Copy link

Yes, yes, that's the "issue", that "flicker".

But I was talking about this in early comments, I know that there is no real issue, I think is the time gap between card elements loads and card_mod applying the css style.

I don't think it is about transition, I already made some tests, and by the way, there is no other card with the same "issue"...
Using conditional card it is working flawless.... which made me think that the "issue" can be solved if filter card will load all the entities from the start, but uses a different method to hides the one which does not meet the conditions.
I don't know exactly, I just think that javascript it is loading the entities only after the state meet the condition (not before), and when an element is newly loaded, only after loads, card_mod will apply css.
These said, a css method could solve this. Filter card could load all the entities, hiding the non-meet conditions with (display:none), then, card_mod style will be applied even for those which are not displayed, and finaly when filter card will change the display to initial, for the entities which meet the conditions, there will not be any "flicker"...

I have seen the same "issue" when I used a browser addon for changing the css for websites, that css will be applied only after the elements are loaded, because that addon it is not a server side css, it is applied from the client side... Maybe it is the same reason for which that "flicker" is happening with card_mod and filter card. Even if card_mod it is installed on the server, it can't be applied in the same time with the actual cards, so a time gap will appear...

@ildar170975
Copy link
Contributor

ildar170975 commented Nov 29, 2024

Filter card could load all the entities, hiding the non-meet conditions with (display:none), then, card_mod style will be applied even for those which are not displayed, and finaly when filter card will change the display to initial, for the entities which meet the conditions, there will not be any "flicker"...

Check another case:

type: entity-filter
entities:
  - entity: switch.test_switch
    name: Room Light 1
  - entity: switch.test_switch_2
    name: Room Light 2
state_filter:
  - "on"
show_empty: false
card:
  type: entities
  card_mod:
    style:
      .card-content hui-toggle-entity-row $:
        hui-generic-entity-row $: |
          .info {font-size: 6px;}

Here card-mod is defined on a card's level - but a style for the ".info" element is defined inside a "card-mod" element on a row's level:
image
and the style is applied after a row is created. Same flickering, card-mod is applied after a row's creation.
Note that in case of changing a color property this flickering would be less visible; and in case of font-size it is rather visible since this is about a SIZE.

But - in some cases it may be "workarounded" by an external js.
Take same card - but with a specified class:

type: entity-filter
entities:
  - entity: switch.test_switch
    name: Room Light 1
  - entity: switch.test_switch_2
    name: Room Light 2
state_filter:
  - "on"
show_empty: false
card:
  type: entities
  card_mod:
    class: entity_filter

and this js:

customElements.whenDefined('hui-entities-card').then(() => {
  const EntitiesCard = customElements.get('hui-entities-card');
  const { html, css } = EntitiesCard.prototype;
  
  const newStyle = css`
  ha-card.entity_filter {font-size: 8px; transition: none;}`;
  
  const newStyles = [].concat(EntitiesCard.styles, newStyle);
  Object.defineProperty(EntitiesCard, 'styles',        {value: newStyles, configurable: true, enumerable: false});
  Object.defineProperty(EntitiesCard, 'elementStyles', {value: newStyles, configurable: true, enumerable: false});
});

And compare - left with card-mod (1st code in my post), right with a class:
filt

@pickonedev
Copy link

pickonedev commented Nov 29, 2024

But - in some cases it may be "workarounded" by an external js.

With the extenal js it is working flowless... So... this means that the issue is not from entity filter card, this "flicker" could be solved from card mod? By changing many things inside... It would be great if this could be implemented in somethinng, in order to not using external js. Not everybody knows Java script :-D

I know, changing the size is extremely visible, same as hiding elements, but this is the way some of us want to change them.

I would try to implement the workaround with the external js, for all my "issues", till something will be changed in the future.

Thank you for your time.

Edit: I am trying to modify your js code in order to add my css, but I lack of js knowledge... Could you help me a bit, please?

This is what I had on every card inside filter card

type: entity-filter
entities:
  - entity: sensor.sonoff_computer_tv_pow_power
    name: Room TV
    card_mod:
      style:
        hui-generic-entity-row$: |
          state-badge {
            display: none;
          }
          .info {
            margin-left:0 !important;
          }
          .info, .value{font-size:10px}

How can I add this css into that external js file? I didn't know how to integrate, seems very hard for me to understand...
I don't understand how to deal with shadow-root into the external js file :-(

Thanks!

@ildar170975
Copy link
Contributor

How can I add this css into that external js file?

That is what I meant by "in some cases it may be" )))
Never tried entering a row from a card in js, actually))

@pickonedev
Copy link

Ah, alright, I understand. Anyway, thanks.
I still hope that somehow, that "flicker" will be solved in the future... not a big deal, but very annoying when you have devices with low performance...

@RobusX
Copy link
Author

RobusX commented Nov 30, 2024

@ildar170975

I am not a SW guru, so I do not even know where to put your Javascript text, but i assumed this text was only useful for @pickonedev's issue.
Now i am providing minimum of the minimum MWE for my issue, where a hidden toggle switch under the fold entity row blinks.

Could you please kindly look into the issue, simulate this scenario at your side and suggest a solution which would prevent flickering issue ? As I said, when in dashboard editing mode, there is no flickering issue.
Thank you very much.

1. Entity filter card with only one light which blinks due to automation at the bottom:

type: entity-filter
title: Lights/Sensors ON
show_header_toggle: false
entities:
  - entity: light.kurilbulb1
    name: Kur_1
    tap_action:
      action: toggle
state_filter:
  - "on"
  - open
  - detected
  - operator: ">"
    value: 4
show_empty: false
sort:
  method: domain
card:
  type: glance
  title: " "


2. Custom fold entity row card with only one entity where hidden toggle switch on the right flickers:

type: entities
entities:
  - type: custom:fold-entity-row
    head:
      entity: switch.shelly_main_door_12v_switch_0
      name: Main Door
      toggle: false
      state_color: true
      card_mod:
        style: |
          :host {
            --card-mod-icon-color: 
            {% if is_state(config.entity, 'on') %}
              orange;
            {% else %}
              grey;
            {% endif %};
          }
          .entities .state-card-toggle .state-card {
            display: none !important;
          }
          ha-entity-toggle {
            display: none !important;
          }
    entities:
      - type: custom:template-entity-row
        entity: switch.shelly_main_door_12v_switch_0
        name: Main Door 12V Switch
        tap_action:
          action: toggle
        toggle: true
        secondary_info: last-updated
        secondary: >
          Last: {{
          states.switch.shelly_main_door_12v_switch_0.last_updated.astimezone().strftime('%m-%d
          %H:%M:%S') }}
title: ""
state_color: true
show_header_toggle: false



3. Automation which blinks kuril1 bulb:

alias: Light Kuril Blinking RED when Armed TEST
description: Light Kuril Blinking RED when Armed TEST
triggers:
  - entity_id:
      - switch.alarm_plug
    to: "on"
    trigger: state
actions:
  - choose:
      - conditions: []
        sequence:
          - repeat:
              sequence:
                - action: light.turn_on
                  target:
                    entity_id:
                      - light.kurilbulb1
                  data:
                    color_name: red
                    brightness_pct: 2
                - delay: "00:00:00.1"
                - action: light.turn_off
                  target:
                    entity_id:
                      - light.kurilbulb1
                  data: {}
                - delay: "00:00:00.1"
                - action: light.turn_on
                  target:
                    entity_id:
                      - light.kurilbulb1
                  data:
                    color_name: white
                    brightness: 2
                - delay: "00:00:00.1"
                - action: light.turn_off
                  target:
                    entity_id:
                      - light.kurilbulb1
                  data: {}
                - delay: "00:00:06"
              until:
                - condition: state
                  entity_id: switch.alarm_plug
                  state: "off"
mode: single



@pickonedev
Copy link

I do not even know where to put your Javascript text

You create a abc.js file inside www folder, then you add a javascript resource to the dashboard, with the path /local/abc.js, after that, you refresh the page and it should work, but it is the worst solution in testing because sometimes you need to open the dashboard into another browser with private tab, in order to see the changes... it is worst than css...

@ildar170975
Copy link
Contributor

How to test with js file:

  1. Create js file, add a code, save.
  2. Add a line into configuration.yaml to import this js. Save.
  3. Reboot HA.
  4. Clean browser’s cache.

How to test with changed js file:

  1. Change js file, save.
  2. Clean browser’s cache.
  3. Reload a page.

@RobusX
Copy link
Author

RobusX commented Dec 1, 2024

As I suspected, and as it now turns out, @pickonedev and I are facing different issues ( while I have no problems when editing the dashboard, @pickonedev still observes flickering) , because your js code has no effect on my issue.

I tried with addition of javascript code in the newly created entity_filter.js, file and put it into /config/www folder.
In the existing ui-lovelace.yaml, where I also have url links from other cards i added:

  • url: /local/entity_filter.js
    type: module

I modified my existing entity-filter card with alarm lamp and added this code below at the end (i also tried with "entities" instead of "glance", issue remained the same):
....
...
..
card:
type: glance
title: " "
card_mod:
class: entity_filter

After restarting Home Assistant, when the alarm blinking light is displayed in the entity filter card, the issue of the flickering toggle button in the main door card (as well as in several other cards with Card Mod applied) remains unchanged.
Flickering in the same manner, as it was before js file.

@ildar170975 Could you please confirm this with simulation and reproduction at your side too ? Thank you.

But, anyway, more annoying for me is still other bug with custom fold entity row and not displaying all included entities within Android (custom template or custom multiple type)... If i add there a card mod code instead of using those cards, then flickering all the way also there ..... :-(

@ildar170975
Copy link
Contributor

@RobusX
I had a look at your code

type: entity-filter
title: Lights/Sensors ON
show_header_toggle: false
entities:
  - entity: light.kurilbulb1
    name: Kur_1
    tap_action:
      action: toggle
state_filter:
  - "on"
  - open
  - detected
  - operator: ">"
    value: 4
show_empty: false
sort:
  method: domain
card:
  type: glance
  title: " "

and a bit confused since it looks like a result of chatgpt.
Sorry - but this code has no sense:

  1. The line "title: Lights/Sensors ON" line is meaningless - it does not belong to entity-filter.
  2. "show_header_toggle" - same.
  3. "sort" - same.
  4. "state_filter" containing values impossible for a light entity.

Why not just replacing this with a simplest

type: entity-filter
entities:
  - entity: input_boolean.test_boolean
state_filter:
  - "on"
card:
  type: glance

for testing where you can manually toggle that input_boolean as frequently as you wish?

@ildar170975
Copy link
Contributor

ildar170975 commented Dec 2, 2024

As for a code with fold-entity-row:

  1. "toggle: false" is not supported for this row, you probably took it from a different custom card.
  2. "state_color: true" for a "head" makes no sense since you are styling a color by card-mod.
  3. This whole line ".entities .state-card-toggle .state-card" makes no sense - again, probably taken from another card.
  4. "secondary_info: last-updated" makes no sense - it is not supported by template-entity-row.

So, before reporting a bug - suggest to always clean-up a code to make it in accordance to Docs.

Anyway, with cleaned-up code:

  - title: ...
    path: ...
    type: masonry
    cards:
      - type: entity-filter
        entities:
          - entity: input_boolean.test_boolean
        state_filter:
          - 'on'
        show_empty: false
        card:
          type: glance

      - type: entities
        entities:
          - type: custom:fold-entity-row
            head:
              entity: switch.test_switch
              card_mod:
                style: |
                  :host {
                    --card-mod-icon-color: 
                    {% if is_state(config.entity, 'on') %}
                      orange;
                    {% else %}
                      grey;
                    {% endif %};
                  }
                  ha-entity-toggle {
                    display: none !important;
                  }
            entities:
              - type: custom:template-entity-row
                entity: switch.test_switch
                secondary: >
                  Last: {{
                  states.switch.test_switch.last_updated.astimezone().strftime('%m-%d
                  %H:%M:%S') }}

      - type: entities
        entities:
          - entity: input_boolean.test_boolean

and an automation toggling the input_boolean entity every 1 second - no flickering:
qaz

@RobusX
Copy link
Author

RobusX commented Dec 2, 2024

@ildar170975:

Thank you for your time and look into my case.
Yes, i mixed similar entity-filter card, where also sensors where in it and other power switches, where i want to display those, whose power >4...so this remained in minimized light card...and I you are right, I am also using chat gpt:). Regarding your example, I am not using masonry, and i believe you, probably it is not flickering as video shows in your printed card.

But, I am interesting in my situation with my existing cards /code, what is issue in my case.
So, when i changed and cleaned my cards regarding your advice, flickering remained.
Currently I tried only with this (all other code cleaned) + automation above for kuril1 light blinking which affects to the entity-filter. IN previous HA versions all worked ok.

Could you test exactly such case at your side, please ? This time i removed above suggested card-mod with js link from the entity-filter card.
In the entities card below hidden toggle switch flickers in the rhythm of kuril1 bulb in the automation above (this is just an example, in other cards also icon blinks, slider,..etc

type: entity-filter
entities:
  - entity: light.kurilbulb1
    name: Kur_1
    tap_action:
      action: toggle
state_filter:
  - "on"
card:
  type: glance


type: entities
entities:
  - type: custom:fold-entity-row
    head:
      entity: switch.shelly_main_door_12v_switch_0
      name: Main Door
      card_mod:
        style: |
          :host {
            --card-mod-icon-color: 
            {% if is_state(config.entity, 'on') %}
              orange;
            {% else %}
              grey;
            {% endif %};
          }
          .entities .state-card-toggle .state-card {
            display: none !important;
          }
          ha-entity-toggle {
            display: none !important;
          }
    entities:
      - type: custom:template-entity-row
        entity: switch.shelly_main_door_12v_switch_0
        name: Main Door 12V Switch



@ildar170975
Copy link
Contributor

ildar170975 commented Dec 2, 2024

  - title: ...
    path: ...
    cards:
      - type: entity-filter
        entities:
          - entity: light.xxx
            name: xxx
            tap_action:
              action: toggle
        state_filter:
          - 'on'
        card:
          type: glance
      - type: entities
        entities:
          - type: custom:fold-entity-row
            head:
              entity: switch.test_switch
              name: Main Door
              card_mod:
                style: |
                  :host {
                    --card-mod-icon-color: 
                    {% if is_state(config.entity, 'on') %}
                      orange;
                    {% else %}
                      grey;
                    {% endif %};
                  }
                  ha-entity-toggle {
                    display: none !important;
                  }
            entities:
              - type: custom:template-entity-row
                entity: switch.test_switch
                name: Main Door 12V Switch
    type: masonry

xcv
Well, you are toggling a light entity every 100ms -> the entity-filter card is redrawn -> a card below is redrawn as well -> and you see a transitional effects as expected since 100ms appears to be a small interval on your client.

IN previous HA versions all worked ok.

Every new HA version needs more resources & causes more impact, so not surprised(

If cards are placed into different columns (example with sections) -> the 2nd card is not redrawn -> no flickering:
xa
(guess all other layouts like masonry, custom:vertical-layout, custom:horizontal-layout will anyway cause redrawing other sibling cards....)

@RobusX
Copy link
Author

RobusX commented Dec 2, 2024

Thank you very much for your research and interesting findings.
So, if i assume correctly, solution would be only to increase blinking period within automation, or using sections.
Regarding first, I just tried with 200ms, 500ms delay, and 1s delay and flickering continued all the way, but i cannot increase it near the 1second range, because then feel of "alarmed place" when looking into blinking lamps is fading out...probably i should say "goodbye" to blinking lamps in the dashboard.
Entity filter card was really responsive in the past, compared to auto-entities.

Regarding sections. I am not familiar with sections yet, so i am in doubt how will this look in the mobile phone, where only one row is displayed at once...and also limitation with equal size quadrants.
if it is possible to include all entities (multiple, custom, and entity filter) into the sections grid and will work without flickering...but even then, equal size limitation probably.
What about masonry placement like here at the link below which allows cards with different heights within one row?
https://www.home-assistant.io/dashboards/masonry/
Will this cause flickering too ?
Thanks again !

@ildar170975
Copy link
Contributor

ildar170975 commented Dec 2, 2024

Entity filter card was really responsive in the past, compared to auto-entities.

Any card with a changing height seems to cause a redraw -> flickering.

using sections.

Could be the way. Not using sections myself; seems that they have a kind of fixed placement which in your case prevents a redraw of sibling cards.

Regarding sections

Erm, can say you only a little about sections. And imho this is beyond this card-mod issue (which I think should be closed).

What about masonry placement

My 1st flickering example above was with masonry. Ofc if a topmost card (entity-filter) changes it's height -> all other cards will be redrawn.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants