gadgetchnnel / lovelace-home-feed-card

A custom Lovelace card for displaying a combination of persistent notifications, calendar events, and entities in the style of a feed.
278 stars 24 forks source link

The card slows down the browser with huge number of requests #59

Open InToSSH opened 3 years ago

InToSSH commented 3 years ago

Hello, I used this card in my lovelace, but if I add include_history: true, it produces a huge number of requests. After adding the card, I could no longer open the "Edit dashboard", the "Edit" buttons under each card were not loading. After refresh, the browser (Chrome) said "Waiting for available sockets" and nothing on that dashboard view was loading. I checked the Developer tools and noticed huge number of requests being made by this card. These are my settings:

type: 'custom:home-feed-card'
title: Home Feed
card_id: main_feed
id_filter: ^home_feed_.*
more_info_on_tap: true
state_color: true
entities:
  - entity: lock.front_door_lock
  - entity: binary_sensor.doods_entry_person_detected
    content_template: Person detected at Front Door
    max_history: 3
    include_history: true
    exclude_states:
      - 'off'
  - entity: binary_sensor.doods_frontyard_person_detected
    content_template: Person detected at Front Yard
    max_history: 3
    include_history: true
    exclude_states:
      - 'off'
  - entity: binary_sensor.entry_door_contact
  - entity: binary_sensor.backyard_door_contact
  - entity: binary_sensor.vestibule_motion
  - entity: input_boolean.home_occupied

I noticed this happens only if I have the include_history: true set. With no history it is ok.

HA version: 2020.12.2

chrome_2021-01-06_02-27-44

redpizza69 commented 3 years ago

I thought it was only causing a problem if you had 2 entities with "include_history: true", as I have had a home feed card with only 1 entity with "include_history: true" for some time and I hadn't noticed any problems.

Today I added a card with 2 entities with "include_history: true" and my system froze up. The following graph shows cpu for the homeassistant container: home feed card The picture above is in 4 sections - ignore section 1, section 2 is with 2 entities with "include_history: true", section 3 with 1 entity with "include_history: true", and section 4 with none.

So my original home feed card was causing problems, but not so much that I noticed. As soon as I added 2 entities with "include_history: true" then my CPU really went up, and I noticed! For completeness here is my card with 2 x "include_history: true":

  - type: 'custom:home-feed-card'
    title: Showers taken today
    max_item_count: 10
    # history_days_back: 1
    # show_empty: false
    more_info_on_tap: true
    state_color: true
    # id_filter: ^home_feed_.*
    entities:
      - entity: binary_sensor.shower_in_use
        format: time
        include_history: true
        remove_repeats: false
        max_history: 10
        content_template: 'Shower'
        exclude_states:
          - "off"
          - "unknown"
      - entity: sensor.hotwater_state
        format: time
        include_history: true
        remove_repeats: false
        max_history: 2
        content_template: 'Hot Water {{state}}'
        exclude_states:
          - "unknown"
gadgetchnnel commented 3 years ago

Can you please try this with the latest beta version, 0.6.1b1, which has an improvement to the history support so that it only calls the API to get the history if the state of any of the entities for which you have include_history set are changed.

Previously, a change in any state in Home Assistant (even ones you don't have in the feed card) could cause it to call the API.

FragMenthor commented 3 years ago

image

I really like this card, but the times the browser usues it, my processor usage rockets sky high, sending all my HA down, to a restart. removed the "history = true" and it's fine, but not nearly as usefull. Great card, hope you can work around this! All this "peaks" in processor usage are due to this.

FragMenthor commented 3 years ago

Can you please try this with the latest beta version, 0.6.1b1, which has an improvement to the history support so that it only calls the API to get the history if the state of any of the entities for which you have include_history set are changed.

Previously, a change in any state in Home Assistant (even ones you don't have in the feed card) could cause it to call the API.

PS: using this beta in the results above.

gadgetchnnel commented 3 years ago

@FragMenthor Have you tried clearing the browser cache after updating to the beta version? This is sometimes necessary to ensure you are running the latest version of the code.

If you have already tried that, can you please let me know:

redpizza69 commented 3 years ago

I've downloaded the beta (0.6.1b1) and it is a lot better. I still get a spike to around 100% cpu when the card loads, but it then falls back to normal. Previously it went a lot higher and then stayed high, so definitely an improvement but still not sure why I get the spike.

image

FragMenthor commented 3 years ago

Hello again! Answering to your questions:

Thanks for your great work!