Closed swiergot closed 1 year ago
Seems a very promising feature! What we will be able to do is:
Define all global vars in a dedicated file - vars.yaml:
variables:
GLOB_VAR_1: xxxxxxxxxxxx
GLOB_VAR_2: xxxxxxxxxxxx
Use these vars in every dashboard:
title: My dashboard 1
config_template_card: !include vars.yaml
views:
...
title: My dashboard 2
config_template_card: !include vars.yaml
views:
...
@ildar170975 Just checked, it's working as you said.
@swiergot Very great. Hope this PR will be merged! Thanks a lot for your addition, will start testing it.
@swiergot Could you provide a "js" file so I will replace it in my "community/config-template-card" folder? Wanna test your changes.
@ildar170975 Here it is:
The current usage for global var is:
title: My dashboard
config_template_card:
variables:
varSUN: states['sun.sun'].state
varSUN_ELEVATION: states['sun.sun'].attributes['elevation']
views:
...
Assume we have multiple dashboards in yaml mode. Then we may need to place the same "config_template_card" section in every dashboard file. Alternatively - me may define it like this for every dashboard:
title: My dashboard
config_template_card: !include my_vars.yaml
views:
...
where the my_vars.yaml
stores our vars:
variables:
varSUN: states['sun.sun'].state
varSUN_ELEVATION: states['sun.sun'].attributes['elevation']
But still we have to store ALL our vars in ONE file. Alternatively - we may keep all vars in a special subfolder in separate files:
title: My dashboard
config_template_card:
variables: !include_dir_merge_named config-template-card-vars/
views:
...
where config-template-card-vars
contains yaml files like this (kind of "config splitting"):
varSUN: states['sun.sun'].state
varSUN_ELEVATION: states['sun.sun'].attributes['elevation']
So far it works OK, thank you very much!
And we came to my proposal.
Next, assume we are using custom:decluttering-card
& custom:button-card
too - then our dashboard file looks like this:
title: My dashboard
decluttering_templates: !include_dir_merge_named templates-decluttering/
button_card_templates: !include_dir_merge_named templates-button-card/
config_template_card:
variables: !include_dir_merge_named config-template-card-vars/
views:
...
That is why I propose to omit the "variables" level; and we may rename the section to "config_template_card_vars". Then it will look like this:
title: My dashboard
decluttering_templates: !include_dir_merge_named templates-decluttering/
button_card_templates: !include_dir_merge_named templates-button-card/
config_template_card_vars: !include_dir_merge_named config-template-card-vars/
views:
...
What do you think?
Makes sense. I don't expect any other configuration than variables to end up there.
Great thanks! Started testing.
Strange, it does not work. A simple test in Lovelace storage mode:
config_template_card_vars:
varSUN: states['sun.sun'].state
type: custom:config-template-card
entities:
- sun.sun
card:
type: entities
title: ${varSUN}
entities:
- entity: sun.sun
This may simply be a cache issue.
First, if you have config-template-card.js.gz
in /config/www/local/config-template-card/
, make sure both .js
and .js.gz
are new versions.
Then try to open this in the web browser:
http://HA-HOST:8123/hacsfiles/config-template-card/config-template-card.js
I suspect it will be the old version. Press F5 to refresh. Then reload the dashboard.
This may simply be a cache issue.
Shame on me. You are absolutely right. Forgot to clear a cache. Cleared - works FINE.
make sure both
.js
and.js.gz
are new versions.
Have just "js" file. I copied "gz" file, then ran "gunzip xx.gz". It works anyway. AFAIK gz is needed as a backup.
I suspect it will be the old version
Checked it's content right after unzipping, found a desired "config_template_card_vars" keyword ))).
Thanks a lot once more! I am testing the plugin.
You're welcome. Thank you for testing and feedback.
Very cool! Looks great! Sorry for the delay, haven't been keeping up on my repos as of late.
If you need to use the same variable in multiple cards, then instead of defining it in each card's
variables
you can do that once for the entire dashboard.Both arrays and objects are supported, just like in card's local variables. It is allowed to mix the two types, i.e. use an array in dashboard variables and an object in card variables, or the other way around. If both definitions are arrays, then dashboard variables are put first in
vars
. In the mixed mode,vars
have array indices and as well as variable names.