You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat(config_tpl): Create a config template and use it everywhere with config_templates, apply the same config to every series with all_series_config and add color_list to define your color list in one shot (#64)
* Initial config templates support
* Display version in error card
* Update documentation
| `config_templates` | array | | NEXT_VERSION | Define a configuration once and reuse it multiple times. See [config_templates](#configuration-templates) |
129
+
| `color_list` | array | | NEXT_VERSION | Define the array of colors applied to the series. Will be overriden by each serie's color if defined. Usefull for `config_templates` mainly. |
130
+
| `all_series_config` | object | | NEXT_VERSION | If something is defined here it will apply this config to all the series. It accepts the same options as a serie minus `entity`. It is useful to avoid repetition but the same thing can be achieve in each serie individually. See [series](#series-options) and [all_series_config](#all_series_config-options) for an example |
| `update_interval` | string | | v1.1.0 | By default the card updates on every state change. Setting this overrides the behaviour. Valid values are any time string, eg: `1h`, `12min`, `1d`, `1h25`, `10sec`, ... |
127
133
| `update_delay` | string | `1500ms` | v1.4.0 | If the chart doesn't display the last state but the one before, you'll want to increase this value, don't go over `10s`, it's not necessary. You'll also want to increase this value if you are using `attribute` in the `series`. Valid values are any time strings. This is because of how Home-Assistant works with history, see [here](https://www.home-assistant.io/integrations/recorder/#commit_interval) |
@@ -411,7 +417,8 @@ This is how you could change some options from ApexCharts as described on the [`
411
417
412
418
Hundreds of options are available and it is not possible to describe them all here so check over there and ask on the [forum](https://community.home-assistant.io/t/apexcharts-card-a-highly-customizable-graph-card/272877) if you need help with using them.
413
419
414
-
Some options might not work in the context of this card.
420
+
* :warning: Some options might not work in the context of this card.
421
+
* :warning: Everything which is available through the default config of this card shouldn't be defined in `apex_config`. If you do, it might break.
415
422
416
423
```yaml
417
424
type: custom:apexcharts-card
@@ -434,6 +441,132 @@ For now, only `minimal` is supported: It will remove the grid, the axis and disp
434
441
435
442
For code junkies, you'll find the default options I use in [`src/apex-layouts.ts`](src/apex-layouts.ts)
436
443
444
+
### Configuration Templates
445
+
446
+
#### General
447
+
448
+
- Define your config template in the main lovelace configuration and then use it in your cards. This will avoid a lot of repetitions! It's basically YAML anchors, but without using YAML anchors and is very useful if you split your config in multiple files 😄
449
+
- You can overload any parameter with a new one
450
+
- Arrays will be merged by matching the index
451
+
- You can also inherit another template from within a template.
452
+
- You can inherit multiple templates at once by making it an array. In this case, the templates will be merged together with the current configuration in the order they are defined. This happens recursively.
453
+
454
+
```yaml
455
+
type: custom:apexcharts-card
456
+
config_templates:
457
+
- template1
458
+
- template2
459
+
# or
460
+
type: custom:apexcharts-card
461
+
config_templates: template1
462
+
```
463
+
464
+
The card templates will be applied in the order they are defined: `template2`will be merged with `template1` and then the local config will be merged with the result. You can still chain templates together (ie. define template in a apexcharts-card template. It will follow the path recursively).
465
+
466
+
Make sure which type of lovelace dashboard you are using before changing the main lovelace configuration:
467
+
* **`managed`** changes are managed by lovelace UI - add the template configuration to configuration in raw editor
468
+
* go to your dashboard
469
+
* click three dots and `Edit dashboard` button
470
+
* click three dots again and click `Raw configuration editor` button
471
+
* **`yaml`** - add template configuration to your dashboard file (`ui-lovelace.yaml` for eg.)
472
+
473
+
**Note:** Templates have to be defined in all dashboards, they are not shared.
474
+
475
+
To give you an idea where to put those (in your dashboard file/RAW editor):
476
+
```yaml
477
+
apexcharts_card_templates:
478
+
default:
479
+
color_list: ['red', 'green', 'blue']
480
+
481
+
bandwidth_chart:
482
+
graph_span: 24h
483
+
config_templates: default
484
+
header:
485
+
show: true
486
+
show_states: true
487
+
colorize_states: true
488
+
all_series_config:
489
+
stroke_width: 2
490
+
opacity: 0.3
491
+
type: area
492
+
493
+
views:
494
+
- title: Main
495
+
panel: true
496
+
cards:
497
+
[...]
498
+
```
499
+
500
+
And then where you define your card, you can consume those templates, and/or overload it:
501
+
502
+
```yaml
503
+
- type: custom:apexcharts-card
504
+
template: bandwidth_chart
505
+
header:
506
+
title: WAN Bandwidth
507
+
series:
508
+
- entity: sensor.wan_download
509
+
- entity: sensor.wan_upload
510
+
invert: true
511
+
```
512
+
513
+
In the end, this would produce the same result as but it's shorter and you can reuse that template elsewhere:
514
+
```yaml
515
+
- type: custom:apexcharts-card
516
+
graph_span: 24h
517
+
header:
518
+
title: WAN Bandwidth
519
+
show: true
520
+
show_states: true
521
+
colorize_states: true
522
+
all_series_config:
523
+
stroke_width: 2
524
+
opacity: 0.3
525
+
type: area
526
+
color_list: ['red', 'green', 'blue']
527
+
series:
528
+
- entity: sensor.wan_download
529
+
- entity: sensor.wan_upload
530
+
invert: true
531
+
```
532
+
533
+
#### `all_series_config` options
534
+
535
+
This will allow you to apply some settings to all the series avoiding repetition. It's just syntaxic sugar and doesn't add more features.
536
+
537
+
Eg:
538
+
```yaml
539
+
- type: custom:apexcharts-card
540
+
graph_span: 24h
541
+
all_series_config:
542
+
stroke_width: 2
543
+
type: area
544
+
transform: return x / 1024;
545
+
unit: Mb/s
546
+
series:
547
+
- entity: sensor.wan_download
548
+
- entity: sensor.wan_upload
549
+
invert: true
550
+
```
551
+
552
+
Generates the same result as repeating the configuration in each series:
553
+
```yaml
554
+
- type: custom:apexcharts-card
555
+
graph_span: 24h
556
+
series:
557
+
- entity: sensor.wan_download
558
+
stroke_width: 2
559
+
type: area
560
+
transform: return x / 1024;
561
+
unit: Mb/s
562
+
- entity: sensor.wan_upload
563
+
invert: true
564
+
stroke_width: 2
565
+
type: area
566
+
transform: return x / 1024;
567
+
unit: Mb/s
568
+
```
569
+
437
570
## Experimental features
438
571
439
572
:warning: You enter the danger zone :warning:
@@ -529,7 +662,7 @@ Not ordered by priority:
529
662
* [ ] Support for logarithmic
530
663
* [X] ~~Support for state mapping for non-numerical state sensors~~
531
664
* [X] ~~Support for simple color threshold (easier to understand/write than the ones provided natively by ApexCharts)~~
532
-
* [ ] Support for graph configuration templates à la [`button-card`](https://github.com/custom-cards/button-card/blob/master/README.md#configuration-templates)
665
+
* [X] ~~Support for graph configuration templates à la [`button-card`](https://github.com/custom-cards/button-card/blob/master/README.md#configuration-templates)~~
533
666
534
667
## Examples
535
668
@@ -636,10 +769,8 @@ series:
636
769
```yaml
637
770
type: custom:apexcharts-card
638
771
graph_span: 1d
639
-
apex_config:
640
-
stroke:
641
-
# Will affect all the series
642
-
width: 2
772
+
all_series_config:
773
+
stroke_width: 2
643
774
series:
644
775
- entity: sensor.temperature
645
776
- entity: sensor.humidity
@@ -650,15 +781,11 @@ series:
650
781
```yaml
651
782
type: custom:apexcharts-card
652
783
graph_span: 1d
653
-
apex_config:
654
-
stroke:
655
-
# 2 will affect sensor.temperature
656
-
# 4 will affect sensor.humidity
657
-
# You need as much values here as the number of series
0 commit comments