From 8dc94f4d30a2c14e6de8ff121bd638a77c390ed5 Mon Sep 17 00:00:00 2001 From: golles Date: Mon, 2 Dec 2024 17:59:29 +0000 Subject: [PATCH] Make remaining time sensors numeric, for easier history tracking --- blueprints/automation/golles/awtrix_clock.yaml | 11 +++++++---- custom_templates/home_connect.jinja | 17 +++++------------ packages/home_connect.yaml | 12 +++++++++--- 3 files changed, 21 insertions(+), 19 deletions(-) diff --git a/blueprints/automation/golles/awtrix_clock.yaml b/blueprints/automation/golles/awtrix_clock.yaml index 8a00c54..9a9f2c3 100644 --- a/blueprints/automation/golles/awtrix_clock.yaml +++ b/blueprints/automation/golles/awtrix_clock.yaml @@ -10,6 +10,7 @@ blueprint: - Display informative apps, including: - Real-time room temperature. - External temperature with weather-dependent icons. + - Appliance remaining time. ### Weather Icons Get a variety of weather icons on your clock by running my [awtrix](https://github.com/golles/Home-Assistant-Config/blob/main/scripts/awtrix) script. @@ -172,10 +173,11 @@ actions: data: topic: "{{ topic }}/custom/dishwasher" payload: >- - {% if states(dishwasher_entity) not in ["unknown", "unavailable"] %} + {% set minutes = states(dishwasher_entity) %} + {% if minutes not in ["-1", "unknown", "unavailable"] %} {{ dict( - text = states(dishwasher_entity) | replace("minuten", ""), + text = iif(minutes == "0", "Klaar", minutes), icon = "dishwasher", ) }} @@ -186,10 +188,11 @@ actions: data: topic: "{{ topic }}/custom/washing_machine" payload: >- - {% if states(washing_machine_entity) not in ["unknown", "unavailable"] %} + {% set minutes = states(washing_machine_entity) %} + {% if minutes not in ["-1", "unknown", "unavailable"] %} {{ dict( - text = states(washing_machine_entity) | replace("minuten", ""), + text = iif(minutes == "0", "Klaar", minutes), icon = "washing_machine", ) }} diff --git a/custom_templates/home_connect.jinja b/custom_templates/home_connect.jinja index 27d6e44..cd200db 100644 --- a/custom_templates/home_connect.jinja +++ b/custom_templates/home_connect.jinja @@ -6,26 +6,19 @@ Params: powerstate_sensor: the power switch from the integration. Returns: - When the powerstate_sensor evaluates falsy the result will be `unavailable`. - When the time is not computable, it will also result in `unavailable`. - Else it will return `x minuten`, `1 minuut` or `klaar` + - When the powerstate_sensor evaluates falsy or the time is not computable, it will return `-1`. + - Otherwise, it returns the remaining time in minutes as an integer. #} {% macro remaining_time(remaining_program_time_sensor, powerstate_sensor) %} {% if states(powerstate_sensor) | lower in ["unknown", "unavailable", "off", "uit"] %} - unavailable + -1 {%- else -%} {% set end_time = states(remaining_program_time_sensor) %} {% if end_time in ["unknown", "unavailable"] %} - unavailable + -1 {% else %} {% set minutes = ((as_timestamp(end_time) - as_timestamp(now())) / 60) | int %} - {%- if minutes <= 0 -%} - Klaar - {%- elif minutes == 1 -%} - 1 minuut - {%- else -%} - {{ minutes }} minuten - {%- endif -%} + {{ minutes if minutes > 0 else 0 }} {% endif %} {% endif %} {% endmacro %} diff --git a/packages/home_connect.yaml b/packages/home_connect.yaml index 80d5456..6116481 100644 --- a/packages/home_connect.yaml +++ b/packages/home_connect.yaml @@ -10,6 +10,7 @@ template: "sensor.bosch_wawh2643nl_68a40e31630b_bsh_common_setting_powerstate" ) }} + unit_of_measurement: minuten - name: Vaatwasser resterende minuten icon: mdi:clock @@ -21,6 +22,7 @@ template: "sensor.bosch_sbv88tx36e_68a40e0cd8f6_bsh_common_setting_powerstate" ) }} + unit_of_measurement: minuten - name: Oven resterende minuten icon: mdi:clock @@ -32,6 +34,7 @@ template: "sensor.384090532720002735_001_bsh_common_setting_powerstate" ) }} + unit_of_measurement: minuten - name: Wasmachine status icon: mdi:washing-machine @@ -41,7 +44,8 @@ template: {% elif is_state("binary_sensor.bosch_wawh2643nl_68a40e31630b_bsh_common_status_doorstate", "on") -%} Deur open {% elif is_state("sensor.bosch_wawh2643nl_68a40e31630b_bsh_common_status_operationstate", "Loopt") -%} - {{ states("sensor.wasmachine_resterende_minuten") }} + {% set minuten = states("sensor.wasmachine_resterende_minuten") %} + {{ minuten ~ " " ~ iif(minuten == "1", "minuut", "minuten") }} {% elif is_state("binary_sensor.bosch_wawh2643nl_68a40e31630b_bsh_common_status_remotecontrolstartallowed", "on") -%} Uitgestelde start {%- else -%} @@ -85,7 +89,8 @@ template: {% elif is_state("binary_sensor.bosch_sbv88tx36e_68a40e0cd8f6_bsh_common_status_doorstate", "on") -%} Deur open {% elif is_state("sensor.bosch_sbv88tx36e_68a40e0cd8f6_bsh_common_status_operationstate", "Loopt") -%} - {{ states("sensor.vaatwasser_resterende_minuten") }} + {% set minuten = states("sensor.vaatwasser_resterende_minuten") %} + {{ minuten ~ " " ~ iif(minuten == "1", "minuut", "minuten") }} {% elif is_state("binary_sensor.bosch_sbv88tx36e_68a40e0cd8f6_bsh_common_status_remotecontrolstartallowed", "on") -%} Uitgestelde start {% elif is_state("switch.bosch_sbv88tx36e_68a40e0cd8f6_bsh_common_setting_powerstate", "off") -%} @@ -134,7 +139,8 @@ template: {% if is_state("sensor.oven_resterende_minuten", "unavailable") -%} {{ states("sensor.384090532720002735_001_bsh_common_status_operationstate") }} {%- else -%} - {{ states("sensor.oven_resterende_minuten") }} + {% set minuten = states("sensor.oven_resterende_minuten") %} + {{ minuten ~ " " ~ iif(minuten == "1", "minuut", "minuten") }} {%- endif %} {% elif states("sensor.384090532720002735_001_bsh_common_setting_powerstate") != "Aan" -%} off