107 lines
2.7 KiB
YAML
107 lines
2.7 KiB
YAML
# ===================================================================
|
|
# ESPHome Configuration
|
|
# CAN-Bus Master für ein Bewässerungssystem auf Basis des ESP32-C6
|
|
#
|
|
# Version 10: Finale Korrektur der Lambda-Signatur gemäß Dokumentation
|
|
# ===================================================================
|
|
|
|
esphome:
|
|
name: can-bridge
|
|
friendly_name: Irrigation can bridge
|
|
|
|
esp32:
|
|
board: esp32-c6-devkitm-1
|
|
framework:
|
|
type: esp-idf # Erforderlich für den ESP32-C6
|
|
|
|
# --- Netzwerk & Sicherheit ---
|
|
wifi:
|
|
ssid: !secret wifi_ssid
|
|
password: !secret wifi_password
|
|
fast_connect: true
|
|
|
|
api:
|
|
encryption:
|
|
key: !secret api_key
|
|
|
|
ota:
|
|
platform: esphome
|
|
password: !secret ota_password
|
|
|
|
logger:
|
|
|
|
web_server:
|
|
|
|
# --- Globale Variablen ---
|
|
globals:
|
|
- id: ventil_2_can_state
|
|
type: int
|
|
initial_value: '0' # Startet als "geschlossen"
|
|
|
|
# --- CAN-Bus Konfiguration ---
|
|
canbus:
|
|
- platform: esp32_can
|
|
id: my_can_bus
|
|
tx_pin: GPIO5
|
|
rx_pin: GPIO4
|
|
bit_rate: 125kbps
|
|
can_id: 0x000 # Erforderlich, um Parser-Fehler zu beheben.
|
|
on_frame:
|
|
# Horcht nur auf die Statusmeldung von Knoten 2 (ID 0x422)
|
|
- can_id: 0x422
|
|
then:
|
|
- lambda: |-
|
|
if (x.size() < 1) {
|
|
ESP_LOGW("on_can_frame", "Received empty Frame for ID 0x422");
|
|
return;
|
|
}
|
|
int received_state = x[0];
|
|
id(ventil_2_can_state) = received_state;
|
|
ESP_LOGD("on_can_frame", "Received state from Valve 2: %i", received_state);
|
|
- valve.template.publish:
|
|
id: ventil_2
|
|
current_operation: !lambda |-
|
|
int state = id(ventil_2_can_state);
|
|
if (state == 2) {
|
|
return VALVE_OPERATION_OPENING;
|
|
} else if (state == 3) {
|
|
return VALVE_OPERATION_CLOSING;
|
|
} else {
|
|
return VALVE_OPERATION_IDLE;
|
|
}
|
|
|
|
# --- Home Assistant Entitäten ---
|
|
valve:
|
|
- platform: template
|
|
name: "Ventil 2"
|
|
id: ventil_2
|
|
|
|
# Diese Lambda meldet nur den binären End-Zustand (offen/geschlossen)
|
|
lambda: |-
|
|
if (id(ventil_2_can_state) == 0) {
|
|
return VALVE_CLOSED;
|
|
} else if (id(ventil_2_can_state) == 1) {
|
|
return VALVE_OPEN;
|
|
} else {
|
|
return NAN;
|
|
}
|
|
|
|
# Aktionen zum Steuern des Ventils
|
|
open_action:
|
|
- canbus.send:
|
|
canbus_id: my_can_bus
|
|
can_id: 0x210
|
|
data: [0x02, 0x01]
|
|
|
|
close_action:
|
|
- canbus.send:
|
|
canbus_id: my_can_bus
|
|
can_id: 0x210
|
|
data: [0x02, 0x00]
|
|
|
|
stop_action:
|
|
- canbus.send:
|
|
canbus_id: my_can_bus
|
|
can_id: 0x210
|
|
data: [0x02, 0x03]
|