From f486a2c86821aea9ca85203c0eec7d6d133b3174 Mon Sep 17 00:00:00 2001 From: mymyke Date: Mon, 5 Feb 2024 22:44:27 +0100 Subject: [PATCH] Update Templates.md Round function added the brightness display part of content to correct off-by-one errors. For example, setting brightnes to 30% would previously show 29% and now shows 30% --- examples/Templates.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/Templates.md b/examples/Templates.md index ed5fdc5..dbcecb9 100644 --- a/examples/Templates.md +++ b/examples/Templates.md @@ -115,13 +115,13 @@ An example of a dimmer light with 4 brightness settings 0..3. Here our light wor "entity": "light.green_house", "name": "LEDs", "type": "template", - "content": "{% if not (is_state('light.green_house', 'off') or is_state('light.green_house', 'unavailable')) %}{{ ((state_attr('light.green_house', 'brightness') | float) / 255 * 100) | int }}%{% else %}Off{% endif %}" + "content": "{% if not (is_state('light.green_house', 'off') or is_state('light.green_house', 'unavailable')) %}{{ (((state_attr('light.green_house', 'brightness') | float) / 255 * 100)|round(0) ) | int }}%{% else %}Off{% endif %}" }, { "entity": "light.green_house", "name": "LEDs 0", "type": "template", - "content": "{% if not (is_state('light.green_house', 'off') or is_state('light.green_house', 'unavailable')) %}{{ ((state_attr('light.green_house', 'brightness') | float) / 255 * 100) | int }}%{% else %}Off{% endif %}", + "content": "{% if not (is_state('light.green_house', 'off') or is_state('light.green_house', 'unavailable')) %}{{ (((state_attr('light.green_house', 'brightness') | float) / 255 * 100)|round(0) ) | int }}%{% else %}Off{% endif %}", "tap_action": { "service": "light.turn_on", "data": { @@ -144,7 +144,7 @@ An example of a dimmer light with 4 brightness settings 0..3. Here our light wor "entity": "light.green_house", "name": "LEDs 2", "type": "template", - "content": "{% if not (is_state('light.green_house', 'off') or is_state('light.green_house', 'unavailable')) %}{{ ((state_attr('light.green_house', 'brightness') | float) / 255 * 100) | int }}%{% else %}Off{% endif %}", + "content": "{% if not (is_state('light.green_house', 'off') or is_state('light.green_house', 'unavailable')) %}{{ (((state_attr('light.green_house', 'brightness') | float) / 255 * 100)|round(0) ) | int }}%{% else %}Off{% endif %}", "tap_action": { "service": "light.turn_on", "data": { @@ -156,7 +156,7 @@ An example of a dimmer light with 4 brightness settings 0..3. Here our light wor "entity": "light.green_house", "name": "LEDs 3", "type": "template", - "content": "{% if not (is_state('light.green_house', 'off') or is_state('light.green_house', 'unavailable')) %}{{ ((state_attr('light.green_house', 'brightness') | float) / 255 * 100) | int }}%{% else %}Off{% endif %}", + "content": "{% if not (is_state('light.green_house', 'off') or is_state('light.green_house', 'unavailable')) %}{{ (((state_attr('light.green_house', 'brightness') | float) / 255 * 100) |round(0) )| int }}%{% else %}Off{% endif %}", "tap_action": { "service": "light.turn_on", "data": {