Yesterday, wanting to optimize the management of my aquarium, I programmed an ESP32 with esphome to use together with a display (model ST7735S), two temperature probes (models DS18B20) and a board with four relays (model Relay Module HL-545). Everything works fine except the relays that turn on and off continuously and very quickly (they seem to have gone crazy - HERE A VIDEO). What could it depend on? Is there a remedy? I also attach the script I created:
esphome:
name: acquario
friendly_name: Acquario
esp32:
board: esp32dev
framework:
type: arduino
# Enable logging
logger:
# Enable Home Assistant API
api:
encryption:
key: "ozvPV2wyKf+udUw/+d7mKFUWLqmGutMGeHqYo6MGDgI="
ota:
- platform: esphome
password: "77dcc783e1eff9029aa4bb80054339c7"
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
manual_ip:
static_ip: 192.168.178.150
gateway: 192.168.178.1
subnet: 255.255.255.0
dns1: 192.168.178.1
spi:
clk_pin: GPIO18
mosi_pin: GPIO23
# MISO non è usato per il display ST7735S
color:
- id: my_red
red: 100%
green: 3%
blue: 5%
- id: my_blu
red: 5%
green: 3%
blue: 100%
- id: my_green
red: 5%
green: 100%
blue: 3%
- id: my_yellow
hex: ffff00
- id: my_fucsia
hex: f400a1
- id: my_orange
hex: b27300
display:
- platform: ili9xxx
model: ST7735
cs_pin: GPIO5
dc_pin: GPIO2
reset_pin: GPIO4
rotation: 180
invert_colors: false
# show_test_card: true
update_interval: 1s
lambda: |-
it.print(25, 0, id(fonts1), id(my_fucsia), "ACQUARIO:");
it.rectangle (0, 17.5, 128, 75, id(my_yellow));
it.print(5, 19, id(fonts), id(my_blu), "Luci:");
if (id(relay_1).state) {
it.print(67, 19, id(fonts), id(my_green), "ON");
} else {
it.print(67, 19, id(fonts), id(my_red), "OFF");
}
it.print(5, 35, id(fonts), id(my_blu), "Filtro:");
if (id(relay_2).state) {
it.print(67, 35, id(fonts), id(my_green), "ON");
} else {
it.print(67, 35, id(fonts), id(my_red), "OFF");
}
it.print(5, 51, id(fonts), id(my_blu), "Aria:");
if (id(relay_3).state) {
it.print(67, 51, id(fonts), id(my_green), "ON");
} else {
it.print(67, 50, id(fonts), id(my_red), "OFF");
}
it.print(5, 67, id(fonts), id(my_blu), "Riscald.:");
if (id(relay_4).state) {
it.print(67, 67, id(fonts), id(my_green), "ON");
} else {
it.print(67, 67, id(fonts), id(my_red), "OFF");
}
it.rectangle (0, 90, 128, 25, id(my_yellow));
it.rectangle (0, 90, 128, 70, id(my_yellow));
if (id(water_temp).state > 23, id(water_temp).state < 27) {
it.printf(5, 120, id(fonts1), id(my_green), "Temp: %.1f°", id(water_temp).state);
}
if (id(water_temp).state < 23) {
it.printf(5, 120, id(fonts1), id(my_orange), "Temp: %.1f°", id(water_temp).state);
}
if (id(water_temp).state > 27) {
it.printf(5, 120, id(fonts1), id(my_red), "Temp: %.1f°", id(water_temp).state);
}
font:
- file: "fonts/arial.ttf"
id: fonts
size: 16
- file: "fonts/arial.ttf"
id: fonts1
size: 14
# Definizione dei relè e interruttori
switch:
- platform: gpio
pin: GPIO13
id: relay_1
name: "Relay 1"
- platform: gpio
pin: GPIO12
id: relay_2
name: "Relay 2"
- platform: gpio
pin: GPIO14
id: relay_3
name: "Relay 3"
- platform: gpio
pin: GPIO27
id: relay_4
name: "Relay 4"
binary_sensor:
- platform: gpio
pin: GPIO32
id: switch_1
name: "Interruttore 1"
on_press:
- switch.toggle: relay_1
- platform: gpio
pin: GPIO33
id: switch_2
name: "Interruttore 2"
on_press:
- switch.toggle: relay_2
- platform: gpio
pin: GPIO25
id: switch_3
name: "Interruttore 3"
on_press:
- switch.toggle: relay_3
- platform: gpio
pin: GPIO26
id: switch_4
name: "Interruttore 4"
on_press:
- switch.toggle: relay_4
sensor:
- platform: dallas_temp
address: 0x7d01131bc3749c28
name: "Temperatura Acqua"
id: water_temp
update_interval: 5s
- platform: dallas_temp
address: 0x9401131bbc62f728
name: "Temperatura Ambiente"
id: temp_ambiente
update_interval: 5s
one_wire:
- platform: gpio
pin: GPIO22
I hope you can help me.
Bye and thanks