380 lines
8.8 KiB
YAML
380 lines
8.8 KiB
YAML
substitutions:
|
|
device_name: tor-steuerung
|
|
friendly_name: Tor Steuerung
|
|
firmware_version: "1.0.0-rc1"
|
|
|
|
wifi_1_ssid: "Leonardo da WiFi"
|
|
wifi_1_password: "44290812080358610465"
|
|
|
|
# Weitere WLANs bei Bedarf aktivieren.
|
|
# wifi_2_ssid: "Werkstatt"
|
|
# wifi_2_password: "PASSWORT"
|
|
# wifi_3_ssid: "Hotspot"
|
|
# wifi_3_password: "PASSWORT"
|
|
|
|
esphome:
|
|
name: ${device_name}
|
|
friendly_name: ${friendly_name}
|
|
comment: "Autonome CC1101 433 MHz Torsteuerung ${firmware_version}"
|
|
|
|
esp32:
|
|
board: esp32dev
|
|
framework:
|
|
type: esp-idf
|
|
version: recommended
|
|
|
|
logger:
|
|
level: INFO
|
|
|
|
api:
|
|
encryption:
|
|
key: "X2kSHZmeEbdPtMBlxB67cJ4/WMNkQOPCstqYiUQlL2g="
|
|
|
|
ota:
|
|
- platform: esphome
|
|
password: "4bd4f24d4a26730d06e84d6e0816fb09"
|
|
|
|
wifi:
|
|
reboot_timeout: 0s
|
|
power_save_mode: none
|
|
|
|
networks:
|
|
- ssid: ${wifi_1_ssid}
|
|
password: ${wifi_1_password}
|
|
|
|
# - ssid: ${wifi_2_ssid}
|
|
# password: ${wifi_2_password}
|
|
|
|
# - ssid: ${wifi_3_ssid}
|
|
# password: ${wifi_3_password}
|
|
|
|
ap:
|
|
ssid: "Torsteuerung"
|
|
password: "Spring.3"
|
|
|
|
captive_portal:
|
|
|
|
debug:
|
|
update_interval: 60s
|
|
|
|
globals:
|
|
- id: total_packets
|
|
type: uint32_t
|
|
restore_value: true
|
|
initial_value: "0"
|
|
|
|
- id: valid_packets
|
|
type: uint32_t
|
|
restore_value: true
|
|
initial_value: "0"
|
|
|
|
- id: rejected_packets
|
|
type: uint32_t
|
|
restore_value: true
|
|
initial_value: "0"
|
|
|
|
- id: gate_open_count
|
|
type: uint32_t
|
|
restore_value: true
|
|
initial_value: "0"
|
|
|
|
- id: last_open_ms
|
|
type: uint32_t
|
|
restore_value: false
|
|
initial_value: "0"
|
|
|
|
- id: last_packet_ms
|
|
type: uint32_t
|
|
restore_value: false
|
|
initial_value: "0"
|
|
|
|
- id: last_vehicle_id
|
|
type: int
|
|
restore_value: true
|
|
initial_value: "0"
|
|
|
|
- id: last_rssi_value
|
|
type: float
|
|
restore_value: true
|
|
initial_value: "-127.0"
|
|
|
|
- id: last_lqi_value
|
|
type: int
|
|
restore_value: true
|
|
initial_value: "0"
|
|
|
|
spi:
|
|
clk_pin: GPIO18
|
|
mosi_pin: GPIO23
|
|
miso_pin: GPIO19
|
|
|
|
cc1101:
|
|
cs_pin: GPIO5
|
|
gdo0_pin: GPIO17
|
|
|
|
frequency: 433.92MHz
|
|
modulation_type: GFSK
|
|
symbol_rate: 4800
|
|
|
|
packet_mode: true
|
|
packet_length: 4
|
|
crc_enable: true
|
|
|
|
sync0: 0x91
|
|
sync1: 0xD3
|
|
|
|
on_packet:
|
|
then:
|
|
- lambda: |-
|
|
const char *tag = "tor_433";
|
|
const uint32_t now = millis();
|
|
id(total_packets) += 1;
|
|
id(last_packet_ms) = now;
|
|
|
|
if (data.size() != 4) {
|
|
id(rejected_packets) += 1;
|
|
id(last_event_text).publish_state("Verworfen: falsche Paketlaenge");
|
|
ESP_LOGW(tag, "Paket verworfen: falsche Laenge (%u)", data.size());
|
|
return;
|
|
}
|
|
|
|
if (data[0] != 0xA7 || data[1] != 0x3C) {
|
|
id(rejected_packets) += 1;
|
|
id(last_event_text).publish_state("Verworfen: falsche Magic Bytes");
|
|
ESP_LOGW(tag, "Paket verworfen: Magic Bytes %02X %02X", data[0], data[1]);
|
|
return;
|
|
}
|
|
|
|
const int vehicle_id = data[2];
|
|
const int reserve = data[3];
|
|
id(last_vehicle_id) = vehicle_id;
|
|
id(last_rssi_value) = rssi;
|
|
id(last_lqi_value) = lqi;
|
|
|
|
id(last_vehicle_sensor).publish_state(vehicle_id);
|
|
id(last_rssi_sensor).publish_state(rssi);
|
|
id(last_lqi_sensor).publish_state(lqi);
|
|
|
|
ESP_LOGI(tag, "Paket: id=%d reserve=%d rssi=%.1f lqi=%d", vehicle_id, reserve, rssi, lqi);
|
|
|
|
if (vehicle_id < 1 || vehicle_id > 10) {
|
|
id(rejected_packets) += 1;
|
|
id(last_event_text).publish_state("Verworfen: Fahrzeug-ID nicht erlaubt");
|
|
ESP_LOGW(tag, "Paket verworfen: Fahrzeug-ID %d nicht erlaubt", vehicle_id);
|
|
return;
|
|
}
|
|
|
|
if (rssi < id(rssi_limit).state) {
|
|
id(rejected_packets) += 1;
|
|
id(last_event_text).publish_state("Verworfen: RSSI zu schwach");
|
|
ESP_LOGW(tag, "Paket verworfen: RSSI %.1f kleiner als Grenze %.1f", rssi, id(rssi_limit).state);
|
|
return;
|
|
}
|
|
|
|
const uint32_t lockout_ms = (uint32_t) (id(lockout_seconds).state * 1000.0f);
|
|
if (id(last_open_ms) != 0 && (now - id(last_open_ms)) < lockout_ms) {
|
|
id(rejected_packets) += 1;
|
|
id(last_event_text).publish_state("Verworfen: Sperrzeit aktiv");
|
|
ESP_LOGI(tag, "Paket ignoriert: Sperrzeit aktiv (%u ms verbleibend)", lockout_ms - (now - id(last_open_ms)));
|
|
return;
|
|
}
|
|
|
|
id(valid_packets) += 1;
|
|
|
|
if (id(test_mode).state) {
|
|
id(last_event_text).publish_state("Testmodus: Oeffnung waere erfolgt");
|
|
ESP_LOGI(tag, "Testmodus aktiv: Relais wird nicht geschaltet");
|
|
return;
|
|
}
|
|
|
|
id(last_open_ms) = now;
|
|
id(gate_open_count) += 1;
|
|
id(last_event_text).publish_state("Torimpuls ausgeloest");
|
|
ESP_LOGI(tag, "Torimpuls ausgeloest durch Fahrzeug-ID %d", vehicle_id);
|
|
id(trigger_gate).execute();
|
|
|
|
switch:
|
|
- platform: gpio
|
|
pin: GPIO16
|
|
id: tor_impuls_relay
|
|
name: "Tor Impuls"
|
|
restore_mode: ALWAYS_OFF
|
|
|
|
- platform: template
|
|
id: test_mode
|
|
name: "Testmodus"
|
|
optimistic: true
|
|
restore_mode: RESTORE_DEFAULT_OFF
|
|
entity_category: config
|
|
|
|
binary_sensor:
|
|
- platform: gpio
|
|
pin: GPIO34
|
|
name: "Tor AUF"
|
|
device_class: door
|
|
|
|
- platform: gpio
|
|
pin: GPIO35
|
|
name: "Tor ZU"
|
|
device_class: door
|
|
|
|
- platform: status
|
|
name: "${friendly_name} Status"
|
|
|
|
number:
|
|
- platform: template
|
|
id: rssi_limit
|
|
name: "RSSI Grenze"
|
|
min_value: -100
|
|
max_value: -30
|
|
step: 1
|
|
initial_value: -60
|
|
restore_value: true
|
|
optimistic: true
|
|
unit_of_measurement: "dBm"
|
|
entity_category: config
|
|
|
|
- platform: template
|
|
id: lockout_seconds
|
|
name: "Sperrzeit"
|
|
min_value: 5
|
|
max_value: 300
|
|
step: 1
|
|
initial_value: 60
|
|
restore_value: true
|
|
optimistic: true
|
|
unit_of_measurement: "s"
|
|
entity_category: config
|
|
|
|
script:
|
|
- id: trigger_gate
|
|
mode: single
|
|
then:
|
|
- switch.turn_on: tor_impuls_relay
|
|
- delay: 500ms
|
|
- switch.turn_off: tor_impuls_relay
|
|
|
|
sensor:
|
|
- platform: wifi_signal
|
|
name: "${friendly_name} WLAN Signal"
|
|
update_interval: 60s
|
|
|
|
- platform: uptime
|
|
name: "${friendly_name} Laufzeit"
|
|
update_interval: 60s
|
|
|
|
- platform: template
|
|
id: last_vehicle_sensor
|
|
name: "Letzte Fahrzeug-ID"
|
|
accuracy_decimals: 0
|
|
lambda: |-
|
|
return id(last_vehicle_id);
|
|
update_interval: 60s
|
|
|
|
- platform: template
|
|
id: last_rssi_sensor
|
|
name: "Letzter RSSI"
|
|
unit_of_measurement: "dBm"
|
|
accuracy_decimals: 1
|
|
lambda: |-
|
|
return id(last_rssi_value);
|
|
update_interval: 60s
|
|
|
|
- platform: template
|
|
id: last_lqi_sensor
|
|
name: "Letzter LQI"
|
|
accuracy_decimals: 0
|
|
lambda: |-
|
|
return id(last_lqi_value);
|
|
update_interval: 60s
|
|
|
|
- platform: template
|
|
name: "Pakete gesamt"
|
|
accuracy_decimals: 0
|
|
lambda: |-
|
|
return id(total_packets);
|
|
update_interval: 60s
|
|
|
|
- platform: template
|
|
name: "Pakete gueltig"
|
|
accuracy_decimals: 0
|
|
lambda: |-
|
|
return id(valid_packets);
|
|
update_interval: 60s
|
|
|
|
- platform: template
|
|
name: "Pakete verworfen"
|
|
accuracy_decimals: 0
|
|
lambda: |-
|
|
return id(rejected_packets);
|
|
update_interval: 60s
|
|
|
|
- platform: template
|
|
name: "Toroeffnungen"
|
|
accuracy_decimals: 0
|
|
lambda: |-
|
|
return id(gate_open_count);
|
|
update_interval: 60s
|
|
|
|
- platform: template
|
|
name: "Sekunden seit letztem Paket"
|
|
unit_of_measurement: "s"
|
|
accuracy_decimals: 0
|
|
lambda: |-
|
|
if (id(last_packet_ms) == 0) return {};
|
|
return (millis() - id(last_packet_ms)) / 1000.0f;
|
|
update_interval: 10s
|
|
|
|
- platform: template
|
|
name: "Sekunden seit letzter Toroeffnung"
|
|
unit_of_measurement: "s"
|
|
accuracy_decimals: 0
|
|
lambda: |-
|
|
if (id(last_open_ms) == 0) return {};
|
|
return (millis() - id(last_open_ms)) / 1000.0f;
|
|
update_interval: 10s
|
|
|
|
- platform: debug
|
|
free:
|
|
name: "${friendly_name} Freier Heap"
|
|
|
|
text_sensor:
|
|
- platform: version
|
|
name: "${friendly_name} ESPHome Version"
|
|
|
|
- platform: template
|
|
name: "${friendly_name} Firmware Version"
|
|
lambda: |-
|
|
return {"${firmware_version}"};
|
|
|
|
- platform: template
|
|
id: last_event_text
|
|
name: "Letztes 433 MHz Ereignis"
|
|
|
|
- platform: debug
|
|
reset_reason:
|
|
name: "${friendly_name} Neustartgrund"
|
|
|
|
- platform: wifi_info
|
|
ip_address:
|
|
name: "${friendly_name} IP"
|
|
ssid:
|
|
name: "${friendly_name} WLAN SSID"
|
|
mac_address:
|
|
name: "${friendly_name} MAC"
|
|
|
|
button:
|
|
- platform: restart
|
|
name: "${friendly_name} Neustart"
|
|
|
|
- platform: template
|
|
name: "Zaehler zuruecksetzen"
|
|
entity_category: config
|
|
on_press:
|
|
- lambda: |-
|
|
id(total_packets) = 0;
|
|
id(valid_packets) = 0;
|
|
id(rejected_packets) = 0;
|
|
id(gate_open_count) = 0;
|
|
id(last_event_text).publish_state("Zaehler zurueckgesetzt");
|