From 796968122b70514ab505348c4a20a0268475b9b8 Mon Sep 17 00:00:00 2001 From: Edward Firmo <94725493+edwardtfn@users.noreply.github.com> Date: Sun, 10 Sep 2023 12:56:15 +0200 Subject: [PATCH] Fix pages not updating values Solves #1026 --- nspanel_blueprint.yaml | 188 +++++++++++++++++++++++++++++------------ nspanel_esphome.yaml | 63 +++++++++++++- 2 files changed, 194 insertions(+), 57 deletions(-) diff --git a/nspanel_blueprint.yaml b/nspanel_blueprint.yaml index bbfcfaa..123a41a 100644 --- a/nspanel_blueprint.yaml +++ b/nspanel_blueprint.yaml @@ -575,7 +575,7 @@ blueprint: description: > *CLIMATE page* - *Entity which should be switched (ONLY light | switch | cover | input_boolean | automation | button | input_button | scene | person | script | binary_sensor | fan | climate)* + *Entity which should be switched (ONLY light | switch | cover | input_boolean | automation | button | input_button | scene | person | script | binary_sensor | fan | climate | media_player)* default: [] selector: &climate-custom-button-entity-selector entity: @@ -625,7 +625,7 @@ blueprint: description: > *CLIMATE page* - *Entity which should be switched (ONLY light | switch | cover | input_boolean | automation | button | input_button | scene | person | script | binary_sensor | fan | climate)* + *Entity which should be switched (ONLY light | switch | cover | input_boolean | automation | button | input_button | scene | person | script | binary_sensor | fan | climate | media_player)* default: [] selector: *climate-custom-button-entity-selector climate_button09_icon: @@ -869,6 +869,7 @@ blueprint: - scene - script - fan + - madia_player left_button_name: name: Left hardware button name - LABEL (Optional) description: > @@ -977,7 +978,7 @@ blueprint: description: > *ButtonPage01* - *Entity which should be switched (ONLY light | switch | cover | input_boolean | automation | button | input_button | scene | person | script | binary_sensor | fan | climate)* + *Entity which should be switched (ONLY light | switch | cover | input_boolean | automation | button | input_button | scene | person | script | binary_sensor | fan | climate | media_player)* default: [] selector: &button-entity-selector entity: @@ -996,6 +997,7 @@ blueprint: - binary_sensor - fan - climate + - media_player entity01_name: name: Button 01 name - LABEL (Optional) description: > @@ -1035,7 +1037,7 @@ blueprint: description: > *ButtonPage01* - *Entity which should be switched (ONLY light | switch | cover | input_boolean | automation | button | input_button | scene | person | script | binary_sensor | fan | climate)* + *Entity which should be switched (ONLY light | switch | cover | input_boolean | automation | button | input_button | scene | person | script | binary_sensor | fan | climate | media_player)* default: [] selector: *button-entity-selector entity02_name: @@ -1077,7 +1079,7 @@ blueprint: description: > *ButtonPage01* - *Entity which should be switched (ONLY light | switch | cover | input_boolean | automation | button | input_button | scene | person | script | binary_sensor | fan | climate)* + *Entity which should be switched (ONLY light | switch | cover | input_boolean | automation | button | input_button | scene | person | script | binary_sensor | fan | climate | media_player)* default: [] selector: *button-entity-selector entity03_name: @@ -1119,7 +1121,7 @@ blueprint: description: > *ButtonPage01* - *Entity which should be switched (ONLY light | switch | cover | input_boolean | automation | button | input_button | scene | person | script | binary_sensor | fan | climate)* + *Entity which should be switched (ONLY light | switch | cover | input_boolean | automation | button | input_button | scene | person | script | binary_sensor | fan | climate | media_player)* default: [] selector: *button-entity-selector entity04_name: @@ -1161,7 +1163,7 @@ blueprint: description: > *ButtonPage01* - *Entity which should be switched (ONLY light | switch | cover | input_boolean | automation | button | input_button | scene | person | script | binary_sensor | fan | climate)* + *Entity which should be switched (ONLY light | switch | cover | input_boolean | automation | button | input_button | scene | person | script | binary_sensor | fan | climate | media_player)* default: [] selector: *button-entity-selector entity05_name: @@ -1203,7 +1205,7 @@ blueprint: description: > *ButtonPage01* - *Entity which should be switched (ONLY light | switch | cover | input_boolean | automation | button | input_button | scene | person | script | binary_sensor | fan | climate)* + *Entity which should be switched (ONLY light | switch | cover | input_boolean | automation | button | input_button | scene | person | script | binary_sensor | fan | climate | media_player)* default: [] selector: *button-entity-selector entity06_name: @@ -1245,7 +1247,7 @@ blueprint: description: > *ButtonPage01* - *Entity which should be switched (ONLY light | switch | cover | input_boolean | automation | button | input_button | scene | person | script | binary_sensor | fan | climate)* + *Entity which should be switched (ONLY light | switch | cover | input_boolean | automation | button | input_button | scene | person | script | binary_sensor | fan | climate | media_player)* default: [] selector: *button-entity-selector entity07_name: @@ -1287,7 +1289,7 @@ blueprint: description: > *ButtonPage01* - *Entity which should be switched (ONLY light | switch | cover | input_boolean | automation | button | input_button | scene | person | script | binary_sensor | fan | climate)* + *Entity which should be switched (ONLY light | switch | cover | input_boolean | automation | button | input_button | scene | person | script | binary_sensor | fan | climate | media_player)* default: [] selector: *button-entity-selector entity08_name: @@ -1346,7 +1348,7 @@ blueprint: description: > *ButtonPage02* - *Entity which should be switched (ONLY light | switch | cover | input_boolean | automation | button | input_button | scene | person | script | binary_sensor | fan | climate)* + *Entity which should be switched (ONLY light | switch | cover | input_boolean | automation | button | input_button | scene | person | script | binary_sensor | fan | climate | media_player)* default: [] selector: *button-entity-selector entity09_name: @@ -1388,7 +1390,7 @@ blueprint: description: > *ButtonPage02* - *Entity which should be switched (ONLY light | switch | cover | input_boolean | automation | button | input_button | scene | person | script | binary_sensor | fan | climate)* + *Entity which should be switched (ONLY light | switch | cover | input_boolean | automation | button | input_button | scene | person | script | binary_sensor | fan | climate | media_player)* default: [] selector: *button-entity-selector entity10_name: @@ -1430,7 +1432,7 @@ blueprint: description: > *ButtonPage02* - *Entity which should be switched (ONLY light | switch | cover | input_boolean | automation | button | input_button | scene | person | script | binary_sensor | fan | climate)* + *Entity which should be switched (ONLY light | switch | cover | input_boolean | automation | button | input_button | scene | person | script | binary_sensor | fan | climate | media_player)* default: [] selector: *button-entity-selector entity11_name: @@ -1472,7 +1474,7 @@ blueprint: description: > *ButtonPage02* - *Entity which should be switched (ONLY light | switch | cover | input_boolean | automation | button | input_button | scene | person | script | binary_sensor | fan | climate)* + *Entity which should be switched (ONLY light | switch | cover | input_boolean | automation | button | input_button | scene | person | script | binary_sensor | fan | climate | media_player)* default: [] selector: *button-entity-selector entity12_name: @@ -1514,7 +1516,7 @@ blueprint: description: > *ButtonPage02* - *Entity which should be switched (ONLY light | switch | cover | input_boolean | automation | button | input_button | scene | person | script | binary_sensor | fan | climate)* + *Entity which should be switched (ONLY light | switch | cover | input_boolean | automation | button | input_button | scene | person | script | binary_sensor | fan | climate | media_player)* default: [] selector: *button-entity-selector entity13_name: @@ -1556,7 +1558,7 @@ blueprint: description: > *ButtonPage02* - *Entity which should be switched (ONLY light | switch | cover | input_boolean | automation | button | input_button | scene | person | script | binary_sensor | fan | climate)* + *Entity which should be switched (ONLY light | switch | cover | input_boolean | automation | button | input_button | scene | person | script | binary_sensor | fan | climate | media_player)* default: [] selector: *button-entity-selector entity14_name: @@ -1598,7 +1600,7 @@ blueprint: description: > *ButtonPage02* - *Entity which should be switched (ONLY light | switch | cover | input_boolean | automation | button | input_button | scene | person | script | binary_sensor | fan | climate)* + *Entity which should be switched (ONLY light | switch | cover | input_boolean | automation | button | input_button | scene | person | script | binary_sensor | fan | climate | media_player)* default: [] selector: *button-entity-selector entity15_name: @@ -1640,7 +1642,7 @@ blueprint: description: > *ButtonPage02* - *Entity which should be switched (ONLY light | switch | cover | input_boolean | automation | button | input_button | scene | person | script | binary_sensor | fan | climate)* + *Entity which should be switched (ONLY light | switch | cover | input_boolean | automation | button | input_button | scene | person | script | binary_sensor | fan | climate | media_player)* default: [] selector: *button-entity-selector entity16_name: @@ -1699,7 +1701,7 @@ blueprint: description: > *ButtonPage03* - *Entity which should be switched (ONLY light | switch | cover | input_boolean | automation | button | input_button | scene | person | script | binary_sensor | fan | climate)* + *Entity which should be switched (ONLY light | switch | cover | input_boolean | automation | button | input_button | scene | person | script | binary_sensor | fan | climate | media_player)* default: [] selector: *button-entity-selector entity17_name: @@ -1741,7 +1743,7 @@ blueprint: description: > *ButtonPage03* - *Entity which should be switched (ONLY light | switch | cover | input_boolean | automation | button | input_button | scene | person | script | binary_sensor | fan | climate)* + *Entity which should be switched (ONLY light | switch | cover | input_boolean | automation | button | input_button | scene | person | script | binary_sensor | fan | climate | media_player)* default: [] selector: *button-entity-selector entity18_name: @@ -1783,7 +1785,7 @@ blueprint: description: > *ButtonPage03* - *Entity which should be switched (ONLY light | switch | cover | input_boolean | automation | button | input_button | scene | person | script | binary_sensor | fan | climate)* + *Entity which should be switched (ONLY light | switch | cover | input_boolean | automation | button | input_button | scene | person | script | binary_sensor | fan | climate | media_player)* default: [] selector: *button-entity-selector entity19_name: @@ -1825,7 +1827,7 @@ blueprint: description: > *ButtonPage03* - *Entity which should be switched (ONLY light | switch | cover | input_boolean | automation | button | input_button | scene | person | script | binary_sensor | fan | climate)* + *Entity which should be switched (ONLY light | switch | cover | input_boolean | automation | button | input_button | scene | person | script | binary_sensor | fan | climate | media_player)* default: [] selector: *button-entity-selector entity20_name: @@ -1867,7 +1869,7 @@ blueprint: description: > *ButtonPage03* - *Entity which should be switched (ONLY light | switch | cover | input_boolean | automation | button | input_button | scene | person | script | binary_sensor | fan | climate)* + *Entity which should be switched (ONLY light | switch | cover | input_boolean | automation | button | input_button | scene | person | script | binary_sensor | fan | climate | media_player)* default: [] selector: *button-entity-selector entity21_name: @@ -1909,7 +1911,7 @@ blueprint: description: > *ButtonPage03* - *Entity which should be switched (ONLY light | switch | cover | input_boolean | automation | button | input_button | scene | person | script | binary_sensor | fan | climate)* + *Entity which should be switched (ONLY light | switch | cover | input_boolean | automation | button | input_button | scene | person | script | binary_sensor | fan | climate | media_player)* default: [] selector: *button-entity-selector entity22_name: @@ -1951,7 +1953,7 @@ blueprint: description: > *ButtonPage03* - *Entity which should be switched (ONLY light | switch | cover | input_boolean | automation | button | input_button | scene | person | script | binary_sensor | fan | climate)* + *Entity which should be switched (ONLY light | switch | cover | input_boolean | automation | button | input_button | scene | person | script | binary_sensor | fan | climate | media_player)* default: [] selector: *button-entity-selector entity23_name: @@ -1993,7 +1995,7 @@ blueprint: description: > *ButtonPage03* - *Entity which should be switched (ONLY light | switch | cover | input_boolean | automation | button | input_button | scene | person | script | binary_sensor | fan | climate)* + *Entity which should be switched (ONLY light | switch | cover | input_boolean | automation | button | input_button | scene | person | script | binary_sensor | fan | climate | media_player)* default: [] selector: *button-entity-selector entity24_name: @@ -2052,7 +2054,7 @@ blueprint: description: > *ButtonPage04* - *Entity which should be switched (ONLY light | switch | cover | input_boolean | automation | button | input_button | scene | person | script | binary_sensor | fan | climate)* + *Entity which should be switched (ONLY light | switch | cover | input_boolean | automation | button | input_button | scene | person | script | binary_sensor | fan | climate | media_player)* default: [] selector: *button-entity-selector entity25_name: @@ -2094,7 +2096,7 @@ blueprint: description: > *ButtonPage04* - *Entity which should be switched (ONLY light | switch | cover | input_boolean | automation | button | input_button | scene | person | script | binary_sensor | fan | climate)* + *Entity which should be switched (ONLY light | switch | cover | input_boolean | automation | button | input_button | scene | person | script | binary_sensor | fan | climate | media_player)* default: [] selector: *button-entity-selector entity26_name: @@ -2136,7 +2138,7 @@ blueprint: description: > *ButtonPage04* - *Entity which should be switched (ONLY light | switch | cover | input_boolean | automation | button | input_button | scene | person | script | binary_sensor | fan | climate)* + *Entity which should be switched (ONLY light | switch | cover | input_boolean | automation | button | input_button | scene | person | script | binary_sensor | fan | climate | media_player)* default: [] selector: *button-entity-selector entity27_name: @@ -2178,7 +2180,7 @@ blueprint: description: > *ButtonPage04* - *Entity which should be switched (ONLY light | switch | cover | input_boolean | automation | button | input_button | scene | person | script | binary_sensor | fan | climate)* + *Entity which should be switched (ONLY light | switch | cover | input_boolean | automation | button | input_button | scene | person | script | binary_sensor | fan | climate | media_player)* default: [] selector: *button-entity-selector entity28_name: @@ -2220,7 +2222,7 @@ blueprint: description: > *ButtonPage04* - *Entity which should be switched (ONLY light | switch | cover | input_boolean | automation | button | input_button | scene | person | script | binary_sensor | fan | climate)* + *Entity which should be switched (ONLY light | switch | cover | input_boolean | automation | button | input_button | scene | person | script | binary_sensor | fan | climate | media_player)* default: [] selector: *button-entity-selector entity29_name: @@ -2262,7 +2264,7 @@ blueprint: description: > *ButtonPage04* - *Entity which should be switched (ONLY light | switch | cover | input_boolean | automation | button | input_button | scene | person | script | binary_sensor | fan | climate)* + *Entity which should be switched (ONLY light | switch | cover | input_boolean | automation | button | input_button | scene | person | script | binary_sensor | fan | climate | media_player)* default: [] selector: *button-entity-selector entity30_name: @@ -2304,7 +2306,7 @@ blueprint: description: > *ButtonPage04* - *Entity which should be switched (ONLY light | switch | cover | input_boolean | automation | button | input_button | scene | person | script | binary_sensor | fan | climate)* + *Entity which should be switched (ONLY light | switch | cover | input_boolean | automation | button | input_button | scene | person | script | binary_sensor | fan | climate | media_player)* default: [] selector: *button-entity-selector entity31_name: @@ -2346,7 +2348,7 @@ blueprint: description: > *ButtonPage04* - *Entity which should be switched (ONLY light | switch | cover | input_boolean | automation | button | input_button | scene | person | script | binary_sensor | fan | climate)* + *Entity which should be switched (ONLY light | switch | cover | input_boolean | automation | button | input_button | scene | person | script | binary_sensor | fan | climate | media_player)* default: [] selector: *button-entity-selector entity32_name: @@ -3527,6 +3529,7 @@ variables: #font_color: 'esphome.{{ nspanel_name }}_send_command_font_color' global_settings: 'esphome.{{ nspanel_name }}_global_settings' hide: 'esphome.{{ nspanel_name }}_send_command_hide' + media_player: 'esphome.{{ nspanel_name }}_media_player' notification_clear: 'esphome.{{ nspanel_name }}_notification_clear' #notification_show: 'esphome.{{ nspanel_name }}_notification_show' open_entity_settings_page: 'esphome.{{ nspanel_name }}_open_entity_settings_page' @@ -3625,6 +3628,8 @@ variables: - "entitypage04" alarm: "alarm" keyb_num: "keyb_num" + madia_player: "media_player" + confirm: "confirm" ##### MUI Multilingual User Interface ##### language_tmp: !input 'language' @@ -6997,7 +7002,8 @@ action: sequence: &refresh_page_buttonpage - &variables-page_buttons variables: - button_page_index: '{{ (nspanel_event.page[-2:] | int(-1)) - 1 }}' + event_page: '{{ nspanel_event.page if nspanel_event is defined and nspanel_event.page is defined else page.current }}' + button_page_index: '{{ (event_page[-2:] | int(-1)) - 1 }}' first_button: '{{ button_page_index * 8 }}' last_button: '{{ first_button + 8 }}' ##### BUTTON Page Labels ##### @@ -7393,7 +7399,8 @@ action: conditions: '{{ nspanel_event.page == page.light }}' sequence: &refresh_page_light - variables: - supported_color_modes: '{{ state_attr(nspanel_event.entity, "supported_color_modes") | default("unknown") }}' + light_entity: '{{ nspanel_event.entity if nspanel_event is defined and nspanel_event.entity is defined else trigger.entity_id }}' + supported_color_modes: '{{ state_attr(light_entity, "supported_color_modes") | default("unknown") }}' color_mode_color: > {{ "hs" in supported_color_modes @@ -7412,7 +7419,7 @@ action: # }} ##### LIGHT State ##### - variables: - curr_brightness: '{{ (state_attr(nspanel_event.entity, "brightness") | int(0) * 100 / 255) | round(0) }}' + curr_brightness: '{{ (state_attr(light_entity, "brightness") | int(0) * 100 / 255) | round(0) }}' - *delay-default - service: '{{ nextion.command.value }}' data: @@ -7436,9 +7443,9 @@ action: - if: '{{ color_mode_color_temp }}' then: - variables: - curr_color_temp: '{{ state_attr(nspanel_event.entity, "color_temp") | int(-1) }}' - min_mireds: '{{ state_attr(nspanel_event.entity, "min_mireds") | int(153) }}' - max_mireds: '{{ state_attr(nspanel_event.entity, "max_mireds") | int(500) }}' + curr_color_temp: '{{ state_attr(light_entity, "color_temp") | int(-1) }}' + min_mireds: '{{ state_attr(light_entity, "min_mireds") | int(153) }}' + max_mireds: '{{ state_attr(light_entity, "max_mireds") | int(500) }}' - variables: curr_color_temp: > {{ @@ -7509,25 +7516,27 @@ action: - alias: Cover settings page conditions: '{{ nspanel_event.page == page.cover }}' sequence: &refresh_page_cover + - variables: + cover_entity: '{{ nspanel_event.entity if nspanel_event is defined and nspanel_event.entity is defined else trigger.entity_id }}' ##### COVER State - service: '{{ nextion.command.value }}' data: component: cover.coverslider - message: '{{ (state_attr(nspanel_event.entity, "current_position") | int ) | round(0) }}' + message: '{{ (state_attr(cover_entity, "current_position") | int ) | round(0) }}' continue_on_error: true - *delay-default - service: '{{ nextion.command.text_printf }}' data: component: cover.cover_value - message: '{{ (state_attr(nspanel_event.entity, "current_position") | int ) | round(0) }} %' + message: '{{ (state_attr(cover_entity, "current_position") | int ) | round(0) }} %' continue_on_error: true ##### COVER Battery ICON Yes / NO ##### - variables: battery_level: > - {% if state_attr(nspanel_event.entity, "battery") | default("unavailable") not in ["unavailable", "unknown", "", None] %} - {{ state_attr(nspanel_event.entity, "battery") | default("unavailable") }} - {% elif expand(device_entities(device_id(nspanel_event.entity))) + {% if state_attr(cover_entity, "battery") | default("unavailable") not in ["unavailable", "unknown", "", None] %} + {{ state_attr(cover_entity, "battery") | default("unavailable") }} + {% elif expand(device_entities(device_id(cover_entity))) | selectattr("attributes.device_class", "defined") | selectattr("attributes.device_class", "eq", "battery") | map(attribute="state") @@ -7535,7 +7544,7 @@ action: | list | count > 0 %} {{ - expand(device_entities(device_id(nspanel_event.entity))) + expand(device_entities(device_id(cover_entity))) | selectattr("attributes.device_class", "defined") | selectattr("attributes.device_class", "eq", "battery") | map(attribute="state") | map("float") @@ -7543,10 +7552,10 @@ action: | first | round(0) }} - {% elif has_value(nspanel_event.entity | replace("cover.","sensor.") ~ "_battery") %} - {{ states(nspanel_event.entity | replace("cover.","sensor.") ~ "_battery", rounded=true) | default("unavailable") }} - {% elif has_value(nspanel_event.entity | replace("cover.","sensor.") | replace("cover", "battery")) %} - {{ states(nspanel_event.entity | replace("cover.","sensor.") | replace("cover", "battery"), rounded=true) | default("unavailable") }} + {% elif has_value(cover_entity | replace("cover.","sensor.") ~ "_battery") %} + {{ states(cover_entity | replace("cover.","sensor.") ~ "_battery", rounded=true) | default("unavailable") }} + {% elif has_value(cover_entity | replace("cover.","sensor.") | replace("cover", "battery")) %} + {{ states(cover_entity | replace("cover.","sensor.") | replace("cover", "battery"), rounded=true) | default("unavailable") }} {% else %} unavailable {% endif %} - if: '{{ is_number(battery_level) }}' @@ -7578,16 +7587,17 @@ action: conditions: '{{ nspanel_event.page == page.fan }}' sequence: &refresh_page_fan - variables: + fan_entity: '{{ nspanel_event.entity if nspanel_event is defined and nspanel_event.entity is defined else trigger.entity_id }}' fan: - supported_features: '{{ state_attr(nspanel_event.entity, "supported_features") | int(0) }}' + supported_features: '{{ state_attr(fan_entity, "supported_features") | int(0) }}' percentage: > {{ - state_attr(nspanel_event.entity, "percentage") | int(0) - if is_state(nspanel_event.entity, 'on') + state_attr(fan_entity, "percentage") | int(0) + if is_state(fan_entity, 'on') else 0 }} steps: > - {% set percentage_step = state_attr(nspanel_event.entity, "percentage_step") | float(0) %} + {% set percentage_step = state_attr(fan_entity, "percentage_step") | float(0) %} {{ (100/percentage_step) | round(0) | int(0) if percentage_step > 0 @@ -7632,6 +7642,72 @@ action: background: [] continue_on_error: true + ## PAGE MEDIA PLAYER ## + - alias: Media player settings page + conditions: '{{ nspanel_event.page == page.media_player }}' + sequence: &refresh_page_media_player + - variables: + media_player_entity: '{{ nspanel_event.entity if nspanel_event is defined and nspanel_event.entity is defined else trigger.entity_id }}' + media_player: + state: '{{ states(media_player_entity) }}' + is_volume_muted: '{{ state_attr(media_player_entity, "is_volume_muted") | default(false) }}' + friendly_name: '{{ state_attr(media_player_entity, "friendly_name") | default("Media player") }}' + volume_level: '{{ state_attr(media_player_entity, "volume_level") }}' + media_title: '{{ state_attr(media_player_entity, "media_title") }}' + media_artist: '{{ state_attr(media_player_entity, "media_artist") }}' + media_album_name: '{{ state_attr(media_player_entity, "media_album_name") }}' + media_duration: '{{ state_attr(media_player_entity, "media_duration") | int(0) }}' + media_position: '{{ state_attr(media_player_entity, "media_position") | int(0) }}' + media_position_updated_at: '{{ state_attr(media_player_entity, "media_position_updated_at") }}' + supported_features: '{{ state_attr(media_player_entity, "supported_features") | int(0) }}' + feature: + PAUSE: 1 + SEEK: 2 + VOLUME_SET: 4 + VOLUME_MUTE: 8 + PREVIOUS_TRACK: 16 + NEXT_TRACK: 32 + reserved: 64 + TURN_ON: 128 + TURN_OFF: 256 + PLAY_MEDIA: 512 + VOLUME_STEP: 1024 + SELECT_SOURCE: 2048 + STOP: 4096 + CLEAR_PLAYLIST: 8192 + PLAY: 16384 + SHUFFLE_SET: 32768 + SELECT_SOUND_MODE: 65536 + BROWSE_MEDIA: 131072 + REPEAT_SET: 262144 + GROUPING: 524288 + MEDIA_ANNOUNCE: 1048576 + MEDIA_ENQUEUE: 2097152 + position_int: '{{ 0 if media_player.media_duration <= 0 else (100*media_player.media_position/media_player.media_duration) | round(0, default=0) }}' + position_str: '{{ "" if media_player.media_duration <= 0 else timedelta(seconds=position_int) }}' + duration_str: '{{ "" if media_player.media_duration <= 0 else timedelta(seconds=media_player.media_duration) }}' + - service: '{{ nextion.command.media_player }}' + data: + entity: '{{ media_player_entity }}' + state: '{{ media_player.state }}' + page_title: '{{ media_player.friendly_name }}' + track: '{{ media_player.media_title }}' + artist: '{{ media_player.media_artist }}' + bt_on_off: '{{ media_player.supported_features | bitwise_and(feature.TURN_ON) > 0 }}' # DEBUG + bt_prev: '{{ media_player.supported_features | bitwise_and(feature.PREVIOUS_TRACK) > 0 }}' + bt_play_pause: 0 + bt_stop: '{{ media_player.supported_features | bitwise_and(feature.STOP) > 0 }}' + bt_next: '{{ media_player.supported_features | bitwise_and(feature.NEXT_TRACK) > 0 }}' + time_current: 0 + time_total: 0 + time_progress: '{{ 0 if media_player.media_duration <= 0 else (100*media_player.media_position/media_player.media_duration) | round(0, default=0) }}' + volume: 0 + bt_mute: 0 + bt_vol_down: '{{ media_player.supported_features | bitwise_and(feature.VOLUME_SET) > 0 }}' + bt_vol_up: '{{ media_player.supported_features | bitwise_and(feature.VOLUME_SET) > 0 }}' + continue_on_error: true + - *delay-default + ## PAGE ALARM ## - alias: Alarm settings page conditions: '{{ nspanel_event.page == page.alarm }}' @@ -7665,7 +7741,7 @@ action: sequence: &refresh_page_climate - &variables-climate_entity variables: - climate_entity_temp: '{{ nspanel_event.entity if nspanel_event.entity is defined }}' + climate_entity_temp: '{{ nspanel_event.entity if nspanel_event is defined and nspanel_event.entity is defined else trigger.entity_id }}' climate_entity: '{{ thermostat_embedded if climate_entity_temp == "embedded_climate" else climate_entity_temp }}' settings_entity_domain: > {{ @@ -8047,7 +8123,7 @@ action: page: entitypage04 component: value08 - variables: - entity_page_index: '{{ (nspanel_event.page[-2:] | int(-1)) - 1 }}' + entity_page_index: '{{ (page.current[-2:] | int(-1)) - 1 }}' first_entity: '{{ entity_page_index * 8 }}' last_entity: '{{ first_entity + 8 }}' ##### Entity page - Label ##### diff --git a/nspanel_esphome.yaml b/nspanel_esphome.yaml index 416a811..0281157 100644 --- a/nspanel_esphome.yaml +++ b/nspanel_esphome.yaml @@ -721,6 +721,67 @@ api: // Logs - End ESP_LOGV("service.alarm_settings", "Finished"); + - service: media_player + variables: + entity: string + state: string + page_title: string + track: string + artist: string + bt_on_off: int + bt_prev: bool + bt_play_pause: int + bt_stop: bool + bt_next: bool + time_current: int + time_total: int + time_progress: int + volume: int + bt_mute: int + bt_vol_down: bool + bt_vol_up: bool + then: + - lambda: |- + ESP_LOGV("service.media_player", "Starting"); + if (id(current_page).state == "media_player") + { + id(disp1).set_component_text_printf("entity", "%s", entity.c_str()); + id(disp1).set_component_text_printf("page_title", "%s", page_title.c_str()); + id(display_wrapped_text).execute("track", track.c_str(), id(display_mode) == 2 ? 15 : 23); + id(display_wrapped_text).execute("artist", artist.c_str(), id(display_mode) == 2 ? 26 : 40); + if (bt_on_off > 0) + { + id(disp1).show_component("bt_on_off"); + if (bt_on_off == 1) id(set_component_color).execute("bt_on_off", {255, 0, 0}, {} ); + else id(set_component_color).execute("bt_on_off", {0, 255, 0}, {} ); + } + else id(disp1).hide_component("bt_on_off"); + if (bt_prev) id(disp1).show_component("bt_prev"); else id(disp1).hide_component("bt_prev"); + if (bt_play_pause > 0) + { + id(disp1).show_component("bt_play_pause"); + if (bt_play_pause == 1) id(disp1).set_component_text_printf("bt_play_pause", "%s", "\uE409"); // mdi:play + else id(disp1).set_component_text_printf("bt_play_pause", "%s", "\uE3E3"); // mdi:pause + } + else id(disp1).hide_component("bt_play_pause"); + if (bt_stop) id(disp1).show_component("bt_stop"); else id(disp1).hide_component("bt_stop"); + if (bt_next) id(disp1).show_component("bt_next"); else id(disp1).hide_component("bt_next"); + id(disp1).set_component_text_printf("time_current", "%i", time_current); + id(disp1).set_component_text_printf("time_total", "%i", time_total); + id(disp1).set_component_value("time_progress", time_progress); + id(disp1).set_component_text_printf("vol_text", "%i%", volume); + id(disp1).set_component_value("vol_slider", time_progress); + if (bt_mute > 0) + { + id(disp1).show_component("bt_mute"); + if (bt_mute == 1) id(disp1).set_component_text_printf("bt_mute", "%s", "\uE57E"); // mdi:volume-low + else id(disp1).set_component_text_printf("bt_mute", "%s", "\uEE07"); // mdi:volume-variant-off + } + else id(disp1).hide_component("bt_mute"); + if (bt_vol_down) id(disp1).show_component("bt_vol_down"); else id(disp1).hide_component("bt_vol_down"); + if (bt_vol_up) id(disp1).show_component("bt_vol_up"); else id(disp1).hide_component("bt_vol_up"); + } + ##### START - GLOBALS CONFIGURATION ##### globals: @@ -1192,7 +1253,7 @@ text_sensor: id(disp1).set_component_text_printf("bt_on_off", "%s", "\uE424"); //mdi:power id(disp1).set_component_text_printf("bt_prev", "%s", "\uE4AD"); //mdi:skip-previous id(disp1).set_component_text_printf("bt_next", "%s", "\uE4AC"); //mdi:skip-next - id(disp1).set_component_text_printf("bt_play_pause", "%s", "\uE3E3"); //mdi:pause + id(disp1).set_component_text_printf("bt_play_pause", "%s", "\uE40D"); //mdi:play-pause id(disp1).set_component_text_printf("bt_stop", "%s", "\uE4DA"); //mdi:stop id(disp1).set_component_text_printf("bt_mute", "%s", "\uE75E"); //mdi:volume-mute id(disp1).set_component_text_printf("bt_vol_down", "%s", "\uE75D"); //mdi:volume-minus