From 1ad66998380e264c29e9b1db1a0e0335466b04bf Mon Sep 17 00:00:00 2001 From: Georgi Gardev Date: Fri, 1 May 2020 17:05:36 +0300 Subject: [PATCH] Make state_indicator_id optional - default to entity_id --- .../with_state_indicator_button.yaml | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/config/lovelace/button_card_templates/with_state_indicator_button.yaml b/config/lovelace/button_card_templates/with_state_indicator_button.yaml index 1ce9f17..d32691c 100644 --- a/config/lovelace/button_card_templates/with_state_indicator_button.yaml +++ b/config/lovelace/button_card_templates/with_state_indicator_button.yaml @@ -13,7 +13,7 @@ with_state_indicator: action: call-service service: homeassistant.toggle service_data: - entity_id: "[[[ return variables.state_indicator_id ]]]" + entity_id: "[[[ return variables.state_indicator_id || entity ]]]" styles: name: - transform: "[[[ return 'translateY(' + variables.state_indicator_size + ')' ]]]" @@ -21,15 +21,18 @@ with_state_indicator: - border-bottom: >- [[[ let color; + const state_indicator = (!variables.state_indicator_id) + ? entity.entity_id + : variables.state_indicator_id; if (entity.state === 'on') { - color = states[variables.state_indicator_id].state === 'on' - ? variables.state_on_indicator_on_color - : variables.state_on_indicator_off_color; + color = states[state_indicator].state === 'on' + ? variables.state_on_indicator_on_color + : variables.state_on_indicator_off_color; } else { - color = states[variables.state_indicator_id].state === 'on' - ? variables.state_indicator_on_color - : variables.state_indicator_off_color; + color = states[state_indicator].state === 'on' + ? variables.state_indicator_on_color + : variables.state_indicator_off_color; } return variables.state_indicator_size + ' solid ' + color;