Add Configurable Display Slideshow

Implements adjustable slideshow timing and view scope, with
manual navigation stopping playback. Adds focused regression tests.
This commit is contained in:
2026-11-13 13:32:04 +01:00
parent e4b51b6c07
commit 892e8d218d
2 changed files with 454 additions and 11 deletions
+133 -11
View File
@@ -154,6 +154,58 @@ light:
output: display_backlight_output
restore_mode: ALWAYS_ON
switch:
- platform: template
id: slideshow_enabled
name: "Diashow"
icon: mdi:play-box-multiple
optimistic: true
restore_mode: ALWAYS_OFF
on_turn_on:
- script.execute: slideshow_worker
on_turn_off:
- script.stop: slideshow_worker
number:
- platform: template
id: slideshow_interval
name: "Diashow Intervall"
icon: mdi:timer-outline
entity_category: config
unit_of_measurement: s
min_value: 5
max_value: 300
step: 5
initial_value: 15
mode: box
optimistic: true
restore_value: true
on_value:
- if:
condition:
switch.is_on: slideshow_enabled
then:
- script.execute: slideshow_worker
select:
- platform: template
id: slideshow_scope
name: "Diashow Umfang"
icon: mdi:view-carousel
entity_category: config
options:
- "Alle Ansichten"
- "Nur Hauptseiten"
initial_option: "Alle Ansichten"
optimistic: true
restore_value: true
on_value:
- if:
condition:
switch.is_on: slideshow_enabled
then:
- script.execute: slideshow_worker
font:
- file: "fonts/Roboto-Regular.ttf"
id: font_small
@@ -535,6 +587,74 @@ interval:
}
script:
- id: slideshow_worker
mode: restart
then:
- while:
condition:
switch.is_on: slideshow_enabled
then:
# Delay first so starting or reconfiguring never skips the current view.
- delay: !lambda |-
const float seconds = id(slideshow_interval).state;
return static_cast<uint32_t>((std::isfinite(seconds)
? fmaxf(5.0f, fminf(seconds, 300.0f)) : 15.0f) * 1000.0f);
- if:
condition:
switch.is_on: slideshow_enabled
then:
- script.execute: advance_slideshow
- id: advance_slideshow
then:
- lambda: |-
// Do not call manual navigation scripts: those intentionally stop the slideshow.
if (id(slideshow_scope).current_option() == "Nur Hauptseiten") {
id(page_index) = (id(page_index) + 1) % 5;
return;
}
switch (id(page_index)) {
case 0:
if (id(page_one_gauge_view)) {
id(page_one_gauge_view) = false;
} else {
id(page_index) = 1;
id(device_usage_view) = 0;
}
break;
case 1:
if (id(device_usage_view) == 0) {
id(device_usage_view) = 1;
} else {
id(page_index) = 2;
id(clock_digital_view) = false;
}
break;
case 2:
if (!id(clock_digital_view)) {
id(clock_digital_view) = true;
} else {
id(page_index) = 3;
id(internet_view) = 0;
}
break;
case 3:
if (id(internet_view) < 2) {
id(internet_view)++;
} else {
id(page_index) = 4;
id(climate_graph_view) = false;
}
break;
case 4:
if (!id(climate_graph_view)) {
id(climate_graph_view) = true;
break;
}
id(page_index) = 0;
id(page_one_gauge_view) = true;
break;
}
- script.execute: refresh_display
- id: reset_energy_subscriptions
then:
- lambda: |-
@@ -561,10 +681,12 @@ script:
- component.update: tft
- id: show_previous_page
then:
- switch.turn_off: slideshow_enabled
- lambda: id(page_index) = (id(page_index) + 5 - 1) % 5;
- script.execute: refresh_display
- id: toggle_page_mode
then:
- switch.turn_off: slideshow_enabled
- lambda: |-
if (id(page_index) == 0) {
id(page_one_gauge_view) = !id(page_one_gauge_view);
@@ -580,6 +702,7 @@ script:
- script.execute: refresh_display
- id: show_next_page
then:
- switch.turn_off: slideshow_enabled
- lambda: id(page_index) = (id(page_index) + 1) % 5;
- script.execute: refresh_display
@@ -813,8 +936,12 @@ display:
const bool grid_power_valid = id(grid_power).has_state() && std::isfinite(id(grid_power).state);
const float grid_power_value = grid_power_valid ? id(grid_power).state : 0.0f;
const float grid_power_magnitude = fabsf(grid_power_value);
const float grid_maximum = gauge_maximum(grid_power_magnitude, 1.0f);
int grid_gauge_percent = static_cast<int>(grid_power_magnitude / grid_maximum * 100.0f);
const bool solar_power_valid = id(balcony_solar_power).has_state()
&& std::isfinite(id(balcony_solar_power).state) && id(balcony_solar_power).state >= 0.0f;
const float solar_power_value = solar_power_valid ? id(balcony_solar_power).state : 0.0f;
// One shared scale keeps grid and solar ring lengths directly comparable.
const float maximum = gauge_maximum(fmaxf(grid_power_magnitude, solar_power_value), 1.0f);
int grid_gauge_percent = static_cast<int>(grid_power_magnitude / maximum * 100.0f);
if (grid_gauge_percent > 100) grid_gauge_percent = 100;
const Color grid_gauge_color = grid_power_value >= 0.0f
? Color(143, 190, 223) // #8FBEDF
@@ -822,12 +949,8 @@ display:
it.filled_gauge(gauge_center_x, gauge_center_y, 140, 122, 100, gauge_background);
it.filled_gauge(gauge_center_x, gauge_center_y, 140, 122, grid_gauge_percent, grid_gauge_color);
// The inner band scales independently to the current solar power.
const bool solar_power_valid = id(balcony_solar_power).has_state()
&& std::isfinite(id(balcony_solar_power).state) && id(balcony_solar_power).state >= 0.0f;
const float solar_power_value = solar_power_valid ? id(balcony_solar_power).state : 0.0f;
const float solar_maximum = gauge_maximum(solar_power_value, 1.0f);
int solar_gauge_percent = static_cast<int>(solar_power_value / solar_maximum * 100.0f);
// The inner solar band uses the same watts-per-percent as the outer grid band.
int solar_gauge_percent = static_cast<int>(solar_power_value / maximum * 100.0f);
if (solar_gauge_percent > 100) solar_gauge_percent = 100;
const Color solar_gauge_color = Color(255, 170, 40); // #FFAA28
it.filled_gauge(gauge_center_x, gauge_center_y, 116, 98, 100, gauge_background);
@@ -855,9 +978,8 @@ display:
return std::string(text);
};
it.printf(gauge_center_x, 204, id(font_device), Color::WHITE, TextAlign::TOP_CENTER,
"Max: Netz %s / Solar %s",
grid_power_valid ? format_power(grid_maximum).c_str() : "--",
solar_power_valid ? format_power(solar_maximum).c_str() : "--");
"Gemeinsame Skala: %s",
grid_power_valid || solar_power_valid ? format_power(maximum).c_str() : "--");
} else if (id(page_index) == 1) {
// Page 2 lists nine consumers at once in two columns; button B changes group.
const int device_count = 18;