iantrich / config-template-card

📝 Templatable Lovelace Configurations
MIT License
434 stars 56 forks source link

Auto refreshing of values raising exception #58

Closed deemonrider closed 7 months ago

deemonrider commented 3 years ago

Checklist:

Release with the issue:

Last working release (if known):

Browser and Operating System: Windows 10 (Edge, Chrome, Firefox) + Android (Home Assistant APP)

Description of problem: Auto refresh of values doesn't work (initial loading or f5 works). The lovelace entities are auto generated by https://github.com/thomasloven/lovelace-auto-entities

Javascript errors shown in the web inspector (if applicable):

Uncaught (in promise) TypeError: this._config.entities.forEach is not a function
    at HTMLElement.shouldUpdate (config-template-card.js:3290)
    at HTMLElement.performUpdate (config-template-card.js:2414)
    at HTMLElement._enqueueUpdate (config-template-card.js:2369)

Additional information:

Lovelace:

type: 'custom:auto-entities'
card:
  type: grid
  columns: 6
card_param: cards
filter:
  include:
    - entity_id: /sensor.server_/
      options:
        type: 'custom:config-template-card'
        entities: this.entity_id
        card:
          type: gauge
          entity: this.entity_id
          max: 100
deemonrider commented 3 years ago

this._config.entities:

image

deemonrider commented 3 years ago

My bad, entitites needed to be a list...

type: 'custom:auto-entities'
card:
  type: grid
  columns: 6
card_param: cards
filter:
  include:
    - entity_id: /sensor.server_/
      options:
        type: 'custom:config-template-card'
        entities: 
         - this.entity_id
        card:
          type: gauge
          entity: this.entity_id
          max: 100

But it still doesn't work as expected, is this template card tested with card-type: gauge? When receiving a new value the animation repeats like I refresh my browser. asddfas

iantrich commented 3 years ago

Have you tried this without auto-entities? No testing has been done with other custom cards.

deemonrider commented 3 years ago

I tired it without auto-entities, same result.

copy paste on my phone doesn't work but with the config below you get this result:

type: 'custom:config-template-card'
entities:
  - sensor.xy
card:
  type: gauge
  entity: sensor.xy
  min: 0
  max: 1000
iantrich commented 3 years ago

I am unable to replicate

deemonrider commented 3 years ago

Thats strange.

I reinstalled this card, cleared Cache and tried different browsers.

  - title: Testttttt
    path: testttttt
    badges: []
    cards:
      - type: 'custom:config-template-card'
        entities:
          - sensor.fritz_box_7590_packets_sent
        card:
          type: gauge
          entity: sensor.fritz_box_7590_packets_sent
          min: 0
          max: 100000000

asfasfasfasfafsf

Any idea what could lead to this behaviour? Im out of ideas

Veuchez commented 3 years ago

Have you found a solution? I think my problem #60 is the same as yours.

deemonrider commented 3 years ago

Nope, sorry. I have still no clue whats going on, this weird refreshes are really annyoing :/

iantrich commented 3 years ago

Good news, I figured out how to replicate this. Will see what can be done. Bad news, my dev environment is all messed up.

kamtschatka commented 3 years ago

Hi

I also had a look at this issue. Basically, when the state of a sensor changes, the Config-Template-Card will trigger a rerender, which will create a new gauge card. The standard behavior of the gauge card is to show this animation and that is why you are seeing this movement(basically the new gauge card is just going from 0 to this value)

I have a question though: Why do you need to use the template-card in the first place for this? The sample you provided can be done without the template as well:

type: custom:auto-entities
card:
  type: grid
  columns: 6
card_param: cards
filter:
  include:
    - entity_id: /sensor.server_/
      options:
        type: gauge
        entity: this.entity_id
        max: 100

Would be interesting to know where exactly you are using the template. I am using this card quite extensively and ran into the issue that recalculating the template is done quite often(basically with any state update), but once the basic templating is done, nothing is updating anymore. Basically I calculate the entity_id of some switches based on a sensor, replace somee strings to shorten them and that's it. There would not be the need to recalculate ANYTHING after that, and no change in the state of any sensor would change that. So I am thinking maybee you have the same usecase and it would be possible to just add a config to the card that would only ever update if the config changes?

fangguisheng commented 1 year ago

Hello, have you solved this problem? I also met it. How can I solve it?

StaleLoafOfBread commented 1 year ago

@kamtschatka Not OP but my use case is that I want the min, max, and name values to be based on attributes. I could make a workaround with helpers where min and max are 0 and 100 but the value is a new template calculating the percentage using the real min and max. The name I am still unsure of, could maybe use vertical stack and card mod to combine it with a markdown or title card.

Edit: I guess I also need to use card mod to hide the gauge's value

Edit 2: Got it (mostly) working with button-card and card-mod

type: custom:button-card
custom_fields:
  xp_gauge:
    card:
      type: gauge
      entity: sensor.xp
      needle: false
      max: '[[[ return states[''sensor.xp''].attributes.level_max ]]]'
      name: XP Meter
      min: '[[[ return states[''sensor.xp''].attributes.level_min ]]]'
      card_mod:
        style: |
          ha-card {
              border-width: 0;
          }
styles:
  grid:
    - grid-template-areas: '"xp_gauge"'

I say mostly because the name field has the same behavior but this is much closer and I can probably fix that with button card eventually by hiding the name completely via card mod and placing another text overlapping it.

FYI @deemonrider @fangguisheng

ildar170975 commented 7 months ago

Any idea what could lead to this behaviour? Im out of ideas

Explained here

ildar170975 commented 7 months ago

Closing the issue. A gauge behaviour is explained, there is nothing else here.