ESPHome-Konfigs für CC1101-Funksender/-empfänger inkl. Flash-Anleitung

- Sender (ESP32-C3 Super Mini) und Empfänger (ESP32-S3), beide mit CC1101 433 MHz
- README dokumentiert USB-TTL-Anschluss, da der interne USB-Serial/JTAG
  nach Zadig unter Windows 11 nicht mehr nutzbar ist
- Verdrahtungsschema CC1101 als SVG
This commit is contained in:
Dominic
2026-07-23 18:20:55 +00:00
commit 32e8277e4b
5 changed files with 555 additions and 0 deletions
+3
View File
@@ -0,0 +1,3 @@
secrets.yaml
.esphome/
*.bin
+215
View File
@@ -0,0 +1,215 @@
# Funksender Tor
Automatische Toröffnung per 433 MHz. Jedes Fahrzeug bekommt einen kleinen Sender
am Zündungsplus, der Empfänger am Tor öffnet, sobald ein bekanntes Fahrzeug nah
genug ist. Kein Knopfdruck, keine App, kein Account.
**Hardware:** ESP32-C3 Super Mini + CC1101 (433 MHz) je Sender,
ESP32-S3 + CC1101 als Empfänger am Tor.
---
## Inhalt
- [Verdrahtung CC1101](#verdrahtung-cc1101)
- [Flashen](#flashen) — **hier steht der USB-TTL-Kram**
- [ESPHome einrichten](#esphome-einrichten)
- [Reichweite einstellen](#reichweite-einstellen)
- [Weiteres Fahrzeug hinzufügen](#weiteres-fahrzeug-hinzufügen)
- [Paketformat](#paketformat)
---
## Verdrahtung CC1101
Die Pins des CC1101 sitzen als **4 Zeilen à 2 Pins**, Antenne rechts:
```
① GND │ VDD ②
③ GDO0 │ CSN ④
⑤ SCK │ MOSI ⑥
⑦ MISO │ GDO2 ⑧
```
> **Achtung:** Pin 1 ist **GND**, Pin 2 ist **VDD**. Nicht die verbreitete
> Belegung mancher anderer CC1101-Boards annehmen, wo es umgekehrt ist —
> Vertauschen macht das Modul und ggf. den ESP heiß.
| CC1101 | Signal | ESP32-C3 Super Mini |
|--------|--------|---------------------|
| 1 | GND | `G` (links) |
| 2 | VDD | `3.3` (links) — **niemals 5V** |
| 3 | GDO0 | `GPIO3` (links) |
| 4 | CSN | `GPIO4` (links) |
| 5 | SCK | `GPIO6` (rechts) |
| 6 | MOSI | `GPIO7` (rechts) |
| 7 | MISO | `GPIO5` (rechts) |
| 8 | GDO2 | *frei lassen* |
Schema: [`doku/verdrahtung-cc1101.svg`](doku/verdrahtung-cc1101.svg)
Beim Empfänger (ESP32-S3) sind die SPI-Pins in `tor_empfaenger.yaml` noch
Platzhalter und müssen an die tatsächliche Verdrahtung angepasst werden.
---
## Flashen
### Warum nicht über den USB-C-Anschluss?
Der ESP32-C3 hat einen eingebauten USB-Serial/JTAG-Controller. Unter Windows 11
sollte er automatisch als COM-Port erscheinen — **tut er aber nicht mehr, sobald
Zadig einmal auf ihm gelaufen ist.**
Was passiert war: Zadig ersetzt den nativen `usbser.sys` durch WinUSB bzw.
selbstgenerierte libwdi/libusbK-Treiber. Danach zeigt der Geräte-Manager zwar
einen COM-Port, aber esptool bekommt nur
```
A fatal error occurred: Failed to connect to ESP32-C3: No serial data received.
```
Das lässt sich reparieren (siehe unten), ist aber fummelig. **Der USB-TTL-Adapter
umgeht das Thema komplett.**
### USB-TTL-Adapter anschließen ← *das ist der Weg, der funktioniert hat*
> **Adapter zwingend auf 3.3 V jumpern.** Der ESP32-C3 ist nicht 5V-tolerant.
| USB-TTL-Adapter | ESP32-C3 Super Mini |
|-----------------|---------------------|
| TX | `GPIO20` (rechts, vorletzter Pin) |
| RX | `GPIO21` (rechts, letzter Pin) |
| GND | `G` (links, 2. Pin) |
| 3.3V | `3.3` (links, 3. Pin) |
TX und RX sind **gekreuzt** — das ist so richtig.
Das CC1101 kann angeschlossen bleiben, GPIO20/21 kollidieren mit nichts.
Liefert der Adapter auf 3.3 V zu wenig Strom, den ESP stattdessen über ein
USB-Netzteil an der USB-C-Buchse versorgen und vom Adapter nur TX, RX und GND
anschließen. **Nicht beide Quellen gleichzeitig.**
### Boot-Modus
**`GPIO9``G` brücken, danach erst Strom drauf.** Reihenfolge ist wichtig.
Nach dem Flashen die Brücke wieder entfernen.
### Ablauf
```bash
# 1. Verbindung prüfen — COM-Port des TTL-Adapters aus dem Geräte-Manager
python -m esptool --chip esp32c3 --port COM16 chip-id
```
Erwartete Ausgabe:
```
Chip type: ESP32-C3 AZ (QFN32) (revision v1.1)
Features: Wi-Fi, BT 5 (LE), Single Core, 160MHz, Embedded Flash 4MB (XMC)
MAC: 44:b1:76:18:cb:ec
```
```bash
# 2. Factory-Image flashen (nicht die normale .bin!)
python -m esptool --chip esp32c3 --port COM16 --baud 460800 \
write-flash 0x0 auto-sender-01.factory.bin
```
Bricht es bei 460800 ab, mit `--baud 115200` wiederholen.
Danach GPIO9-Brücke raus, Strom aus/an. Ab hier läuft alles über OTA —
der Adapter wird nicht mehr gebraucht.
`esptool` installieren falls nötig: `pip install esptool`
### Falls der interne USB doch mal repariert werden soll
Als Administrator:
```cmd
pnputil /enum-drivers | findstr /i "libwdi libusb"
pnputil /delete-driver oemXX.inf /uninstall /force
```
Alle gefundenen libwdi/libusbK-Pakete löschen, besonders das mit
`MS_COMP_USBSER` — das kapert systemweit jedes CDC-Gerät. Danach neu starten.
Windows zieht dann wieder `usbser.sys`.
**Zadig nicht mehr auf den ESP32-C3 loslassen.** Für den eingebauten
USB-Serial/JTAG ist es das falsche Werkzeug (außer man will JTAG-Debugging
über OpenOCD).
---
## ESPHome einrichten
Beide YAMLs erwarten in `secrets.yaml`:
```yaml
wifi_ssid: "..."
wifi_password: "..."
api_key: "..." # base64, 32 Byte
ota_password: "..."
```
1. In ESPHome (HA-Add-on) neues Gerät anlegen
2. Inhalt der passenden Datei aus `esphome/` einfügen
3. Drei Punkte → **Install****Manual download****Factory format**
4. Mit esptool flashen (siehe oben)
`reboot_timeout: 0s` beim Sender ist kein Versehen: im Auto ist kein WLAN in
Reichweite, ohne diese Zeile startet der ESP alle 15 Minuten neu.
---
## Reichweite einstellen
Die Reichweite wird **nicht** am Sender begrenzt — alle Sender laufen mit voller
Leistung. Der Empfänger entscheidet anhand der Signalstärke (RSSI), ob das
Fahrzeug nah genug ist.
Der Schwellwert liegt als Schieberegler **„RSSI Schwelle"** in Home Assistant,
Änderungen brauchen kein Neuflashen.
Einmessen:
1. Empfänger-Log in ESPHome öffnen
2. Mit dem Fahrzeug in verschiedenen Abständen anhalten
3. RSSI-Werte notieren — z. B. `Fahrzeug 1, RSSI -73.5 dBm, LQI 12`
4. Den Wert bei der gewünschten Distanz (~5 m) als Schwelle setzen
Je näher der Wert an 0, desto kürzer die Reichweite. Startwert ist `-60`.
Nach jeder Öffnung greift eine **Sperrzeit von 60 Sekunden**.
---
## Weiteres Fahrzeug hinzufügen
In `auto_sender_01.yaml` nur die beiden Substitutions oben ändern:
```yaml
substitutions:
geraet: auto-sender-02
fahrzeug_id: "0x02"
```
Der Empfänger akzeptiert IDs `0x01` bis `0x0A` (110) und muss dafür **nicht**
angefasst werden. Sollen weniger Fahrzeuge erlaubt sein, im `on_packet`-Lambda
die Zeile `if (fz < 1 || fz > 10)` anpassen.
---
## Paketformat
4 Bytes, GFSK, 4800 Baud, CRC-16 aktiv, Sync `0xD391`:
| Byte | Inhalt |
|------|--------|
| 0 | `0xA7` Magic |
| 1 | `0x3C` Magic |
| 2 | Fahrzeug-ID (`0x01``0x0A`) |
| 3 | reserviert (`0x00`) |
Der Sender schickt das Paket alle 2 Sekunden, solange die Zündung an ist.
+162
View File
@@ -0,0 +1,162 @@
<svg width="100%" viewBox="0 0 750 520" xmlns="http://www.w3.org/2000/svg">
<style>
text { font-family: monospace; }
</style>
<!-- Hintergrund -->
<rect width="750" height="520" fill="#1a1a1a"/>
<!-- Titel -->
<rect x="0" y="0" width="750" height="36" fill="#922b21"/>
<text x="375" y="22" text-anchor="middle" style="font-size:13px;font-weight:bold;fill:#fff" dominant-baseline="central">⚠️ Nie 5V! · Pin1=GND · Pin2=VDD(3.3V) · GPIO9↔GND nur beim Flashen!</text>
<!-- ═══ ESP32-C3 Super Mini ═══ -->
<rect x="30" y="55" width="160" height="380" rx="10" fill="#1e3a6e" stroke="#4a7bc8" stroke-width="2"/>
<!-- USB -->
<rect x="85" y="44" width="50" height="14" rx="3" fill="#333" stroke="#666"/>
<text x="110" y="53" text-anchor="middle" dominant-baseline="central" style="font-size:8px;fill:#888">USB-C</text>
<text x="110" y="75" text-anchor="middle" style="font-size:13px;font-weight:bold;fill:#fff">ESP32-C3</text>
<text x="110" y="92" text-anchor="middle" style="font-size:10px;fill:#8ab4f8">Super Mini</text>
<!-- LINKE PINS mit Beschriftung rechts davon -->
<!-- 5V -->
<rect x="14" y="112" width="22" height="22" rx="3" fill="#2a2a2a" stroke="#444"/>
<text x="25" y="123" text-anchor="middle" dominant-baseline="central" style="font-size:9px;fill:#444">5V</text>
<text x="40" y="123" dominant-baseline="central" style="font-size:9px;fill:#c0392b">✗ nicht verbinden</text>
<!-- G -->
<rect x="14" y="144" width="22" height="22" rx="3" fill="#444" stroke="#ccc" stroke-width="1.5"/>
<text x="25" y="155" text-anchor="middle" dominant-baseline="central" style="font-size:9px;fill:#fff;font-weight:bold">G</text>
<text x="40" y="155" dominant-baseline="central" style="font-size:9px;fill:#ccc">→ CC1101 Pin 1</text>
<!-- 3.3 -->
<rect x="14" y="176" width="22" height="22" rx="3" fill="#922b21" stroke="#e74c3c" stroke-width="1.5"/>
<text x="25" y="187" text-anchor="middle" dominant-baseline="central" style="font-size:9px;fill:#fff;font-weight:bold">3.3</text>
<text x="40" y="187" dominant-baseline="central" style="font-size:9px;fill:#e74c3c">→ CC1101 Pin 2</text>
<!-- GPIO4 -->
<rect x="14" y="208" width="22" height="22" rx="3" fill="#0e6655" stroke="#1abc9c" stroke-width="1.5"/>
<text x="25" y="219" text-anchor="middle" dominant-baseline="central" style="font-size:9px;fill:#fff;font-weight:bold">4</text>
<text x="40" y="219" dominant-baseline="central" style="font-size:9px;fill:#1abc9c">→ CC1101 Pin 4</text>
<!-- GPIO3 -->
<rect x="14" y="240" width="22" height="22" rx="3" fill="#784212" stroke="#f39c12" stroke-width="1.5"/>
<text x="25" y="251" text-anchor="middle" dominant-baseline="central" style="font-size:9px;fill:#fff;font-weight:bold">3</text>
<text x="40" y="251" dominant-baseline="central" style="font-size:9px;fill:#f39c12">→ CC1101 Pin 3</text>
<!-- GPIO2 -->
<rect x="14" y="272" width="22" height="22" rx="3" fill="#2a2a2a" stroke="#555"/>
<text x="25" y="283" text-anchor="middle" dominant-baseline="central" style="font-size:9px;fill:#555">2</text>
<text x="40" y="283" dominant-baseline="central" style="font-size:9px;fill:#444">nicht benutzt</text>
<!-- GPIO1 -->
<rect x="14" y="304" width="22" height="22" rx="3" fill="#2a2a2a" stroke="#333"/>
<text x="25" y="315" text-anchor="middle" dominant-baseline="central" style="font-size:9px;fill:#333">1</text>
<!-- GPIO0 -->
<rect x="14" y="336" width="22" height="22" rx="3" fill="#2a2a2a" stroke="#333"/>
<text x="25" y="347" text-anchor="middle" dominant-baseline="central" style="font-size:9px;fill:#333">0</text>
<!-- RECHTE PINS mit Beschriftung links davon -->
<!-- GPIO5 -->
<rect x="184" y="112" width="22" height="22" rx="3" fill="#444" stroke="#ccc" stroke-width="1.5"/>
<text x="195" y="123" text-anchor="middle" dominant-baseline="central" style="font-size:9px;fill:#fff;font-weight:bold">5</text>
<text x="180" y="123" text-anchor="end" dominant-baseline="central" style="font-size:9px;fill:#ccc">Pin 7 ←</text>
<!-- GPIO6 -->
<rect x="184" y="144" width="22" height="22" rx="3" fill="#4a235a" stroke="#9b59b6" stroke-width="1.5"/>
<text x="195" y="155" text-anchor="middle" dominant-baseline="central" style="font-size:9px;fill:#fff;font-weight:bold">6</text>
<text x="180" y="155" text-anchor="end" dominant-baseline="central" style="font-size:9px;fill:#9b59b6">Pin 5 ←</text>
<!-- GPIO7 -->
<rect x="184" y="176" width="22" height="22" rx="3" fill="#4a235a" stroke="#9b59b6" stroke-width="1.5"/>
<text x="195" y="187" text-anchor="middle" dominant-baseline="central" style="font-size:9px;fill:#fff;font-weight:bold">7</text>
<text x="180" y="187" text-anchor="end" dominant-baseline="central" style="font-size:9px;fill:#9b59b6">Pin 6 ←</text>
<!-- GPIO8-21 nicht benutzt -->
<rect x="184" y="208" width="22" height="22" rx="3" fill="#2a2a2a" stroke="#333"/>
<text x="195" y="219" text-anchor="middle" dominant-baseline="central" style="font-size:9px;fill:#333">8</text>
<rect x="184" y="240" width="22" height="22" rx="3" fill="#2a2a2a" stroke="#333"/>
<text x="195" y="251" text-anchor="middle" dominant-baseline="central" style="font-size:9px;fill:#333">9</text>
<rect x="184" y="272" width="22" height="22" rx="3" fill="#2a2a2a" stroke="#333"/>
<text x="195" y="283" text-anchor="middle" dominant-baseline="central" style="font-size:9px;fill:#333">10</text>
<rect x="184" y="304" width="22" height="22" rx="3" fill="#2a2a2a" stroke="#333"/>
<text x="195" y="315" text-anchor="middle" dominant-baseline="central" style="font-size:9px;fill:#333">20</text>
<rect x="184" y="336" width="22" height="22" rx="3" fill="#2a2a2a" stroke="#333"/>
<text x="195" y="347" text-anchor="middle" dominant-baseline="central" style="font-size:9px;fill:#333">21</text>
<!-- ═══ CC1101 V2.0 ═══ -->
<rect x="460" y="100" width="240" height="180" rx="10" fill="#0a3a15" stroke="#27ae60" stroke-width="2"/>
<text x="570" y="126" text-anchor="middle" style="font-size:14px;font-weight:bold;fill:#fff">CC1101 V2.0</text>
<text x="570" y="144" text-anchor="middle" style="font-size:10px;fill:#4eca7f">433MHz</text>
<!-- Chip -->
<rect x="510" y="155" width="50" height="35" rx="4" fill="#0d5c2a" stroke="#1a8a3e"/>
<text x="535" y="173" text-anchor="middle" dominant-baseline="central" style="font-size:8px;fill:#4eca7f">CC1101</text>
<!-- Quarz -->
<rect x="572" y="160" width="28" height="25" rx="3" fill="#1a4a25" stroke="#27ae60"/>
<text x="586" y="173" text-anchor="middle" dominant-baseline="central" style="font-size:7px;fill:#aaa">40MHz</text>
<!-- SMA + Antenne -->
<rect x="692" y="155" width="16" height="30" rx="2" fill="#b8860b" stroke="#daa520"/>
<rect x="706" y="148" width="16" height="44" rx="6" fill="#444" stroke="#666"/>
<text x="696" y="200" text-anchor="middle" style="font-size:7px;fill:#888">SMA</text>
<text x="714" y="200" text-anchor="middle" style="font-size:7px;fill:#aaa">ANT</text>
<!-- CC1101 PINS 4 Zeilen × 2 Spalten, links am Board -->
<!-- Zeile 1: Pin1 GND | Pin2 VDD -->
<rect x="442" y="112" width="22" height="22" rx="3" fill="#444" stroke="#ccc" stroke-width="1.5"/>
<text x="453" y="123" text-anchor="middle" dominant-baseline="central" style="font-size:9px;fill:#fff;font-weight:bold">1</text>
<rect x="468" y="112" width="22" height="22" rx="3" fill="#922b21" stroke="#e74c3c" stroke-width="1.5"/>
<text x="479" y="123" text-anchor="middle" dominant-baseline="central" style="font-size:9px;fill:#fff;font-weight:bold">2</text>
<text x="440" y="112" text-anchor="end" style="font-size:8px;fill:#ccc" dominant-baseline="hanging">GND</text>
<text x="494" y="112" style="font-size:8px;fill:#e74c3c" dominant-baseline="hanging">VDD</text>
<!-- Zeile 2: Pin3 GDO0 | Pin4 CSN -->
<rect x="442" y="145" width="22" height="22" rx="3" fill="#784212" stroke="#f39c12" stroke-width="1.5"/>
<text x="453" y="156" text-anchor="middle" dominant-baseline="central" style="font-size:9px;fill:#fff;font-weight:bold">3</text>
<rect x="468" y="145" width="22" height="22" rx="3" fill="#0e6655" stroke="#1abc9c" stroke-width="1.5"/>
<text x="479" y="156" text-anchor="middle" dominant-baseline="central" style="font-size:9px;fill:#fff;font-weight:bold">4</text>
<text x="440" y="145" text-anchor="end" style="font-size:8px;fill:#f39c12" dominant-baseline="hanging">GDO0</text>
<text x="494" y="145" style="font-size:8px;fill:#1abc9c" dominant-baseline="hanging">CSN</text>
<!-- Zeile 3: Pin5 SCK | Pin6 MOSI -->
<rect x="442" y="178" width="22" height="22" rx="3" fill="#4a235a" stroke="#9b59b6" stroke-width="1.5"/>
<text x="453" y="189" text-anchor="middle" dominant-baseline="central" style="font-size:9px;fill:#fff;font-weight:bold">5</text>
<rect x="468" y="178" width="22" height="22" rx="3" fill="#4a235a" stroke="#9b59b6" stroke-width="1.5"/>
<text x="479" y="189" text-anchor="middle" dominant-baseline="central" style="font-size:9px;fill:#fff;font-weight:bold">6</text>
<text x="440" y="178" text-anchor="end" style="font-size:8px;fill:#9b59b6" dominant-baseline="hanging">SCK</text>
<text x="494" y="178" style="font-size:8px;fill:#9b59b6" dominant-baseline="hanging">MOSI</text>
<!-- Zeile 4: Pin7 MISO | Pin8 GDO2 -->
<rect x="442" y="211" width="22" height="22" rx="3" fill="#444" stroke="#ccc" stroke-width="1.5"/>
<text x="453" y="222" text-anchor="middle" dominant-baseline="central" style="font-size:9px;fill:#fff;font-weight:bold">7</text>
<rect x="468" y="211" width="22" height="22" rx="3" fill="#2a2a2a" stroke="#555" stroke-dasharray="3 2"/>
<text x="479" y="222" text-anchor="middle" dominant-baseline="central" style="font-size:9px;fill:#555">8</text>
<text x="440" y="211" text-anchor="end" style="font-size:8px;fill:#ccc" dominant-baseline="hanging">MISO</text>
<text x="494" y="211" style="font-size:8px;fill:#555" dominant-baseline="hanging">GDO2*</text>
<!-- ═══ VERBINDUNGSTABELLE unten ═══ -->
<rect x="30" y="460" width="690" height="50" rx="8" fill="#111" stroke="#333"/>
<text x="375" y="474" text-anchor="middle" style="font-size:10px;font-weight:bold;fill:#888">7 Verbindungen (Dupont-Kabel):</text>
<!-- Zeile 1 -->
<rect x="44" y="482" width="10" height="10" rx="2" fill="#ccc"/>
<text x="58" y="491" dominant-baseline="central" style="font-size:9px;fill:#ccc">G→1(GND)</text>
<rect x="145" y="482" width="10" height="10" rx="2" fill="#e74c3c"/>
<text x="159" y="491" dominant-baseline="central" style="font-size:9px;fill:#e74c3c">3.3→2(VDD)</text>
<rect x="255" y="482" width="10" height="10" rx="2" fill="#f39c12"/>
<text x="269" y="491" dominant-baseline="central" style="font-size:9px;fill:#f39c12">GPIO3→3(GDO0)</text>
<rect x="385" y="482" width="10" height="10" rx="2" fill="#1abc9c"/>
<text x="399" y="491" dominant-baseline="central" style="font-size:9px;fill:#1abc9c">GPIO4→4(CSN)</text>
<rect x="490" y="482" width="10" height="10" rx="2" fill="#9b59b6"/>
<text x="504" y="491" dominant-baseline="central" style="font-size:9px;fill:#9b59b6">GPIO6→5(SCK)</text>
<rect x="590" y="482" width="10" height="10" rx="2" fill="#9b59b6"/>
<text x="604" y="491" dominant-baseline="central" style="font-size:9px;fill:#9b59b6">GPIO7→6(MOSI)</text>
<text x="680" y="491" text-anchor="end" dominant-baseline="central" style="font-size:9px;fill:#ccc">GPIO5→7(MISO)</text>
</svg>

After

Width:  |  Height:  |  Size: 11 KiB

+65
View File
@@ -0,0 +1,65 @@
substitutions:
geraet: auto-sender-01 # <- pro Fahrzeug ändern: 01, 02, 03 ...
fahrzeug_id: "0x01" # <- pro Fahrzeug ändern: 0x01, 0x02, 0x03 ...
esphome:
name: ${geraet}
friendly_name: Auto Sender 01
esp32:
board: esp32-c3-devkitm-1
framework:
type: esp-idf
logger:
api:
encryption:
key: !secret api_key
ota:
- platform: esphome
password: !secret ota_password
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
# Wichtig: im Auto ist kein WLAN in Reichweite.
# Ohne diese Zeile würde der ESP alle 15 Min neu starten.
reboot_timeout: 0s
# --- SPI zum CC1101 ---
spi:
clk_pin: GPIO6
mosi_pin: GPIO7
miso_pin: GPIO5
# --- CC1101 im Paketmodus ---
cc1101:
cs_pin: GPIO4
gdo0_pin: GPIO3
frequency: 433.92MHz
modulation_type: GFSK
symbol_rate: 4800
output_power: 10 # volle Leistung, Reichweite regelt der Empfänger per RSSI
packet_mode: true
packet_length: 4
crc_enable: true
sync0: 0x91
sync1: 0xD3
# --- alle 2 Sekunden die Fahrzeug-Kennung senden ---
# Paketaufbau: [Magic, Magic, Fahrzeug-ID, Reserve]
interval:
- interval: 2s
then:
- cc1101.send_packet:
data: [0xA7, 0x3C, ${fahrzeug_id}, 0x00]
# Onboard-LED des Super Mini (invertiert)
light:
- platform: status_led
name: Status
pin:
number: GPIO8
inverted: true
+110
View File
@@ -0,0 +1,110 @@
esphome:
name: tor-empfaenger
friendly_name: Tor Empfänger
esp32:
board: esp32-s3-devkitc-1 # <- ggf. an dein Board anpassen
framework:
type: esp-idf
logger:
api:
encryption:
key: !secret api_key
ota:
- platform: esphome
password: !secret ota_password
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
# --- SPI zum CC1101 ---
# Diese Pins am S3 prüfen und ggf. anpassen!
spi:
clk_pin: GPIO12
mosi_pin: GPIO11
miso_pin: GPIO13
cc1101:
cs_pin: GPIO10
gdo0_pin: GPIO9
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: |-
// Magic-Bytes prüfen
if (x.size() < 3 || x[0] != 0xA7 || x[1] != 0x3C) return;
uint8_t fz = x[2];
ESP_LOGI("tor", "Fahrzeug %u, RSSI %.1f dBm, LQI %u", fz, rssi, lqi);
// Reichweite: nur öffnen wenn Signal stark genug (= Auto nah)
if (rssi < id(rssi_schwelle).state) return;
// erlaubte Fahrzeuge
if (fz < 1 || fz > 10) {
ESP_LOGW("tor", "Unbekannte Fahrzeug-ID: %u", fz);
return;
}
// Sperrzeit, damit das Tor nicht dauernd getriggert wird
uint32_t jetzt = millis();
if (id(letzte_oeffnung) != 0 && (jetzt - id(letzte_oeffnung)) < 60000) return;
id(letzte_oeffnung) = jetzt;
ESP_LOGI("tor", "Tor öffnen für Fahrzeug %u (RSSI %.1f)", fz, rssi);
id(letztes_fahrzeug).publish_state(std::to_string(fz));
id(tor_impuls).press();
globals:
- id: letzte_oeffnung
type: uint32_t
restore_value: false
initial_value: '0'
# --- RSSI-Schwelle, in HA per Schieberegler einstellbar ---
# Je näher an 0, desto kürzer die Reichweite.
# Startwert -60 entspricht grob 5 m — beim Einrichten im Log ablesen und anpassen.
number:
- platform: template
name: RSSI Schwelle
id: rssi_schwelle
min_value: -100
max_value: -20
step: 1
initial_value: -60
optimistic: true
restore_value: true
unit_of_measurement: dBm
entity_category: config
text_sensor:
- platform: template
name: Letztes Fahrzeug
id: letztes_fahrzeug
# --- Torimpuls: Relais 500 ms schließen ---
switch:
- platform: gpio
id: tor_relais
pin: GPIO7 # <- an deine Relais-Verdrahtung anpassen
restore_mode: ALWAYS_OFF
button:
- platform: template
name: Tor Impuls
id: tor_impuls
on_press:
- switch.turn_on: tor_relais
- delay: 500ms
- switch.turn_off: tor_relais