Skip to content

Instantly share code, notes, and snippets.

@ithygit
Created February 6, 2021 07:11
Show Gist options
  • Save ithygit/02d5cb635e9f0d0a56920613080adb7c to your computer and use it in GitHub Desktop.
Save ithygit/02d5cb635e9f0d0a56920613080adb7c to your computer and use it in GitHub Desktop.
#ith - v1 - backlight untested, works good otherwise, use buttons to cycle
esphome:
name: ttg
platform: ESP32
board: featheresp32
font:
- file: 'fonts\slkscr.ttf'
id: font_slkscr_8
size: 8
glyphs: "!%()+,-/_.:°0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz"
- file: 'fonts\BebasNeue-Regular.ttf'
id: font_bebas_48
size: 48
- file: 'fonts\BebasNeue-Regular.ttf'
id: font_bebas_56
size: 56
- file: 'fonts\arial.ttf'
id: font_arial_12
size: 12
# COLORS ARE IN RGB565 format
globals:
- id: color_red
type: int
restore_value: no
initial_value: '0xF800'
- id: color_green
type: int
restore_value: no
initial_value: '0x07E0'
- id: color_blue
type: int
restore_value: no
initial_value: '0x001F'
- id: color_yellow
type: int
restore_value: no
initial_value: '0xFFE0'
- id: color_yellow_alt
type: int
restore_value: no
initial_value: '0xFE40'
- id: color_cyan
type: int
restore_value: no
initial_value: '0x07FF'
- id: color_orange
type: int
restore_value: no
initial_value: '0xFC20'
- id: color_teal_blue
type: int
restore_value: no
initial_value: '0x04AE'
- id: color_beige
type: int
restore_value: no
initial_value: '0xFFBD'
# OPTIONAL: Another way to set colors
substitutions:
RED: '(0x1F << 11)'
GREEN: '(0x3F << 5)'
BLUE: '(0x1F << 0)'
YELLOW: '(0x1F << 11) | (0x3F << 5)'
CYAN: '(0x3F << 5) | (0x1F << 0)'
MAGENTA: '(0x1F << 11) | (0x1F << 0)'
WHITE: '(0x1F << 11) | (0x3F << 5) | (0x1F << 0)'
GRAY: '(0x10 << 11) | (0x20 << 5) | (0x10 << 0)'
#########
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_pass
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "ESP32-FALLBACK"
password: "Allyouwantisapasswordbutallyougotwaswastedcycles^$\n"
captive_portal:
# Enable logging
logger:
# Enable Home Assistant API
api:
password: "Allyouwantisapasswordbutallyougotwaswastedcycles^$\n"
ota:
password: "Allyouwantisapasswordbutallyougotwaswastedcycles^$\n"
### CUSTOM!!
spi:
clk_pin: GPIO18
mosi_pin: GPIO19
time:
- platform: homeassistant
id: esptime
binary_sensor:
- platform: homeassistant
entity_id: switch.termo
id: termo_state
- platform: gpio
pin:
number: GPIO35
inverted: true
id: tdisplay_button_input_1
on_click:
then:
- homeassistant.service:
service: switch.toggle
data:
entity_id: switch.tasmota
- platform: gpio
pin:
number: GPIO0
inverted: true
id: tdisplay_button_input_0
on_click:
then:
- homeassistant.service:
service: switch.toggle
data:
entity_id: switch.termo
- platform: status
name: "Node Status"
id: system_status
# We can still control the backlight independently
switch:
- platform: gpio
pin: GPIO4
name: "Backlight"
id: backlight
sensor:
- platform: homeassistant
id: termo_power
entity_id: sensor.termo_energy_power
unit_of_measurement: 'W'
- platform: homeassistant
id: termo_voltage
unit_of_measurement: 'V'
entity_id: sensor.termo_energy_voltage
- platform: adc
pin: 34
attenuation: 11db
name: VBatt
id: vcc
update_interval: 60s
- platform: adc
pin: 33
attenuation: 11db
name: VSoil
id: vcc2
update_interval: 60s
- platform: template
name: batterylevel
id: batterylevel
unit_of_measurement: '%'
update_interval: 60s
lambda: |-
// I know infering the battery from voltage only is misleading, but I'll take it. Considering linear decay (again, i'll take it), max=2.23, min=1.38
return ((id(vcc2).state * 118) - 162);
- platform: template
name: soillevel
id: soillevel
unit_of_measurement: '%'
update_interval: 60s
lambda: |-
// I know infering the battery from voltage only is misleading, but I'll take it. Considering linear decay (again, i'll take it), max=2.23, min=1.38
return ((id(vcc).state * 118) - 162);
# TODO brightness
display:
- platform: st7789v
backlight_pin: GPIO4
cs_pin: GPIO5
dc_pin: GPIO16
reset_pin: GPIO23
rotation: 90°
#brightness: 0.5
update_interval: 5s
lambda: |-
if (id(vcc).has_state()) {
it.printf(4, 4, id(font_arial_12), id(color_teal_blue), "%.2f VBat (%.2f %%)", id(vcc).state, id(batterylevel).state);
}
if (id(vcc2).has_state()) {
it.printf(5, 5, id(font_arial_12), id(color_green), "%.2f VSoil (%.2f %%)", id(vcc2).state, id(soillevel).state);
}
it.print(212, 4, id(font_slkscr_8), id(color_teal_blue), "PLUG");
it.print(210, 120, id(font_slkscr_8), id(color_teal_blue), "TERMO");
if(id(termo_state).has_state()) {
if (id(termo_state).state) {
it.print(16, 18, id(font_bebas_56), id(color_green), "TERMO: ON");
} else {
it.print(16, 18, id(font_bebas_56), id(color_red), "TERMO: OFF");
}
}
if (id(termo_power).has_state()) {
float pwr = id(termo_power).state;
if (pwr > 10.0) {
it.printf(16, 72, id(font_bebas_56), id(color_orange), "%.1f W", id(termo_power).state);
} else {
it.printf(16, 72, id(font_bebas_56), id(color_green), "%.1f W", id(termo_power).state);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment