Hey so this is a pointless little feature I have been working on. Am not sure if someone has done it before or not but I figured I would share. You must have 3 unassigned GPIO to make this work. Text color is adjustable in HA like it was an RGB light entity:
esphome:
name: mini-display-tv-yellow
friendly_name: Mini Display TV - Yellow
esp8266:
board: esp01_1m
external_components:
- source:
type: git
url: https://github.com/rletendu/esphome.git
ref: st7789_nobuffer_202312
components: [st7789v]
logger:
api:
ota:
platform: esphome
wifi:
ssid: "wifissid"
password: "wifipassword"
ap:
ssid: "display"
password: "wifipassword"
spi:
clk_pin: GPIO14
mosi_pin: GPIO13
interface: hardware
id: spihwd
output:
- platform: esp8266_pwm
pin: GPIO05
frequency: 1000 Hz
id: pwm_output
inverted: true
# Dummy RGB outputs (not connected to physical pins)
- platform: esp8266_pwm
id: output_red
pin: GPIO4 # Dummy pin
inverted: false
- platform: esp8266_pwm
id: output_green
pin: GPIO12 # Dummy pin
inverted: false
- platform: esp8266_pwm
id: output_blue
pin: GPIO15 # Dummy pin
inverted: false
light:
- platform: monochromatic
name: "Backlight"
output: pwm_output
id: backlight
restore_mode: RESTORE_AND_ON
# Virtual RGB light for text color control
- platform: rgb
name: "Text Color"
red: output_red
green: output_green
blue: output_blue
id: text_color
restore_mode: ALWAYS_ON
font:
- file: "gfonts://Orbitron"
id: dspfont
size: 75
- file: "gfonts://Orbitron"
id: dspfont_small
size: 26
- file: "gfonts://Orbitron"
id: dspfont_medium
size: 38
time:
- platform: homeassistant
id: esptime
switch:
- platform: homeassistant
id: air_purifier_outlet1
entity_id: switch.air_purifier_outlet1
sensor:
- platform: homeassistant
id: temperature
entity_id: weather.home
attribute: temperature
internal: true
# Text sensors for weather and location information
text_sensor:
- platform: homeassistant
id: weather_condition
entity_id: weather.home
internal: true
display:
- platform: st7789v
model: "Custom"
spi_id: spihwd
height: 240
width: 240
offset_height: 0
offset_width: 0
dc_pin: GPIO00
reset_pin: GPIO02
eightbitcolor: true
update_interval: 30s
id: disp
spi_mode: mode3
lambda: |-
// Read RGB values from the virtual light entity
float r = id(text_color).current_values.get_red() * 255;
float g = id(text_color).current_values.get_green() * 255;
float b = id(text_color).current_values.get_blue() * 255;
Color text_color = Color(r, g, b);
// Display the time in 12-hour format
it.strftime(0, 80, id(dspfont), text_color, TextAlign::BASELINE_LEFT, "%l:%M", id(esptime).now());
// Display the date in abbreviated weekday, MM/DD format (no year)
it.strftime(0, 130, id(dspfont_medium), text_color, TextAlign::BASELINE, "%a %m/%d", id(esptime).now());
// Display current weather condition with text_color
it.print(0, 140, id(dspfont_small), text_color, id(weather_condition).state.c_str());
// Display current temperature under the weather condition with text_color
String temp_str = "Temp: " + String(id(temperature).state) + " °F";
it.print(0, 170, id(dspfont_small), text_color, temp_str.c_str());
// Display "Party mode: ON" or "No fun allowed" with text_color
if (id(air_purifier_outlet1).state) {
it.printf(0, 230, id(dspfont_small), text_color, TextAlign::BASELINE_LEFT, "Party mode: ON");
} else {
it.printf(0, 230, id(dspfont_small), text_color, TextAlign::BASELINE_LEFT, "No fun allowed");
}