e.g. apexcharts-card has the statistics option which allows you to read data from the statistics table.
But it cannot be enabled/disabled.
That means you have to remove all related options or the cards won’t work.
So I was thinking about whether it is possible to add/remove a properly indented block of options using javascript/templating.
That way any card could be made functional even with options that would normally break a card if they are undefined (but would not be as desired if the options were defined at all times)
The stock cards are almost all very basic in the available options. So name any card and I will try to explain better.
Let’s take a button-card (not the ideal example).
Depending on the entity (sourced from an input_select) you either want to have a hold action or not (“toggle2” is a placeholder name).
- type: button
tap_action:
action: toggle
hold_action:
action: toggle2
entity: { template get from input_select }
If you remove the “toggle2” from action: toggle2 the card stops working. You have to remove the key plus the parent hold_action also.
But you want to be able to switch between having a hold_action and not having one without having to create two separate cards.
So you need to be able to add & remove the code block
hold_action:
action: toggle2
using templating/javascript somehow. And it needs to have the correct indentation also, otherwise the card will not work either.
type: custom:decluttering-card
template: my_graph_card
variables:
...
- COLOR_THRESHOLDS:
... your settings (a list; for other option may be a dictionary), like:
- xxx: yyy
abc: bbb
- xxx: yyy_2
abc: bbb_2
or
type: custom:decluttering-card
template: my_graph_card
variables:
... w/o specifying color thresholds - i.e. a default value is used
And similarly may be done with “tap_action” etc: when calling a template you specify a required set of options (dict or list). Here you are not using config-template-card since all required options are either specified by default or specified by a user.
Is it close to what you need?
Is there a way to use templating in the entities selection already?
I am facing the problem that two entities (input_datetime) keep making my card reload because the value changes every minute. The card itself should be ignoring this change as it is part of an if statement that is not ‘true’.
So I think the problem is, that the config-template-card is monitoring the input_datetime and causes a reload of the card with the new state.
I would like to prevent this, if the input_booleans are both true.
type: custom:config-template-card
entities:
- input_select.dropdown_wildcards
- input_select.dropdown_entities
- input_select.dropdown_areas
- input_select.dropdown_types
- input_boolean.end_datetime_now
- input_boolean.start_datetime_24h
- input_datetime.start_datetime # only if input_boolean.start_datetime_24h returns 'true'
- input_datetime.end_datetime # only if input_boolean.end_datetime_now returns 'true'
If that were possible somehow, it would prevent the regular reloading.
When I replace the actual entity by (what the result should be) input_number.piek_afname_12, and the card is showing.
So something is going wrong when creating the entity from the variables.
This has been working for half a year or so, and (when I remember correct) stopped working about 2 months ago.