From 6d69db1c732d7c39a93ac636ecdd0165fb599001 Mon Sep 17 00:00:00 2001 From: ildar170975 <71872483+ildar170975@users.noreply.github.com> Date: Sat, 8 Mar 2025 16:01:19 +0300 Subject: [PATCH] examples for "templating entities" --- README.md | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 56 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 943aab1..1e222df 100644 --- a/README.md +++ b/README.md @@ -82,8 +82,8 @@ card: icon: "${GARAGE_STATE === 'open' ? 'mdi:hotel' : '' }" ``` -### Templated entities example - +### Templated entities examples +Each entry of `entities` is a template: ```yaml type: 'custom:config-template-card' variables: @@ -95,6 +95,60 @@ card: entity: '${vars[0].entity_id}' name: "${vars[0].state === 'on' ? 'Light On' : 'Light Off'}" ``` +Whole `entities` array defined as a template: +```yaml +type: custom:config-template-card +variables: + ENTITIES: >- #filtering out a particular domain + Object.keys(states).filter( + k => k.startsWith('light') + ) +entities: &ref_entities ${ENTITIES} +card: + type: entities + entities: *ref_entities +``` +```yaml +type: custom:config-template-card +variables: + ENTITIES: >- #filtering out partial matches + Object.keys(states).filter( + k => ( + k.search('input_boolean.test_boolea*') != -1 + ) + ) +entities: &ref_entities ${ENTITIES} +card: + type: entities + entities: *ref_entities +``` +Concatenating entities: +```yaml +type: custom:config-template-card +variables: + ENTITIES_1: >- + Object.keys(states).filter( + k => ( + k.search('input_boolean.test_boolea*') != -1 + ) + ) + ENTITIES_2: >- + Object.keys(states).filter( + k => ( + k.search('input_number.test_number*') != -1 + ) + ) +entities: &ref_entities >- + ${ + ENTITIES_1.concat( + ENTITIES_2, + Array('input_select.test_select') + ) + } +card: + type: entities + entities: *ref_entities +``` ### Picture-elements card example