-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathESPHome config.yaml
More file actions
220 lines (195 loc) · 5.58 KB
/
Copy pathESPHome config.yaml
File metadata and controls
220 lines (195 loc) · 5.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
esphome:
name: cc1101-transceiver
friendly_name: CC1101 RF Transceiver
esp32:
board: esp32dev
framework:
type: arduino
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
logger:
api:
encryption:
key: ""
ota:
- platform: esphome
password: ""
web_server:
port: 80
# Globals to store learned signals
globals:
- id: learned_code
type: std::vector<int32_t>
restore_value: no
- id: learning_mode
type: bool
initial_value: 'false'
- id: signal_learned
type: bool
initial_value: 'false'
# SPI Bus
spi:
clk_pin: GPIO18
mosi_pin: GPIO23
miso_pin: GPIO19
# CC1101 - Dual Pin Mode
cc1101:
id: cc1101_module
cs_pin: GPIO5
frequency: 433.92MHz
output_power: 10
modulation_type: ASK/OOK
symbol_rate: 5000
filter_bandwidth: 200kHz
# Remote Receiver - connected to GDO2
remote_receiver:
id: rf_receiver
pin: GPIO2
tolerance: 50%
filter: 200us
dump:
- raw
idle: 10ms
on_raw:
then:
- lambda: |-
// Log as single copyable line for YAML
std::string code_str = "";
for (int i = 0; i < x.size(); i++) {
if (i > 0) code_str += ", ";
code_str += std::to_string(x[i]);
}
ESP_LOGI("raw_code", "Pulses: %d", x.size());
ESP_LOGI("raw_code", "Copy this line:");
ESP_LOGI("raw_code", "[%s]", code_str.c_str());
// Learning mode logic
if (id(learning_mode)) {
id(learned_code).clear();
for (int32_t val : x) {
id(learned_code).push_back(val);
}
id(signal_learned) = true;
id(learning_mode) = false;
std::string preview = "";
int count = 0;
for (int32_t val : id(learned_code)) {
if (count > 0) preview += ", ";
preview += std::to_string(val);
count++;
if (count >= 20) {
preview += "... (" + std::to_string(id(learned_code).size()) + " total)";
break;
}
}
id(last_signal).publish_state(preview.c_str());
id(learn_status).publish_state("Signal learned! " + std::to_string(id(learned_code).size()) + " pulses. Select slot to save.");
}
# Remote Transmitter - connected to GDO0
remote_transmitter:
id: rf_transmitter
pin: GPIO4
carrier_duty_percent: 100%
on_transmit:
then:
- cc1101.begin_tx: cc1101_module
on_complete:
then:
- cc1101.begin_rx: cc1101_module
switch:
- platform: template
name: "Learning Mode"
id: learning_mode_switch
icon: "mdi:school"
lambda: 'return id(learning_mode);'
turn_on_action:
- lambda: |-
id(learning_mode) = true;
id(learn_status).publish_state("Waiting for signal... Press remote now!");
- logger.log: "Learning mode ON - press your remote"
turn_off_action:
- lambda: |-
id(learning_mode) = false;
id(learn_status).publish_state("Learning cancelled");
- logger.log: "Learning mode OFF"
button:
- platform: restart
name: "Restart"
- platform: template
name: "Learn Signal"
icon: "mdi:record-rec"
on_press:
- switch.turn_on: learning_mode_switch
- platform: template
name: "Replay Learned Signal"
icon: "mdi:replay"
on_press:
- lambda: |-
if (!id(signal_learned) || id(learned_code).empty()) {
ESP_LOGW("replay", "No signal learned yet!");
id(learn_status).publish_state("No signal to replay - learn one first!");
return;
}
ESP_LOGI("replay", "Replaying %d pulses...", id(learned_code).size());
id(learn_status).publish_state("Transmitting...");
- remote_transmitter.transmit_raw:
carrier_frequency: 0Hz
code: !lambda 'return id(learned_code);'
- lambda: |-
id(learn_status).publish_state("Signal transmitted!");
ESP_LOGI("replay", "Replay complete");
- platform: template
name: "Replay x3"
icon: "mdi:replay"
on_press:
- lambda: |-
if (!id(signal_learned) || id(learned_code).empty()) {
ESP_LOGW("replay", "No signal learned yet!");
return;
}
- repeat:
count: 3
then:
- remote_transmitter.transmit_raw:
carrier_frequency: 0Hz
code: !lambda 'return id(learned_code);'
- delay: 50ms
- platform: template
name: "Clear Learned Signal"
icon: "mdi:delete"
on_press:
- lambda: |-
id(learned_code).clear();
id(signal_learned) = false;
id(last_signal).publish_state("(empty)");
id(learn_status).publish_state("Signal cleared");
ESP_LOGI("learn", "Learned signal cleared");
- platform: template
name: "TX Test"
icon: "mdi:access-point"
on_press:
- remote_transmitter.transmit_raw:
carrier_frequency: 0Hz
code: [500, -500, 500, -500, 500, -500, 500, -500, 500, -500]
text_sensor:
- platform: template
name: "Last Received Signal"
id: last_signal
icon: "mdi:signal"
- platform: template
name: "Learn Status"
id: learn_status
icon: "mdi:information"
sensor:
- platform: template
name: "Learned Signal Length"
id: signal_length
icon: "mdi:counter"
unit_of_measurement: "pulses"
lambda: 'return id(learned_code).size();'
update_interval: 5s
binary_sensor:
- platform: template
name: "Signal Learned"
icon: "mdi:check-circle"
lambda: 'return id(signal_learned);'