diff --git a/Examples/1BAR_1Display_Basic.yaml b/Examples/1BAR_1Display_Basic.yaml index 328f271..71fd09e 100644 --- a/Examples/1BAR_1Display_Basic.yaml +++ b/Examples/1BAR_1Display_Basic.yaml @@ -6,9 +6,14 @@ packages: ref: main refresh: 1d +substitutions: + nr_of_pages: '1' + globals: - - id: !extend nr_of_pages - initial_value: '1' + - id: !extend page_names + initial_value: '{"Page 1"}' + - id: !extend active_page_name + initial_value: "" font: - file: "https://github.com/web-fonts/ttf/raw/refs/heads/master/bpg-ingiri-arial-webfont.ttf" diff --git a/Examples/2BAR_1Display_Basic.yaml b/Examples/2BAR_1Display_Basic.yaml index 3b1a8bf..916edc8 100644 --- a/Examples/2BAR_1Display_Basic.yaml +++ b/Examples/2BAR_1Display_Basic.yaml @@ -6,9 +6,14 @@ packages: ref: main refresh: 1d +substitutions: + nr_of_pages: '1' + globals: - - id: !extend nr_of_pages - initial_value: '1' + - id: !extend page_names + initial_value: '{"Page 1"}' + - id: !extend active_page_name + initial_value: "" font: - file: "https://github.com/web-fonts/ttf/raw/refs/heads/master/bpg-ingiri-arial-webfont.ttf" diff --git a/Examples/3BAR_1Display_Basic.yaml b/Examples/3BAR_1Display_Basic.yaml index 52b8ff9..2f1cfe2 100644 --- a/Examples/3BAR_1Display_Basic.yaml +++ b/Examples/3BAR_1Display_Basic.yaml @@ -6,9 +6,14 @@ packages: ref: main refresh: 1d +substitutions: + nr_of_pages: '1' + globals: - - id: !extend nr_of_pages - initial_value: '1' + - id: !extend page_names + initial_value: '{"Page 1"}' + - id: !extend active_page_name + initial_value: "" font: - file: "https://github.com/web-fonts/ttf/raw/refs/heads/master/bpg-ingiri-arial-webfont.ttf" diff --git a/Examples/3pages_TotalExample.yml b/Examples/3pages_TotalExample.yml index b779ab2..23f95ed 100644 --- a/Examples/3pages_TotalExample.yml +++ b/Examples/3pages_TotalExample.yml @@ -29,6 +29,7 @@ wifi: password: !secret wifi_password substitutions: + nr_of_pages: '3' music_card_enity_id: 'media_player.media_keuken_2' music_card_text_color: FFFFFF music_card_icon_main_color: FF7F00 @@ -44,13 +45,9 @@ packages: refresh: 1d globals: - - id: !extend nr_of_pages - initial_value: '3' - - id: page_names - type: std::vector + - id: !extend page_names initial_value: '{"Page 1","Music","Page 3"}' - - id: active_page_name - type: std::string + - id: !extend active_page_name initial_value: "" font: diff --git a/package/base.yaml b/package/base.yaml index 94d30ab..f169eb4 100644 --- a/package/base.yaml +++ b/package/base.yaml @@ -29,12 +29,15 @@ spi: mosi_pin: GPIO35 globals: - - id: nr_of_pages - type: int - initial_value: '1' - id: actual_page type: int initial_value: '0' + - id: page_names + type: std::vector + initial_value: '{"Page 1"}' + - id: active_page_name + type: std::string + initial_value: "" output: - platform: ledc @@ -93,24 +96,24 @@ time: id: datetime number: - ## Creates a number entity in Home Assistant + # Creates a number entity in Home Assistant # It sets the menu of the Button Plus - platform: template name: "Menu Selector" - id: menuselector + id: menu_selector optimistic: true min_value: 0 # keep at 0 - max_value: 10 # TODO replace page numbers with substitution + max_value: ${nr_of_pages} step: 1 on_value: then: - lambda: |- - if(id(menuselector).state >= id(nr_of_pages)) { - id(actual_page) = id(nr_of_pages)-1; + if(id(menu_selector).state >= $nr_of_pages) { + id(actual_page) = $nr_of_pages-1; } else { - id(actual_page) = id(menuselector).state; + id(actual_page) = id(menu_selector).state; } -# # Refresh the screen + # Refresh the screen # - script.execute: update_page <<< this ends in an loop... script: @@ -121,7 +124,7 @@ script: then: - lambda: |- id(actual_page) = id(actual_page) + 1; - if(id(actual_page) >= id(nr_of_pages)) { + if(id(actual_page) >= $nr_of_pages) { id(actual_page) = 0; } - script.execute: update_page @@ -130,7 +133,7 @@ script: - lambda: |- id(actual_page) = id(actual_page) - 1; if(id(actual_page) < 0) { - id(actual_page) = id(nr_of_pages) - 1; + id(actual_page) = $nr_of_pages - 1; } - script.execute: update_page - id: update_page @@ -144,7 +147,5 @@ script: id: active_page_name_ha state: !lambda 'return id(active_page_name);' - number.set: - id: menuselector + id: menu_selector value: !lambda 'return id(actual_page);' - - script.execute: update_all -