config-template-card icon indicating copy to clipboard operation
config-template-card copied to clipboard

Auto refreshing of values raising exception

Open deemonrider opened this issue 3 years ago • 10 comments

Checklist:

  • [x] I updated to the latest version available
  • [x] I cleared the cache of my browser

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 avatar Jan 20 '21 14:01 deemonrider

this._config.entities:

image

deemonrider avatar Jan 20 '21 15:01 deemonrider

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

deemonrider avatar Jan 20 '21 19:01 deemonrider

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

iantrich avatar Jan 25 '21 20:01 iantrich

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

deemonrider avatar Jan 25 '21 20:01 deemonrider

I am unable to replicate

iantrich avatar Jan 27 '21 03:01 iantrich

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

deemonrider avatar Jan 29 '21 08:01 deemonrider

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

Veuchez avatar Feb 11 '21 21:02 Veuchez

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

deemonrider avatar Mar 04 '21 14:03 deemonrider

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

iantrich avatar Apr 29 '21 02:04 iantrich

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?

kamtschatka avatar Jun 06 '21 14:06 kamtschatka

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

fangguisheng avatar Dec 01 '22 13:12 fangguisheng

@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

StaleLoafOfBread avatar May 18 '23 05:05 StaleLoafOfBread

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

Explained here

ildar170975 avatar Jan 16 '24 03:01 ildar170975

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

ildar170975 avatar Jan 16 '24 03:01 ildar170975