From 1b8ec2f4899411e55216da9f01e7f0085c6212cf Mon Sep 17 00:00:00 2001 From: Joshua King Date: Fri, 6 Mar 2026 14:08:12 -0500 Subject: [PATCH] Add touchscreen support and medication control buttons in Cat Medication Tracker --- esphome/cat-medication-tracker.yaml | 132 +++++++++++++++++++++++++++- 1 file changed, 129 insertions(+), 3 deletions(-) diff --git a/esphome/cat-medication-tracker.yaml b/esphome/cat-medication-tracker.yaml index 4acf5c7..44956df 100644 --- a/esphome/cat-medication-tracker.yaml +++ b/esphome/cat-medication-tracker.yaml @@ -147,8 +147,134 @@ display: it.filled_rectangle(reset_x, reset_y, reset_w, reset_h, dark_grey); it.rectangle(reset_x, reset_y, reset_w, reset_h, black); it.printf(reset_x + reset_w/2, reset_y + reset_h/2, id(status_font), white, TextAlign::CENTER, "RESET"); +# XPT2046 Touchscreen +touchscreen: + - platform: xpt2046 + id: my_touchscreen + spi_id: tft_spi + cs_pin: GPIO33 + update_interval: 250ms + threshold: 1200 + calibration: + x_min: 280 + x_max: 3850 + y_min: 340 + y_max: 3860 -# ... (rest of your config remains unchanged: touchscreen, binary_sensors, light, interval, switches, script, fonts) +# Touch buttons as binary sensors +binary_sensor: + - platform: touchscreen + touchscreen_id: my_touchscreen + name: "Penelope Button" + id: penelope_button + x_min: 40 + x_max: 280 + y_min: 90 + y_max: 210 + on_press: + then: + - switch.toggle: penelope_medicated -# Touchscreen, binary sensors, backlight, interval, switches, script, fonts sections unchanged -# (copy them from your original YAML) \ No newline at end of file + - platform: touchscreen + touchscreen_id: my_touchscreen + name: "Tess Button" + id: tess_button + x_min: 40 + x_max: 280 + y_min: 230 + y_max: 350 + on_press: + then: + - switch.toggle: tess_medicated + + - platform: touchscreen + touchscreen_id: my_touchscreen + name: "Reset Button" + id: reset_button + x_min: 110 + x_max: 210 + y_min: 395 + y_max: 450 + on_press: + then: + - switch.turn_off: penelope_medicated + - switch.turn_off: tess_medicated + + - platform: template + name: "Penelope Medication Status" + lambda: 'return id(penelope_medicated).state;' + device_class: running + + - platform: template + name: "Tess Medication Status" + lambda: 'return id(tess_medicated).state;' + device_class: running + + - platform: template + name: "All Cats Medicated" + lambda: 'return id(penelope_medicated).state && id(tess_medicated).state;' + device_class: running + +# Backlight control +output: + - platform: gpio + pin: GPIO21 + id: backlight_pwm + inverted: true + +light: + - platform: binary + output: backlight_pwm + name: "${friendly_name} Backlight" + id: backlight + restore_mode: ALWAYS_ON + +# Medication state switches (exposed to Home Assistant) +switch: + - platform: template + name: "Penelope Medicated" + id: penelope_medicated + optimistic: true + restore_mode: RESTORE_DEFAULT_OFF + on_turn_on: + - script.execute: update_display + on_turn_off: + - script.execute: update_display + + - platform: template + name: "Tess Medicated" + id: tess_medicated + optimistic: true + restore_mode: RESTORE_DEFAULT_OFF + on_turn_on: + - script.execute: update_display + on_turn_off: + - script.execute: update_display + + - platform: template + name: "Reset All Medications" + id: reset_all + optimistic: false + turn_on_action: + - switch.turn_off: penelope_medicated + - switch.turn_off: tess_medicated + +# Script to update display +script: + - id: update_display + then: + - component.update: my_display + +# Fonts +font: + - file: "gfonts://Roboto" + id: title_font + size: 28 + + - file: "gfonts://Roboto" + id: button_font + size: 24 + + - file: "gfonts://Roboto" + id: status_font + size: 14