esphome: name: display friendly_name: DISPLAY esp32: board: esp32dev framework: type: arduino # Enable logging logger: level: WARN # Enable Home Assistant API api: encryption: key: "S9zpaMdXsTbjQE5QTWJ2SN3sdSlTEnSomw/PnbwyMZc=" ota: platform: esphome password: !secret ota wifi: ssid: !secret wifi_ssid password: !secret wifi_password ap: ssid: "Display Fallback Hotspot" password: "ajRx8MZPIszl" spi: clk_pin: 18 mosi_pin: 23 miso_pin: 19 # Display configuration display: - platform: ili9xxx model: st7789v dimensions: height: 320 width: 240 offset_height: 0 offset_width: 0 rotation: 0 color_order: bgr invert_colors: false data_rate: 80MHz cs_pin: 5 dc_pin: 16 reset_pin: 4 lambda: |- // Define row positions int icon_row = 5; int row_y = icon_row + 25; int y_step = 30; int col_start = 5; int col_offset = col_start + 25; int icon_size = y_step * 0.75; // Calculate column and row positions int col_array[] = {col_start, 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[] = {icon_row, 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 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]; center = ((col_array[col_index] + col_array[col_index + 1]) / 2) - 10; if (text != "on" && text != "off" && text != "unavailable" && text != "unknown" && text != "") { if (type == "temperature") { text = text + "°C"; } else if (type == "humidity") { text = text + "%"; } } if (text == "unavailable" || text == "unknown") { it.filled_triangle(x, y + icon_size, x + icon_size, y + icon_size, x + (icon_size / 2), y, Color(255, 0, 0)); it.print((x + icon_size / 3) + 1, y, id(my_font), Color(255, 255, 255), "!"); } else if (text == "" && type == "door" || text == "" && type == "motion") { it.filled_rectangle(x, y, icon_size, icon_size, Color(128, 128, 128)); } else if (text == "on") { it.filled_rectangle(x, y, icon_size, icon_size, Color(0, 255, 0)); } else if (text == "off") { it.filled_rectangle(x, y, icon_size, icon_size, Color(255, 0, 0)); } else if (type == "icon") { it.print(center, y, id(icon_font), Color(255, 255, 255), text.c_str()); } else { it.print(x, y, id(my_font), Color(255, 255, 255), text.c_str()); } }; // Room names (first column) handle_state(0,0, "󰚡", "icon"); handle_state(0,1, "Bath", "name"); handle_state(0,2, "Hall", "name"); handle_state(0,3, "Kitch", "name");; handle_state(0,4, "Tom", "name"); handle_state(0,5, "Mate", "name"); // Door status (second column) handle_state(1, 0, "󰠚", "icon"); handle_state(1, 1, id(bath_door_status).state, "door"); handle_state(1, 2, id(hall_door_status).state, "door"); handle_state(1, 3, "", "door"); handle_state(1, 4, id(tomek_door_status).state, "door"); handle_state(1, 5, id(mateusz_door_status).state, "door"); // Motion status (third column) handle_state(2, 0, "󰶑", "icon"); handle_state(2, 1, id(bath_motion_status).state, "motion"); handle_state(2, 2, id(hall_motion_status).state, "motion"); handle_state(2, 3, id(kitchen_motion_status).state, "motion"); handle_state(2, 4, "", "motion"); handle_state(2, 5, "", "motion"); // Temperature (fourth column) handle_state(3, 0, "󰔏", "icon"); handle_state(3, 1, id(bath_temperature).state, "temperature"); handle_state(3, 2, id(hall_temperature).state, "temperature"); handle_state(3, 3, id(kitchen_temperature).state, "temperature"); handle_state(3, 4, id(tomek_temperature).state, "temperature"); handle_state(3, 5, id(mateusz_temperature).state, "temperature"); // Humidity (fifth column) handle_state(4, 0, "󰖌", "icon"); handle_state(4, 1, id(bath_humidity).state, "humidity"); handle_state(4, 2, id(hall_humidity).state, "humidity"); handle_state(4, 3, id(kitchen_humidity).state, "humidity"); handle_state(4, 4, id(tomek_humidity).state, "humidity"); handle_state(4, 5, id(mateusz_humidity).state, "humidity"); # Home Assistant integration text_sensor: - platform: homeassistant entity_id: binary_sensor.bathroom_door_opening id: bath_door_status - platform: homeassistant entity_id: binary_sensor.entrance_door_opening id: hall_door_status # - platform: homeassistant # entity_id: binary_sensor.kitchen_door_status # id: kitchen_door_status - platform: homeassistant entity_id: binary_sensor.tomasz_s_door_opening id: tomek_door_status - platform: homeassistant entity_id: binary_sensor.mateusz_s_door_opening id: mateusz_door_status - platform: homeassistant entity_id: binary_sensor.bathroom_motion_occupancy id: bath_motion_status - platform: homeassistant entity_id: binary_sensor.hall_motion_occupancy id: hall_motion_status - platform: homeassistant entity_id: binary_sensor.kitchen_motion_occupancy id: kitchen_motion_status # - platform: homeassistant # entity_id: binary_sensor.tomek_motion_sensor # id: tomek_motion_status # - platform: homeassistant # entity_id: binary_sensor.mateusz_motion_sensor # id: mateusz_motion_status - platform: homeassistant entity_id: sensor.bathroom_sensor_temperature id: bath_temperature - platform: homeassistant entity_id: sensor.hall_sensor_temperature id: hall_temperature - platform: homeassistant entity_id: sensor.kitchen_sensor_temperature id: kitchen_temperature - platform: homeassistant entity_id: sensor.t_h_sensor_temperature id: tomek_temperature - platform: homeassistant entity_id: sensor.mateusz_s_room_sensor_temperature id: mateusz_temperature - platform: homeassistant entity_id: sensor.bathroom_sensor_humidity id: bath_humidity - platform: homeassistant entity_id: sensor.hall_sensor_humidity id: hall_humidity - platform: homeassistant entity_id: sensor.kitchen_sensor_humidity id: kitchen_humidity - platform: homeassistant entity_id: sensor.t_h_sensor_humidity id: tomek_humidity - platform: homeassistant entity_id: sensor.mateusz_s_room_sensor_humidity id: mateusz_humidity font: - id: my_font file: "fonts/Roboto.ttf" size: 20 - id: icon_font file: "fonts/JetBrains.ttf" size: 20 glyphs: [ "󰚡", "󰠚", "󰶑", "󰔏", "󰖌" ]