diff --git a/liloled b/liloled new file mode 100644 index 0000000..9c46518 --- /dev/null +++ b/liloled @@ -0,0 +1,170 @@ +esphome: + name: esphome-web-4fc3ec + friendly_name: oled little guy + min_version: 2024.11.0 + name_add_mac_suffix: false + +esp32: + board: esp32dev + framework: + type: esp-idf + +# Enable logging +logger: + +# Enable Home Assistant API +api: + +ota: + platform: esphome + +wifi: + ssid: "DNTD" + password: "wifipassword" + +# BLE Tracker and Proxy +esp32_ble_tracker: + scan_parameters: + active: false + +bluetooth_proxy: + active: true + +sensor: + - platform: homeassistant + id: temperature + entity_id: weather.home + attribute: temperature + internal: true + +time: + - platform: homeassistant + id: esptime + +# Define global variable for the page +globals: + - id: page + type: int + restore_value: no + initial_value: '0' + +# I2C Configuration for OLED Display +i2c: + sda: GPIO21 + scl: GPIO22 + scan: true + +# OLED Display Configuration +display: + - platform: ssd1306_i2c + model: "SSD1306 128x64" + address: 0x3C + rotation: 0 + lambda: |- + if (id(page) == 0) { + std::string weather_text = id(weather_condition).state.c_str(); + + // Wrap the weather text if it exceeds 16 characters + if (weather_text.length() > 16) { + it.print(0, 0, id(font1), weather_text.substr(0, 16).c_str()); + it.print(0, 20, id(font1), weather_text.substr(16).c_str()); + } else { + it.print(0, 0, id(font1), weather_text.c_str()); + } + + // Temperature + char temp_str[20]; + snprintf(temp_str, sizeof(temp_str), "%d°F", (int) id(temperature).state); + if (strlen(temp_str) > 16) { + it.print(0, 40, id(font1), temp_str); + } else { + it.print(0, 40, id(font1), temp_str); + } + } + else if (id(page) == 1) { + // Date & Time + std::string time_str = id(esptime).now().strftime("%I:%M %p"); + if (time_str.length() > 16) { + it.print(0, 0, id(font1), time_str.substr(0, 16).c_str()); + it.print(0, 20, id(font1), time_str.substr(16).c_str()); + } else { + it.print(0, 0, id(font1), time_str.c_str()); + } + } + else if (id(page) == 2) { + // Date (e.g., "Wed 04/03") + std::string date_str = id(esptime).now().strftime("%a %m/%d"); + if (date_str.length() > 16) { + it.print(0, 0, id(font1), date_str.substr(0, 16).c_str()); + it.print(0, 20, id(font1), date_str.substr(16).c_str()); + } else { + it.print(0, 0, id(font1), date_str.c_str()); + } + } + 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()); + } + } + else if (id(page) == 4) { + // 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(); + + // Display media title + if (media_title.length() > 16) { + it.print(0, 0, id(font2), media_title.substr(0, 16).c_str()); + it.print(0, 20, id(font2), media_title.substr(16).c_str()); + } else { + 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()); + } + } + + + +# Define Font for OLED +font: + - file: "gfonts://Roboto" + id: font1 + size: 22 + + - file: "gfonts://Roboto" + id: font2 + size: 14 + +# Text sensors for weather and location information +text_sensor: + - platform: homeassistant + id: weather_condition + entity_id: weather.home + internal: true + + - platform: homeassistant + id: media_title_sensor + entity_id: media_player.deepthought + attribute: media_title + + - platform: homeassistant + id: media_artist_sensor + entity_id: media_player.deepthought + attribute: media_artist + + +interval: + - interval: 5s + then: + - lambda: |- + id(page) = (id(page) + 1) % 5;