Update liloled

This commit is contained in:
void 2025-04-04 06:22:48 +00:00
parent 41be8b1915
commit 7012d53d86
1 changed files with 93 additions and 18 deletions

111
liloled
View File

@ -10,7 +10,7 @@ esp32:
type: esp-idf
# Enable logging
logger:
logger:
# Enable Home Assistant API
api:
@ -102,20 +102,79 @@ display:
}
}
else if (id(page) == 3) {
// If needed, add a new page for custom info (just an example)
std::string custom_text = "More info here";
if (custom_text.length() > 16) {
it.print(0, 0, id(font1), custom_text.substr(0, 16).c_str());
it.print(0, 20, id(font1), custom_text.substr(16).c_str());
} else {
it.print(0, 0, id(font1), custom_text.c_str());
}
// Retrieve the state of the sensor for today (Day 0)
std::string condition_day_0 = to_string(id(home_condition_day_0).state);
// Log the state for debugging
ESP_LOGD("custom", "Condition Day 0: %s", condition_day_0.c_str());
// Check if the state is available and assign a default value if not
if (condition_day_0.empty()) {
condition_day_0 = "No data"; // Default text if the state is empty
}
// Create a display string for Day 0 (today)
std::string display_text_0 = "Today: " + condition_day_0;
// Define the maximum number of characters per line based on display width
const int max_chars_per_line = 24; // Adjusted to 24 characters per line
int start = 0;
int y_offset = 0; // Vertical position for the next line
// Loop through the display text and split it into lines if needed
while (start < display_text_0.length()) {
// Get the next substring (line)
std::string line = display_text_0.substr(start, max_chars_per_line);
it.print(0, y_offset, id(font3), line.c_str()); // Print each line at the proper position
// Update start to the next portion of text
start += max_chars_per_line;
y_offset += 10; // Halved vertical space between lines
}
}
else if (id(page) == 4) {
// Retrieve the state of the sensor for tomorrow (Day 1)
std::string condition_day_1 = to_string(id(home_condition_day_1).state);
// Log the state for debugging
ESP_LOGD("custom", "Condition Day 1: %s", condition_day_1.c_str());
// Check if the state is available and assign a default value if not
if (condition_day_1.empty()) {
condition_day_1 = "No data"; // Default text if the state is empty
}
// Create a display string for Day 1 (tomorrow)
std::string display_text_1 = "Tomorrow: " + condition_day_1;
// Define the maximum number of characters per line based on display width
const int max_chars_per_line = 24; // Adjusted to 24 characters per line
int start = 0;
int y_offset = 0; // Vertical position for the next line
// Loop through the display text and split it into lines if needed
while (start < display_text_1.length()) {
// Get the next substring (line)
std::string line = display_text_1.substr(start, max_chars_per_line);
it.print(0, y_offset, id(font3), line.c_str()); // Print each line at the proper position
// Update start to the next portion of text
start += max_chars_per_line;
y_offset += 10; // Halved vertical space between lines
}
}
else if (id(page) == 5) {
// Media Title and Artist
std::string media_title = id(media_title_sensor).state.c_str();
std::string media_artist = id(media_artist_sensor).state.c_str();
// Check if either media title or media artist is empty and display "No music playing"
if (media_title.empty() || media_artist.empty()) {
media_title = "No music playing"; // Default message if no music is playing
media_artist.clear(); // Clear artist to prevent extra text
}
// Display media title
if (media_title.length() > 16) {
it.print(0, 0, id(font2), media_title.substr(0, 16).c_str());
@ -124,12 +183,14 @@ display:
it.print(0, 0, id(font2), media_title.c_str());
}
// Display media artist
if (media_artist.length() > 16) {
it.print(0, 40, id(font2), media_artist.substr(0, 16).c_str());
it.print(0, 60, id(font2), media_artist.substr(16).c_str());
} else {
it.print(0, 40, id(font2), media_artist.c_str());
// Display media artist if it's not empty
if (!media_artist.empty()) {
if (media_artist.length() > 16) {
it.print(0, 40, id(font2), media_artist.substr(0, 16).c_str());
it.print(0, 60, id(font2), media_artist.substr(16).c_str());
} else {
it.print(0, 40, id(font2), media_artist.c_str());
}
}
}
@ -143,7 +204,11 @@ font:
- file: "gfonts://Roboto"
id: font2
size: 14
size: 12
- file: "gfonts://Roboto"
id: font3
size: 10
# Text sensors for weather and location information
text_sensor:
@ -162,9 +227,19 @@ text_sensor:
entity_id: media_player.deepthought
attribute: media_artist
- platform: homeassistant
id: home_condition_day_0
entity_id: sensor.home_condition_day_0
internal: true
- platform: homeassistant
id: home_condition_day_1
entity_id: sensor.home_condition_day_1
internal: true
interval:
- interval: 5s
then:
- lambda: |-
id(page) = (id(page) + 1) % 5;
id(page) = (id(page) + 1) % 6;