I have set up an ESP32 system where both the ESP32 itself and my MOSFET relay module are clearly receiving power, as the status LEDs on both are lit. However, the system is not working as expected.
My temperature sensor is not providing any data to the ESP32, even though I have connected it according to the instructions, namely to D2 (data), GND, and 3.3 volts. At the same time, I connected the MOSFET relay module using two jumper wires to D18 and also to 3.3 volts. However, I am neither able to read temperature values nor control the current flow through the MOSFET relay module.
This leaves me uncertain about where the issue lies. Either there is something wrong with my ESPHome configuration or code, or I have made a fundamental mistake in the wiring or in my understanding of the components.
The code nach dem grundlegenden Code
captive_portal:
OneWire Bus
one_wire:
ˋˋ- platform: gpio
ˋˋˋˋpin: GPIO4
ˋˋˋˋid: bus_a
Temperatur Sensor
sensor:
ˋˋ- platform: dallas_temp
ˋˋˋˋname: “Temperatur”
ˋˋˋˋid: temp_sensor
ˋˋˋˋone_wire_id: bus_a
ˋˋˋˋupdate_interval: 10s
ˋˋˋˋon_value:
ˋˋˋˋˋˋthen:
ˋˋˋˋˋˋˋˋ- lambda: |-
ˋˋˋˋˋˋˋˋˋˋˋˋˋ// MANUELLER OVERRIDE
ˋˋˋˋˋˋˋˋˋˋˋˋˋif (id(manual_override).state) {
ˋˋˋˋˋˋˋˋˋˋˋˋˋid(relais).turn_on();
ˋˋˋˋˋˋˋˋˋˋˋˋˋreturn;
ˋˋˋˋˋˋˋˋˋˋˋˋˋ}
// Failsafe: Sensorfehler
if (isnan(x)) {
id(relais).turn_off();
return;
}
static bool hot_active = false;
static bool cold_active = false;
float high_on = id(temp_high_on).state;
float high_off = id(temp_high_off).state;
float low_on = id(temp_low_on).state;
float low_off = id(temp_low_off).state;
// HITZE (Lüfter)
if (!hot_active && x >= high_on) {
hot_active = true;
id(relais).turn_on();
} else if (hot_active && x <= high_off) {
hot_active = false;
if (!cold_active) {
id(relais).turn_off();
}
}
// KÄLTE (Frostschutz)
if (!cold_active && x <= low_on) {
cold_active = true;
id(relais).turn_on();
} else if (cold_active && x >= low_off) {
cold_active = false;
if (!hot_active) {
id(relais).turn_off();
}
}
Einstellbare Werte (Home Assistant)
number:
ˋˋ- platform: template
ˋˋˋˋname: “Max Temperatur Lüfter an”
ˋˋˋˋid: temp_high_on
ˋˋˋˋmin_value: 20
ˋˋˋˋmax_value: 40
ˋˋˋˋstep: 0.5
ˋˋˋˋinitial_value: 30
ˋˋˋˋrestore_value: true
ˋˋˋˋoptimistic: true
ˋˋ- platform: template
ˋˋˋˋname: “Max Temperatur Lüfter aus”
ˋˋˋˋid: temp_high_off
ˋˋˋˋmin_value: 20
ˋˋˋˋmax_value: 40
ˋˋˋˋstep: 0.5
ˋˋˋˋinitial_value: 28
ˋˋˋˋrestore_value: true
ˋˋˋˋoptimistic: true
ˋˋ- platform: template
ˋˋˋˋname: “Min Temperatur Frost an”
ˋˋˋˋid: temp_low_on
ˋˋˋˋmin_value: -10
ˋˋˋˋmax_value: 10
ˋˋˋˋstep: 0.5
ˋˋˋˋinitial_value: 5
ˋˋˋˋrestore_value: true
ˋˋˋˋoptimistic: true
ˋˋ- platform: template
ˋˋˋˋname: “Min Temperatur Frost aus”
ˋˋˋˋid: temp_low_off
ˋˋˋˋmin_value: -10
ˋˋˋˋmax_value: 10
ˋˋˋˋstep: 0.5
ˋˋˋˋinitial_value: 7
ˋˋˋˋrestore_value: true
ˋˋˋˋoptimistic: true
switch:
ˋˋ- platform: gpio
ˋˋˋˋpin: GPIO18
ˋˋˋˋid: relais
ˋˋˋˋinternal: True
ˋˋˋˋname: “Lüfter Frostschutz”
ˋˋˋˋrestore_mode: RESTORE_DEFAULT_OFF
ˋˋ- platform: template
ˋˋˋˋname: “Manueller Override”
ˋˋˋˋid: manual_override
ˋˋˋˋoptimistic: true
