From 581808a1238aa4956c1a596c475c9d83ce1ec720 Mon Sep 17 00:00:00 2001 From: Edward Firmo <94725493+edwardtfn@users.noreply.github.com> Date: Sun, 17 Sep 2023 12:21:11 +0200 Subject: [PATCH] Don't send to Nextion obsolete volume settings If the volume is the same as the last one sent to the screen, don't send again, so if changes are being made on the screen it didn't receive the update all the time, making the slider unresponsive. --- nspanel_esphome.yaml | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/nspanel_esphome.yaml b/nspanel_esphome.yaml index 00b870e..b1692d9 100644 --- a/nspanel_esphome.yaml +++ b/nspanel_esphome.yaml @@ -824,8 +824,12 @@ api: // VOLUME_SET if (supported_features & 4) { - id(disp1).set_component_text_printf("vol_text", "%i%%", volume_level); - id(disp1).set_component_value("vol_slider", volume_level); + if (volume_level != id(last_volume_level)) + { + id(last_volume_level) = volume_level; + id(disp1).set_component_text_printf("vol_text", "%i%%", volume_level); + id(disp1).set_component_value("vol_slider", volume_level); + } id(disp1).show_component("vol_slider"); id(disp1).show_component("bt_vol_down"); id(disp1).show_component("bt_vol_up"); @@ -860,6 +864,12 @@ api: ##### START - GLOBALS CONFIGURATION ##### globals: + ###### Last volume level from Home Assistant ###### + - id: last_volume_level + type: int + restore_value: false + initial_value: '-1' + ###### Relay fallback even when buttons have other entities? ###### - id: relay_1_fallback type: bool @@ -1245,7 +1255,8 @@ text_sensor: on_value: then: - lambda: |- - if (x != "climate" and x != "cover" and x != "fan" and x != "light" and x != "media_player" and x != "confirm" and x != "keyb_num" ) id(entity_id) = ""; + if (x != "climate" and x != "cover" and x != "fan" and x != "light" and x != "media_player" and x != "confirm" and x != "keyb_num") id(entity_id) = ""; + if (x != "media_player") id(last_volume_level) = -1; ESP_LOGD("text_sensor.current_page", "New page: %s", x.c_str()); if (!id(entity_id).empty()) ESP_LOGD("text_sensor.current_page", "Entity shown: %s", id(entity_id).c_str()); id(timer_reset_all).execute(x.c_str());