.ccbsp;
ESP32 buttons linked to first 2 relays
Realtime display of relays position on ESP32 TTGO

Input:
- Ph Sensor (analogue)
- TDS Sensor (analogue)
- Ultrasonic distance sensor (waterproof)
- Air temperature sensor
- Water temperature sensor
- optional analogue CO2 sensor
Output:
- 2x (4x) Relay
4 Relays schema

##############################################################
ESP Home Code:
esphome:
name: ttgo_dispaly4
platform: ESP32
board: esp-wrover-kit
wifi:
ssid: "RAIVIoT"
password: "564656464"
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "Ttgo Display Fallback Hotspot"
password: "3215464646"
captive_portal:
# Enable logging
logger:
# Enable Home Assistant API
api:
password: "xxx"
ota:
password: "xxx"
web_server:
port: 80
time:
- platform: sntp
id: esptime
timezone: europe/prague
servers: 10.168.100.254
color:
- id: my_red
red: 100%
green: 0%
blue: 0%
- id: my_yellow
red: 100%
green: 100%
blue: 0%
- id: my_green
red: 0%
green: 100%
blue: 0%
- id: my_blue
red: 0%
green: 0%
blue: 100%
- id: my_gray
red: 50%
green: 50%
blue: 50%
- id: my_black
red: 0%
green: 0%
blue: 0%
font:
- file: "Helvetica.ttf"
id: helvetica_48
size: 48
- file: "Helvetica.ttf"
id: helvetica_24
size: 24
- file: "Helvetica.ttf"
id: helvetica_14
size: 15
- file: "Helvetica.ttf"
id: helvetica_12
size: 12
i2c:
sda: 21
scl: 22
scan: True
# frequency: 100kHz
ads1115:
address: 0x48
# continuous_mode: on
id: ads1115_48
dallas:
- pin: GPIO32
update_interval: 60s
sensor:
- platform: ultrasonic
trigger_pin: GPIO25
echo_pin: GPIO26
update_interval: 15s
name: "Ultrasonic TTGO"
id: ultra1
pulse_time: 20us
timeout: 3m
unit_of_measurement: m
- platform: dallas
address: 0x5B01204E88E46428
name: "Temp1"
id: Temp1
- platform: dallas
address: 0xD401204E90C71328
name: "Temp2"
id: Temp2
- platform: ads1115
name: "ADS1115 Channel A0-GND"
id: ads1115_a0
ads1115_id: ads1115_48
multiplexer: 'A0_GND'
gain: 6.144
update_interval: 90s
accuracy_decimals: 4
# filters:
# - calibrate_polynomial:
# degree: 2
# datapoints:
# - 0.00 -> -0.10
# - 0.04 -> 0.92
# - 0.20 -> 4.17
# - 0.37 -> 8.42
- platform: ads1115
name: "ADS1115 Channel A1-GND"
id: ads1115_a1
ads1115_id: ads1115_48
multiplexer: 'A1_GND'
gain: 6.144
update_interval: 90s
accuracy_decimals: 4
# filters:
# - calibrate_polynomial:
# degree: 2
# datapoints:
# - 0.00 -> -0.10
# - 0.04 -> 0.92
# - 0.20 -> 4.17
# - 0.37 -> 8.42
- platform: ads1115
name: "ADS1115 Channel A2-GND"
id: ads1115_a2
ads1115_id: ads1115_48
multiplexer: 'A2_GND'
gain: 6.144
update_interval: 90s
accuracy_decimals: 4
# filters:
# - calibrate_polynomial:
# degree: 2
# datapoints:
# - 0.00 -> -0.10
# - 0.04 -> 0.92
# - 0.20 -> 4.17
# - 0.37 -> 8.42
- platform: ads1115
name: "ADS1115 Channel A3-GND"
id: ads1115_a3
ads1115_id: ads1115_48
multiplexer: 'A3_GND'
gain: 6.144
update_interval: 90s
accuracy_decimals: 4
# filters:
# - calibrate_polynomial:
# degree: 2
# datapoints:
# - 0.00 -> -0.10
# - 0.04 -> 0.92
# - 0.20 -> 4.17
# - 0.37 -> 8.42
- platform: pulse_counter
pin: 37
unit_of_measurement: 'm/s'
name: 'Wind meter pulses counter'
update_interval: 60s
binary_sensor:
- platform: status
name: "Node Status"
id: system_status
- platform: gpio
pin:
number: GPIO0
inverted: true
name: "T-Display Button Input 0"
on_press:
then:
- switch.toggle: relay1
id: tdisplay_button_input_0
- platform: gpio
pin:
number: GPIO35
inverted: true
name: "T-Display Button Input 1"
on_press:
then:
- switch.toggle: relay2
id: tdisplay_button_input_1
# We can still control the backlight independently
switch:
- platform: gpio
pin: GPIO4
name: "Backlight"
id: backlight
- platform: gpio
pin: GPIO 12
name: "Relay1"
id: relay1
inverted: yes
- platform: gpio
pin: GPIO 13
name: "Relay2"
id: relay2
inverted: yes
- platform: gpio
pin: GPIO 15
name: "Relay3"
id: relay3
inverted: yes
- platform: gpio
pin: GPIO 17
name: "Relay4"
id: relay4
inverted: yes
#image:
# - file: "image.png"
# id: my_image
# resize: 200x200
# type: RGB565
#time:
# - platform: homeassistant
# id: esptime
spi:
clk_pin: GPIO18
mosi_pin: GPIO19
display:
- platform: st7789v
backlight_pin: GPIO4
cs_pin: GPIO5
update_interval: 1s
dc_pin: GPIO16
reset_pin: GPIO23
rotation: 270
lambda: |-
it.rectangle(0, 0, it.get_width(), it.get_height(), id(my_blue));
it.rectangle(0, 20, it.get_width(), it.get_height(), id(my_blue)); // header bar
it.strftime(7, 3, id(helvetica_14), id(my_gray), TextAlign::TOP_LEFT, "%H:%M:%S - %d.%m.%Y", id(esptime).now());
it.printf(7, 25 , id(helvetica_14), "Temp1: %.1f°C", id(Temp1).state);
it.printf(7, 45 , id(helvetica_14), "Temp2: %.1f°C", id(Temp2).state);
it.line(5, 65, 115, 65, id(my_gray));
it.line(115, 25, 115, 125, id(my_gray));
it.printf(7, 68 , id(helvetica_14), "Ultra: %.2f m", id(ultra1).state);
it.line(5, 87, 116, 87, id(my_gray));
if (id(relay1).state) {
it.filled_circle(17,110,10,id(my_green));
it.print(15, 103, id(helvetica_12), id(my_black), "1");
}
else {
it.filled_circle(17,110,10,id(my_red));
it.print(15, 103, id(helvetica_12), id(my_black), "1");
}
if (id(relay2).state) {
it.filled_circle(43,110,10,id(my_green));
it.print(40, 103, id(helvetica_12), id(my_black), "2");
}
else {
it.filled_circle(43,110,10,id(my_red));
it.print(40, 103, id(helvetica_12), id(my_black), "2");
}
if (id(relay3).state) {
it.filled_circle(69,110,10,id(my_green));
it.print(67, 103, id(helvetica_12), id(my_black), "3");
}
else {
it.filled_circle(69,110,10,id(my_red));
it.print(67, 103, id(helvetica_12), id(my_black), "3");
}
if (id(relay4).state) {
it.filled_circle(94,110,10,id(my_green));
it.print(91, 103, id(helvetica_12), id(my_black), "4");
}
else {
it.filled_circle(94,110,10,id(my_red));
it.print(91, 103, id(helvetica_12), id(my_black), "4");
}
it.printf(125, 25 , id(helvetica_14), "DAC1: %.3f", id(ads1115_a0).state);
it.printf(125, 52 , id(helvetica_14), "DAC2: %.3f", id(ads1115_a1).state);
it.printf(125, 79 , id(helvetica_14), "DAC2: %.3f", id(ads1115_a2).state);
it.printf(125, 106 , id(helvetica_14), "DAC2: %.3f", id(ads1115_a3).state);
if (id(system_status).state) {
it.print(235, 5, id(helvetica_12), id(my_green), TextAlign::TOP_RIGHT, "Online");
}
else {
it.print(235, 5, id(helvetica_12), id(my_red), TextAlign::TOP_RIGHT, "Offline");
}
