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

entities parameter does not accept variable #93

Open
2 tasks done
wrieden opened this issue Jan 1, 2022 · 3 comments · May be fixed by #153
Open
2 tasks done

entities parameter does not accept variable #93

wrieden opened this issue Jan 1, 2022 · 3 comments · May be fixed by #153
Labels
bug Something isn't working question Further information is requested

Comments

@wrieden
Copy link

wrieden commented Jan 1, 2022

Checklist:

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

Release with the issue: Master Branch
Last working release (if known): unknown
Browser and Operating System: chrome 96.0.4664.110, Win 11

Description of problem:

entity list based of variables is not working for me.
For example:

type: custom:config-template-card
variables:
  STATE_KEYS: Object.keys(states).filter(k => k.startsWith('sensor'))
entities: ${STATE_KEYS}

or

type: custom:config-template-card
variables:
  STATE_KEYS: Object.keys(states).filter(k => k.startsWith('sensor'))
entities: 
  - ${STATE_KEYS}

Additional information:

This seems to be an error with the shouldUpdate function, as the evaluation of the Variables is carried out too late.
I've made the following change locally, which solves the problem for me:

old:

 if (oldHass) {
    for (const entity of this._config.entities) {
      const evaluatedTemplate = this._evaluateTemplate(entity);
      if (Boolean(this.hass && oldHass.states[evaluatedTemplate] !== this.hass.states[evaluatedTemplate])) {
        return true;
      }
    }
    return false;
  }

new:

if (oldHass) {
    for (const entity of this._evaluateTemplate(this._config.entities)) {
        if (Boolean(this.hass && oldHass.states[entity] !== this.hass.states[entity])) {
            return true;
        }
    }
    return false;
}
@wrieden wrieden added the bug Something isn't working label Jan 1, 2022
@ildar170975
Copy link
Collaborator

ildar170975 commented Jan 16, 2024

@wrieden

  1. What happens if "entities" are not templated here? I.e. in case of a traditional list of entities.
for (const entity of this._evaluateTemplate(this._config.entities)) {
  1. Suggest you to create a PR for this proposal!

@ildar170975 ildar170975 added the question Further information is requested label Jan 16, 2024
@ildar170975
Copy link
Collaborator

Tested the proposed fix locally.
It causes constant flickering - even when a monitored entity is not changed.

type: custom:config-template-card
entities:
  - sun.sun
card:
  type: history-graph
  entities:
    - sun.sun

This card erratically flickering every several seconds.

PaulSD added a commit to PaulSD/config-template-card that referenced this issue Dec 23, 2024
@PaulSD PaulSD linked a pull request Dec 23, 2024 that will close this issue
@PaulSD
Copy link

PaulSD commented Dec 23, 2024

The problem here is that the change above only works if entities (as a whole) is a template; It does not work if entities is a list (that may or may not contain templates). Fixed in #153.

PaulSD added a commit to PaulSD/config-template-card that referenced this issue Dec 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working question Further information is requested
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants