From a07c1ad06e30104a6aaff105acc0bdc4b97f6872 Mon Sep 17 00:00:00 2001 From: ZareMate <0.zaremate@gmail.com> Date: Mon, 3 Feb 2025 23:14:26 +0100 Subject: [PATCH] Adjust desk lamp power limits and add 3D printer progress bar with light status display --- desk-lamp.yaml | 6 ++++-- display.yaml | 46 +++++++++++++++++++++++++++++++++++----------- 2 files changed, 39 insertions(+), 13 deletions(-) diff --git a/desk-lamp.yaml b/desk-lamp.yaml index 4b818ee..524bb8d 100644 --- a/desk-lamp.yaml +++ b/desk-lamp.yaml @@ -37,11 +37,13 @@ output: - platform: libretiny_pwm id: output_cold pin: P26 - max_power: 80% # Limit the cold white channel to 80% + max_power: 70% # Limit the cold white channel to 80% + min_power: 14% - platform: libretiny_pwm id: output_warm pin: P24 - max_power: 80% # Limit the warm white channel to 80% + max_power: 70% # Limit the warm white channel to 80% + min_power: 14% light: - platform: cwww diff --git a/display.yaml b/display.yaml index 54cc18c..ea94723 100644 --- a/display.yaml +++ b/display.yaml @@ -60,15 +60,23 @@ display: // Calculate column and row positions int col_array[] = {margin, col_offset + y_step, col_offset + y_step * 2, col_offset + y_step * 3, col_offset + y_step * 5, col_offset + y_step * 7}; - int row_array[] = {margin, row_y, row_y + y_step, row_y + y_step * 2, row_y + y_step * 3, row_y + y_step * 4}; it.fill(Color(0, 0, 0)); // Clear screen + // Function to calculate row position + auto row = [&](int row_in) { + if (row_in == 0) { + return margin; + } else { + return row_y + y_step * (row_in - 1); + } + }; + // Function to handle all state conditions auto handle_state = [&](int col_index, int row_index, std::string text, std::string type) { int x, y, center; x = col_array[col_index]; - y = row_array[row_index]; + y = row(row_index); center = ((col_array[col_index] + col_array[col_index + 1]) / 2) - 10; if (text != "on" && text != "off" && text != "unavailable" && text != "unknown" && text != "") { @@ -136,14 +144,23 @@ display: handle_state(4, 4, id(tomek_humidity).state, "humidity"); handle_state(4, 5, id(mateusz_humidity).state, "humidity"); + + // 3D Printer variables + int progress_width = screen_width - (2 * margin) - 120; + int progress = (atoi(id(octo_prog).state.c_str()) / 100) * progress_width; + // 3D Printer progress bar - if (id(printer_3d_progress).state != "" && id(printer_3d_progress).state != "unknown" && id(printer_3d_progress).state != "unavailable" && id(printer_3d_progress).state != "0") { - int progress_y = row_array[5] + y_step; - it.print(margin, progress_y, id(my_font), Color(255, 255, 255), "3D Printer:"); - int progress_width = screen_width - (2 * margin) - 100; - int progress = (atoi(id(printer_3d_progress).state.c_str()) / 100) * progress_width; - it.filled_rectangle(margin + 90, progress_y, progress, 20, Color(0, 255, 0)); - it.rectangle(margin + 90, progress_y, progress_width, 20, Color(255, 255, 255)); + if (id(octo_state).state == "Printing") { + it.print(margin, row(6), id(my_font), Color(255, 255, 255), "3D Printer:"); + it.filled_rectangle(margin + 90, row(6), progress, 20, Color(0, 255, 0)); + it.rectangle(margin + 90, row(6), progress_width, 20, Color(255, 255, 255)); + } + + // 3D Printer light status + if (id(printer_light).state == "on" && id(octo_state).state == "Printing" ) { + it.print(margin + 90 + progress_width + 10, row(6), id(icon_font), Color(255, 255, 255), "󰖨"); + } else if (id(printer_light).state == "on") { + it.print(margin, row(6), id(my_font), Color(255, 255, 255), "3D Printer Light On"); } # Home Assistant integration @@ -211,9 +228,16 @@ text_sensor: - platform: homeassistant entity_id: sensor.mateusz_s_room_sensor_humidity id: mateusz_humidity + - platform: homeassistant entity_id: sensor.octoprint_job_percentage - id: printer_3d_progress + id: octo_prog + - platform: homeassistant + entity_id: sensor.octoprint_current_state + id: octo_state + - platform: homeassistant + entity_id: switch.3d_printer_light + id: printer_light font: - id: my_font @@ -222,7 +246,7 @@ font: - id: icon_font file: "fonts/JetBrains.ttf" size: 20 - glyphs: [ "󰚡", "󰠚", "󰶑", "󰔏", "󰖌" ] + glyphs: [ "󰚡", "󰠚", "󰶑", "󰔏", "󰖌", "󰖨" ] interval: - interval: 1s