Jon
27 december 2024
Great little touchscreen. Wanted to build a touch screen smart bulb switch panel for all my smart bulbs in my house, interfacing through homeassistant. It took lots of Googling plus a really helpful review on here showing correct pin out configurations. I built this using the esp32 nodemcu module from AZ delivery. Here is my config for esphome, I hope it helps someone:esphome:name: tscontrolesp32:board: esp32devframework:type: arduino# Enable logginglogger:# Enable Home Assistant APIapi:ota:password: ####wifi:ssid: !secret wifi_ssidpassword: !secret wifi_passwordmanual_ip:static_ip: ###.###.###.###subnet: 255.255.255.0dns1: ###.###.###.####dns2: #.#.#.#gateway: ###.###.###.#### Enable fallback hotspot (captive portal) in case wifi connection failsap:ssid: ######password: ########captive_portal:spi:clk_pin: GPIO18mosi_pin: GPIO23miso_pin: GPIO19xpt2046:id: touchscreencs_pin: GPIO14irq_pin: GPIO27update_interval: 50msreport_interval: 1sthreshold: 400dimension_x: 240dimension_y: 320calibration_x_min: 3860calibration_x_max: 280calibration_y_min: 340calibration_y_max: 3860swap_x_y: Falseoutput:# backlight- platform: ledcpin: 15id: gpio_15_backlight_pwminverted: truelight:# backlight for HA- platform: monochromaticoutput: gpio_15_backlight_pwmname: "ILI9341 Display Backlight"id: back_lightrestore_mode: ALWAYS_OFFtext_sensor:- platform: homeassistantid: mblightgroupentity_id: light.bedside_lights- platform: homeassistantid: emmabedsideentity_id: light.smart_lighting_tunable_white_and_color_3- platform: homeassistantid: jonbedsideentity_id: light.smart_lighting_tunable_white_and_color_2_2- platform: homeassistantid: kitchenlightsentity_id: light.kitchen_lights- platform: homeassistantid: kitchenlight1entity_id: light.smart_bulb_2- platform: homeassistantid: kitchenlight2entity_id: light.smart_bulb_3- platform: homeassistantid: kitchenlight3entity_id: light.smart_bulb_4- platform: homeassistantid: livingroomlightsentity_id: light.living_room_lights- platform: homeassistantid: livingroomlight1entity_id: light.mk_smart_led_bulb_rgbpro- platform: homeassistantid: livingroomlight2entity_id: light.mk_smart_led_bulb_rgbpro_2- platform: homeassistantid: porchlightentity_id: light.smart_bulb- platform: homeassistantid: toiletlightentity_id: light.smart_lighting_tunable_white_and_color- platform: homeassistantid: landinglightentity_id: light.smart_lighting_tunable_white_and_color_3_2- platform: homeassistantid: hallandlandinglightsentity_id: light.hall_and_landing_lights- platform: homeassistantid: halllightentity_id: light.smart_lighting_tunable_white_and_color_4- platform: homeassistantid: girlslightentity_id: light.smart_lighting_tunable_white_and_color_2display:- platform: ili9341model: TFT 2.4id: touch_displaycs_pin: GPIO5dc_pin: GPIO4reset_pin: GPIO22rotation: 180pages:- id: page1lambda: |-it.fill(Color::WHITE);if (id(mblightgroup).state == "on") // KEY1{ it.image(27, 10, id(bulb_on)); } // Bulb on Iconelse{ it.image(27, 10, id(bulb_off)); } // Bulb off Iconit.print(5, 70, id(RobotoMed), id(COLOR_CSS_PURPLE), TextAlign::TOP_LEFT, "Master Bedroom");if (id(kitchenlights).state == "on") // KEY2{ it.image(147, 10, id(bulb_on)); } // Bulb on Iconelse{ it.image(147, 10, id(bulb_off)); } // Bulb off Iconit.print(135, 70, id(RobotoMed), id(COLOR_CSS_PURPLE), TextAlign::TOP_LEFT, "Kitchen Lights");if (id(livingroomlights).state == "on") // KEY3{ it.image(27, 90, id(bulb_on)); } // Bulb on Iconelse{ it.image(27, 90, id(bulb_off)); } // Bulb off Iconit.print(15, 150, id(RobotoMed), id(COLOR_CSS_PURPLE), TextAlign::TOP_LEFT, "Lounge Lights");if (id(hallandlandinglights).state == "on") // KEY4{ it.image(147, 90, id(bulb_on)); } // Bulb on Iconelse{ it.image(147, 90, id(bulb_off)); } // Bulb off Iconit.print(145, 150, id(RobotoMed), id(COLOR_CSS_PURPLE), TextAlign::TOP_LEFT, "Hall Lights");if (id(toiletlight).state == "on") // KEY5{ it.image(27, 170, id(bulb_on)); } // Bulb on Iconelse{ it.image(27, 170, id(bulb_off)); } // Bulb off Iconit.print(25, 230, id(RobotoMed), id(COLOR_CSS_PURPLE), TextAlign::TOP_LEFT, "Toilet Light");if (id(girlslight).state == "on") // KEY6{ it.image(147, 170, id(bulb_on)); } // Bulb on Iconelse{ it.image(147, 170, id(bulb_off)); } // Bulb off Iconit.print(145, 230, id(RobotoMed), id(COLOR_CSS_PURPLE), TextAlign::TOP_LEFT, "Girls Light");it.image(37, 260, id(prev)); // Previous Iconit.image(157, 260, id(next)); // Next Icon- id: page2lambda: |-it.fill(Color::WHITE);if (id(emmabedside).state == "on") // KEY1{ it.image(27, 10, id(bulb_on)); } // Bulb on Iconelse{ it.image(27, 10, id(bulb_off)); } // Bulb off Iconit.print(7, 70, id(RobotoMed), id(COLOR_CSS_PURPLE), TextAlign::TOP_LEFT, "Emma Bedside");if (id(jonbedside).state == "on") // KEY2{ it.image(147, 10, id(bulb_on)); } // Bulb on Iconelse{ it.image(147, 10, id(bulb_off)); } // Bulb off Iconit.print(135, 70, id(RobotoMed), id(COLOR_CSS_PURPLE), TextAlign::TOP_LEFT, "Jon Bedside");if (id(porchlight).state == "on") // KEY3{ it.image(27, 90, id(bulb_on)); } // Bulb on Iconelse{ it.image(27, 90, id(bulb_off)); } // Bulb off Iconit.print(20, 150, id(RobotoMed), id(COLOR_CSS_PURPLE), TextAlign::TOP_LEFT, "Porch Light");//if (id(hallandlandinglights).state == "on") // KEY4//{ it.image(147, 90, id(bulb_on)); } // Bulb on Icon//else//{ it.image(147, 90, id(bulb_off)); } // Bulb off Icon//it.print(145, 150, id(RobotoMed), id(COLOR_CSS_PURPLE), TextAlign::TOP_LEFT, "Hall Lights");if (id(landinglight).state == "on") // KEY5{ it.image(27, 170, id(bulb_on)); } // Bulb on Iconelse{ it.image(27, 170, id(bulb_off)); } // Bulb off Iconit.print(15, 230, id(RobotoMed), id(COLOR_CSS_PURPLE), TextAlign::TOP_LEFT, "Landing Light");if (id(halllight).state == "on") // KEY6{ it.image(147, 170, id(bulb_on)); } // Bulb on Iconelse{ it.image(147, 170, id(bulb_off)); } // Bulb off Iconit.print(145, 230, id(RobotoMed), id(COLOR_CSS_PURPLE), TextAlign::TOP_LEFT, "Hall Light");it.image(37, 260, id(prev)); // Previous Iconit.image(157, 260, id(next)); // Next Iconfont:- file: '/config/fonts/Roboto-Medium.ttf'id: RobotoMedsize: 14# - file: 'fonts/materialdesignicons-webfont.ttf'# id: font_icon# size: 75# glyphs:# - "U000F0E4F" # mdi-lightbulb_off# - "U000F06E8" # mdi_lightbulb_oncolor:- id: COLOR_CSS_PURPLEred: 41%green: 13%blue: 55%white: 100%image:- file: "/config/images/slide-on.png"id: slide_onresize: 100x53type: RGB24- file: "/config/images/slide-off.png"id: slide_offresize: 100x53type: RGB24- file: "/config/images/bulb-icon-on.png"id: bulb_onresize: 65x65type: RGB24- file: "/config/images/bulb-icon-off.png"id: bulb_offresize: 65x65type: RGB24- file: "/config/images/next-icon.png"id: nextresize: 45x45type: RGB24- file: "/config/images/previous-icon.png"id: prevresize: 45x45type: RGB24binary_sensor:- platform: xpt2046xpt2046_id: touchscreenid: touch_key1x_min: 0x_max: 119y_min: 0y_max: 89on_press:- if:condition:and:- display.is_displaying_page: page1- light.is_on: back_lightthen:- logger.log: "Key1 was touched"- homeassistant.service:service: light.toggledata:entity_id: light.bedside_lights- if:condition:and:- display.is_displaying_page: page2- light.is_on: back_lightthen:- logger.log: "Key9 was touched"- homeassistant.service:service: light.toggledata:entity_id: light.smart_lighting_tunable_white_and_color_3- platform: xpt2046xpt2046_id: touchscreenid: touch_key2x_min: 120x_max: 239y_min: 0y_max: 89on_press:- if:condition:and:- display.is_displaying_page: page1- light.is_on: back_lightthen:- logger.log: "Key2 was touched"- homeassistant.service:service: light.toggledata:entity_id: light.kitchen_lights- if:condition:and:- display.is_displaying_page: page2- light.is_on: back_lightthen:- logger.log: "Key10 was touched"- homeassistant.service:service: light.toggledata:entity_id: light.smart_lighting_tunable_white_and_color_2_2- platform: xpt2046xpt2046_id: touchscreenid: touch_key3x_min: 0x_max: 119y_min: 90y_max: 169on_press:- if:condition:and:- display.is_displaying_page: page1- light.is_on: back_lightthen:- logger.log: "Key3 was touched"- homeassistant.service:service: light.toggledata:entity_id: light.living_room_lights- if:condition:and:- display.is_displaying_page: page2- light.is_on: back_lightthen:- logger.log: "Key11 was touched"- homeassistant.service:service: light.toggledata:entity_id: light.smart_bulb- platform: xpt2046xpt2046_id: touchscreenid: touch_key4x_min: 120x_max: 239y_min: 90y_max: 169on_press:- if:condition:and:- display.is_displaying_page: page1- light.is_on: back_lightthen:- logger.log: "Key4 was touched"- homeassistant.service:service: light.toggledata:entity_id: light.hall_and_landing_lights- platform: xpt2046xpt2046_id: touchscreenid: touch_key5x_min: 0x_max: 119y_min: 170y_max: 249on_press:- if:condition:and:- display.is_displaying_page: page1- light.is_on: back_lightthen:- logger.log: "Key5 was touched"- homeassistant.service:service: light.toggledata:entity_id: light.smart_lighting_tunable_white_and_color- if:condition:and:- display.is_displaying_page: page2- light.is_on: back_lightthen:- logger.log: "Key13 was touched"- homeassistant.service:service: light.toggledata:entity_id: light.smart_lighting_tunable_white_and_color_3_2- platform: xpt2046xpt2046_id: touchscreenid: touch_key6x_min: 120x_max: 239y_min: 170y_max: 249on_press:- if:condition:and:- display.is_displaying_page: page1- light.is_on: back_lightthen:- logger.log: "Key6 was touched"- homeassistant.service:service: light.toggledata:entity_id: light.smart_lighting_tunable_white_and_color_2- if:condition:and:- display.is_displaying_page: page2- light.is_on: back_lightthen:- logger.log: "Key14 was touched"- homeassistant.service:service: light.toggledata:entity_id: light.smart_lighting_tunable_white_and_color_4- platform: xpt2046xpt2046_id: touchscreenid: touch_key7x_min: 0x_max: 119y_min: 250y_max: 320on_press:- if:condition:- light.is_on: back_lightthen:- logger.log: "Key7 was touched"- display.page.show_previous: touch_display- platform: xpt2046xpt2046_id: touchscreenid: touch_key8x_min: 120x_max: 239y_min: 250y_max: 320on_press:- if:condition:- light.is_on: back_lightthen:- logger.log: "Key8 was touched"- display.page.show_next: touch_display- platform: xpt2046xpt2046_id: touchscreenid: touch_key14x_min: 0x_max: 240y_min: 0y_max: 320on_press:- if:condition:- light.is_off: back_lightthen:- logger.log: "Key14 was touched"- light.turn_on: back_light- delay: 30 sec- light.turn_off: back_light