work: функционал для работы с вятяжкой
* Добавил полный функционал управления elica через esp32 по MQTT * Добавил в прошивку принудительную блокировку внешнего винтелятора при работающей вытяжке * Добавил веб-панели для управления вытяжкой
This commit is contained in:
@@ -80,6 +80,18 @@ globals:
|
||||
restore_value: no
|
||||
initial_value: '0xFF'
|
||||
|
||||
# Tracks the real Elica Power LED so OUT5 can be used as a hard
|
||||
# interlock for the external fan. The LED line is active LOW.
|
||||
- id: elica_power_initialized
|
||||
type: bool
|
||||
restore_value: no
|
||||
initial_value: 'false'
|
||||
|
||||
- id: elica_power_was_on
|
||||
type: bool
|
||||
restore_value: no
|
||||
initial_value: 'false'
|
||||
|
||||
script:
|
||||
- id: write_relays
|
||||
mode: restart
|
||||
@@ -114,12 +126,53 @@ interval:
|
||||
|
||||
id(input_state) = v;
|
||||
|
||||
// Elica Power LED is connected to IN5 (74HC165 mask 0x40).
|
||||
// IMPORTANT: on this board the 74HC165 raw state is inverted
|
||||
// relative to the MQTT binary_sensor state. Empirically:
|
||||
// raw bit 1 -> Elica Power LED ON, raw bit 0 -> LED OFF.
|
||||
const bool elica_power_on = (v & 0x40) != 0;
|
||||
bool relay5_changed = false;
|
||||
|
||||
if (!id(elica_power_initialized)) {
|
||||
id(elica_power_initialized) = true;
|
||||
|
||||
// If ESP32 boots while Elica is already running, enforce
|
||||
// the interlock immediately. If Elica is OFF, boot defaults
|
||||
// already leave Relay 5 OFF -> NC closed -> fan ON.
|
||||
if (elica_power_on && !(id(relay_state) & 0x10)) {
|
||||
id(relay_state) |= 0x10;
|
||||
relay5_changed = true;
|
||||
}
|
||||
} else if (elica_power_on) {
|
||||
// Hard interlock: while Elica is ON, Relay 5 must stay ON.
|
||||
// Relay 5 ON opens the NC contact and stops the external fan.
|
||||
if (!(id(relay_state) & 0x10)) {
|
||||
id(relay_state) |= 0x10;
|
||||
relay5_changed = true;
|
||||
}
|
||||
} else if (id(elica_power_was_on)) {
|
||||
// Elica has just switched OFF: automatically restore the
|
||||
// external fan. Relay 5 OFF closes NC and starts the fan.
|
||||
if (id(relay_state) & 0x10) {
|
||||
id(relay_state) &= ~0x10;
|
||||
relay5_changed = true;
|
||||
}
|
||||
}
|
||||
|
||||
id(elica_power_was_on) = elica_power_on;
|
||||
|
||||
// Shared bus changed while reading 74HC165:
|
||||
// restore the requested relay state in 74HC595.
|
||||
digitalWrite(25, LOW);
|
||||
shiftOut(33, 26, MSBFIRST, ~id(relay_state));
|
||||
digitalWrite(25, HIGH);
|
||||
|
||||
// Keep MQTT/web-server state in sync when the interlock itself
|
||||
// changes Relay 5 rather than an external command doing it.
|
||||
if (relay5_changed) {
|
||||
id(relay5).publish_state((id(relay_state) & 0x10) != 0);
|
||||
}
|
||||
|
||||
switch:
|
||||
- platform: template
|
||||
name: "Relay 1"
|
||||
@@ -177,6 +230,15 @@ switch:
|
||||
command_topic: "elica/relay/4/set"
|
||||
state_topic: "elica/relay/4/state"
|
||||
|
||||
# OUT5 управляет внешним вентилятором через NC-контакт.
|
||||
# relay5=OFF -> NC замкнут -> внешний вентилятор ВКЛ.
|
||||
# relay5=ON -> NC разомкнут -> внешний вентилятор ВЫКЛ.
|
||||
#
|
||||
# HARD INTERLOCK по фактическому Power LED Elica (IN5):
|
||||
# Elica ON -> Relay 5 принудительно ON -> внешний вентилятор OFF.
|
||||
# Elica OFF -> при переходе автоматически Relay 5 OFF -> вентилятор ON.
|
||||
# Пока Elica включена, MQTT-команда Relay 5 OFF игнорируется, чтобы
|
||||
# внешний вентилятор нельзя было случайно включить одновременно с Elica.
|
||||
- platform: template
|
||||
name: "Relay 5"
|
||||
id: relay5
|
||||
@@ -186,7 +248,15 @@ switch:
|
||||
- lambda: id(relay_state) |= 0x10;
|
||||
- script.execute: write_relays
|
||||
turn_off_action:
|
||||
- lambda: id(relay_state) &= ~0x10;
|
||||
- lambda: |-
|
||||
// Use the same raw IN5 polarity as the interlock above:
|
||||
// raw bit 1 means the Elica Power LED is ON.
|
||||
const bool elica_power_on = (id(input_state) & 0x40) != 0;
|
||||
if (elica_power_on) {
|
||||
id(relay_state) |= 0x10;
|
||||
} else {
|
||||
id(relay_state) &= ~0x10;
|
||||
}
|
||||
- script.execute: write_relays
|
||||
command_topic: "elica/relay/5/set"
|
||||
state_topic: "elica/relay/5/state"
|
||||
|
||||
Reference in New Issue
Block a user