Files
Home-Assistant/esphome/cat-medication-tracker.yaml

154 lines
4.6 KiB
YAML
Raw Normal View History

substitutions:
name: cat-medication-tracker
friendly_name: "Cat Medication Tracker"
esphome:
name: ${name}
friendly_name: ${friendly_name}
on_boot:
priority: 100
then:
- light.turn_on:
id: backlight
brightness: 100%
- delay: 300ms
- light.turn_off: backlight
- delay: 300ms
- light.turn_on: backlight
- delay: 300ms
- component.update: my_display
esp32:
board: esp32dev
framework:
type: arduino
logger:
level: DEBUG
logs:
xpt2046: WARN
api:
encryption:
key: !secret api_encryption_key
ota:
platform: esphome
password: !secret ota_password
wifi:
ssid: !secret wifi_iot_ssid
password: !secret wifi_password
ap:
ssid: "${name}-fallback"
password: !secret fallback_password
captive_portal:
time:
- platform: homeassistant
id: homeassistant_time
on_time:
- seconds: 0
minutes: 0
hours: 0
then:
- switch.turn_off: penelope_medicated
- switch.turn_off: tess_medicated
- script.execute: update_display
spi:
- id: tft_spi
clk_pin: GPIO14
mosi_pin: GPIO13
miso_pin: GPIO12
display:
- platform: mipi_spi
model: ILI9488
spi_id: tft_spi
cs_pin: GPIO15
dc_pin: GPIO2
reset_pin: GPIO4
# rotation: 0 # Commenting out; overriding MADCTL manually below for better compatibility
invert_colors: true
color_order: bgr
data_rate: 10MHz # Reduced from 20MHz to improve stability
dimensions:
width: 320
height: 480
id: my_display
auto_clear_enabled: false
update_interval: 2s
color_depth: 18 # Key fix: align with 0x3A 0x66 (18-bit mode)
buffer_size: 25%
lambda: |-
// Quick test: fill entire screen bright red to confirm display is alive
// Comment out once working
it.fill(Color(255, 0, 0));
// Colors
auto red = Color(255, 0, 0);
auto green = Color(0, 200, 0);
auto light_grey = Color(200, 200, 200);
auto white = Color(255, 255, 255);
auto black = Color(0, 0, 0);
auto dark_grey = Color(80, 80, 80);
// Force common MADCTL for portrait (try 0x28, 0x48, 0x68, 0x98 if still wrong orientation)
it.command(0x36);
it.data(0x28); // ← Try this first; change to 0x48 / 0x68 etc. if upside-down/mirrored
// Fill background
it.fill(light_grey);
// Border: green if all done, red otherwise
bool all_done = id(penelope_medicated).state && id(tess_medicated).state;
auto border_color = all_done ? green : red;
int border = 10;
it.filled_rectangle(0, 0, 320, border, border_color);
it.filled_rectangle(0, 480 - border, 320, border, border_color);
it.filled_rectangle(0, 0, border, 480, border_color);
it.filled_rectangle(320 - border, 0, border, 480, border_color);
// Title
it.printf(160, 30, id(title_font), black, TextAlign::TOP_CENTER, "Cat Meds");
// Penelope button
int btn_x = 40;
int btn_y = 90;
int btn_w = 240;
int btn_h = 120;
auto penelope_color = id(penelope_medicated).state ? green : red;
it.filled_rectangle(btn_x, btn_y, btn_w, btn_h, penelope_color);
it.rectangle(btn_x, btn_y, btn_w, btn_h, dark_grey);
it.printf(btn_x + btn_w/2, btn_y + btn_h/2, id(button_font), white, TextAlign::CENTER, "Penelope");
if (id(penelope_medicated).state) {
it.printf(btn_x + btn_w/2, btn_y + btn_h - 20, id(status_font), white, TextAlign::CENTER, "DONE");
}
// Tess button
btn_y = 230;
auto tess_color = id(tess_medicated).state ? green : red;
it.filled_rectangle(btn_x, btn_y, btn_w, btn_h, tess_color);
it.rectangle(btn_x, btn_y, btn_w, btn_h, dark_grey);
it.printf(btn_x + btn_w/2, btn_y + btn_h/2, id(button_font), white, TextAlign::CENTER, "Tess");
if (id(tess_medicated).state) {
it.printf(btn_x + btn_w/2, btn_y + btn_h - 20, id(status_font), white, TextAlign::CENTER, "DONE");
}
// Reset button
int reset_x = 110;
int reset_y = 395;
int reset_w = 100;
int reset_h = 55;
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");
# ... (rest of your config remains unchanged: touchscreen, binary_sensors, light, interval, switches, script, fonts)
# Touchscreen, binary sensors, backlight, interval, switches, script, fonts sections unchanged
# (copy them from your original YAML)