summaryrefslogtreecommitdiffstats
path: root/esphome
diff options
context:
space:
mode:
Diffstat (limited to 'esphome')
-rw-r--r--esphome/config/couchlight.yaml234
-rw-r--r--esphome/config/my_components/mycc1101/__init__.py22
-rw-r--r--esphome/config/my_components/mycc1101/mycc1101.h39
3 files changed, 245 insertions, 50 deletions
diff --git a/esphome/config/couchlight.yaml b/esphome/config/couchlight.yaml
index ad6da9d..7244163 100644
--- a/esphome/config/couchlight.yaml
+++ b/esphome/config/couchlight.yaml
@@ -1,10 +1,22 @@
1substitutions: 1substitutions:
2 device_name: couchlight 2 device_name: couchlight
3 friendly_name: "Couch Light" 3 friendly_name: "Couch Light"
4 fan_code: "0000"
5
6external_components:
7 - source: github://pr#6300
8 components: [ cc1101 ]
9 - source: my_components
10 components: [ mycc1101 ]
4 11
5esphome: 12esphome:
6 name: ${device_name} 13 name: ${device_name}
7 friendly_name: ${friendly_name} 14 friendly_name: ${friendly_name}
15 devices:
16 - id: couchlight
17 name: "Couch Light"
18 - id: fancontrol
19 name: "Fan Control"
8 on_boot: 20 on_boot:
9 then: 21 then:
10 - lock.template.publish: 22 - lock.template.publish:
@@ -43,77 +55,46 @@ wifi:
43captive_portal: 55captive_portal:
44 56
45light: 57light:
46 - platform: binary 58 - id: light1
47 id: light1 59 device_id: couchlight
60 platform: binary
48 name: "Spot 1" 61 name: "Spot 1"
49 output: relay_light1 62 output: relay_light1
50 63
51 - platform: binary 64 - id: light2
52 id: light2 65 device_id: couchlight
66 platform: binary
53 name: "Spot 2" 67 name: "Spot 2"
54 output: relay_light2 68 output: relay_light2
55 69
56output: 70output:
57 - platform: gpio 71 - id: relay_light1
58 id: relay_light1 72 platform: gpio
59 pin: GPIO5 # D1 73 pin: GPIO5 # D1
60 74
61 - platform: gpio 75 - id: relay_light2
62 id: relay_light2 76 platform: gpio
63 pin: GPIO4 # D2 77 pin: GPIO4 # D2
64 78
65 # UNUSED GPIO 79 # UNUSED GPIO
66 - platform: gpio 80 - platform: gpio
67 id: unused_gpio0
68 pin:
69 number: GPIO0 # D3
70 mode: INPUT_PULLUP
71 - platform: gpio
72 id: unused_gpio1 81 id: unused_gpio1
73 pin: 82 pin:
74 number: TX # GPIO1 83 number: TX # GPIO1
75 mode: INPUT_PULLUP 84 mode: INPUT_PULLUP
76 - platform: gpio 85 - platform: gpio
77 id: unused_gpio2
78 pin:
79 number: GPIO2 # D4
80 mode: INPUT_PULLUP
81 - platform: gpio
82 id: unused_gpio3 86 id: unused_gpio3
83 pin: 87 pin:
84 number: RX # GPIO3 88 number: RX # GPIO3
85 mode: INPUT_PULLUP 89 mode: INPUT_PULLUP
86 - platform: gpio
87 id: unused_gpio14
88 pin:
89 number: GPIO14 # D5
90 mode: INPUT_PULLUP
91 - platform: gpio
92 id: unused_gpio15
93 pin:
94 number: GPIO15 # D8
95 mode: INPUT_PULLUP
96 - platform: gpio
97 id: unused_gpio16
98 pin:
99 number: GPIO16 # D0
100 mode: INPUT_PULLDOWN
101
102script:
103 - id: reset_child_lock
104 mode: restart
105 then:
106 - delay: 30min
107 - lock.template.publish:
108 id: child_lock
109 state: UNLOCKED
110 90
111binary_sensor: 91binary_sensor:
112 - platform: gpio 92 - id: button_light1
113 id: button_light1 93 device_id: couchlight
94 platform: gpio
114 name: "Spot 1 PushButton" 95 name: "Spot 1 PushButton"
115 pin: 96 pin:
116 number: GPIO13 # D7 97 number: GPIO2 # D4
117 mode: INPUT_PULLUP 98 mode: INPUT_PULLUP
118 filters: 99 filters:
119 - invert 100 - invert
@@ -127,11 +108,12 @@ binary_sensor:
127 - light.toggle: light1 108 - light.toggle: light1
128 internal: true # hide from UI 109 internal: true # hide from UI
129 110
130 - platform: gpio 111 - id: button_light2
131 id: button_light2 112 device_id: couchlight
113 platform: gpio
132 name: "Spot 2 PushButton" 114 name: "Spot 2 PushButton"
133 pin: 115 pin:
134 number: GPIO12 # D6 116 number: GPIO0 # D3
135 mode: INPUT_PULLUP 117 mode: INPUT_PULLUP
136 filters: 118 filters:
137 - invert 119 - invert
@@ -146,8 +128,9 @@ binary_sensor:
146 internal: true # hide from UI 128 internal: true # hide from UI
147 129
148lock: 130lock:
149 - platform: template 131 - id: child_lock
150 id: child_lock 132 device_id: couchlight
133 platform: template
151 name: "Child Lock" 134 name: "Child Lock"
152 optimistic: true 135 optimistic: true
153 on_lock: 136 on_lock:
@@ -155,3 +138,154 @@ lock:
155 on_unlock: 138 on_unlock:
156 - script.stop: reset_child_lock 139 - script.stop: reset_child_lock
157 140
141spi:
142 clk_pin: GPIO14 # D5
143 miso_pin: GPIO12 # D6
144 mosi_pin: GPIO13 # D7
145
146mycc1101:
147 id: transceiver
148 cs_pin: GPIO15 # D8
149 gdo0_pin:
150 number: GPIO16 # D0
151 allow_other_uses: true
152 output_power: 10 # 5
153 tuner:
154 frequency: 433920
155 if_frequency: 153
156 bandwidth: 270
157 symbol_rate: 6000
158 sync_mode: None
159 carrier_sense_above_threshold: false
160 modulation: ASK/OOK
161
162remote_transmitter:
163 pin:
164 number: GPIO16 # same as GDO0
165 allow_other_uses: true
166 carrier_duty_percent: 100%
167
168fan:
169 - id: myfan
170 device_id: fancontrol
171 platform: template
172 name: "Fan"
173 speed_count: 6
174 has_direction: true
175 restore_mode: ALWAYS_OFF
176 on_turn_off:
177 - logger.log: "on_turn_off"
178 - lambda: |-
179 id(transceiver)->wakeup();
180 id(fan_stop_frames).execute();
181 id(transceiver)->power_down();
182 on_turn_on:
183 - logger.log: "on_turn_on"
184 - lambda: |-
185 id(transceiver)->wakeup();
186 auto x = id(myfan).speed;
187 if (x == 1) { id(fan_speed1_frames).execute(); }
188 else if (x == 2) { id(fan_speed2_frames).execute(); }
189 else if (x == 3) { id(fan_speed3_frames).execute(); }
190 else if (x == 4) { id(fan_speed4_frames).execute(); }
191 else if (x == 5) { id(fan_speed5_frames).execute(); }
192 else if (x == 6) { id(fan_speed6_frames).execute(); }
193 id(transceiver)->power_down();
194 on_speed_set:
195 - logger.log: "on_speed_set"
196 - lambda: |-
197 if (!id(myfan).state)
198 return;
199 id(transceiver)->wakeup();
200 if (x == 1) { id(fan_speed1_frames).execute(); }
201 else if (x == 2) { id(fan_speed2_frames).execute(); }
202 else if (x == 3) { id(fan_speed3_frames).execute(); }
203 else if (x == 4) { id(fan_speed4_frames).execute(); }
204 else if (x == 5) { id(fan_speed5_frames).execute(); }
205 else if (x == 6) { id(fan_speed6_frames).execute(); }
206 id(transceiver)->power_down();
207 on_direction_set:
208 - logger.log: "on_direction_set"
209 - lambda: |-
210 if (!id(myfan).state)
211 return;
212 id(transceiver)->wakeup();
213 id(fan_reverse_frames).execute();
214 id(transceiver)->power_down();
215
216script:
217 - id: reset_child_lock
218 mode: restart
219 then:
220 - delay: 30min
221 - lock.template.publish:
222 id: child_lock
223 state: UNLOCKED
224
225 # see https://www.alldatasheet.com/datasheet-pdf/pdf/114193/ETC1/M1EN.html
226 # code format is 0 <code> 0 <command>
227 # commands:
228 # - stop: 111101
229 # - lvl1: 110111
230 # - lvl2: 110101
231 # - lvl3: 101111
232 # - lvl4: 100111
233 # - lvl5: 011101
234 # - lvl6: 011111
235 # - light: 111110
236 # - reverse: 111011
237 - id: fan_stop_frames
238 then:
239 - remote_transmitter.transmit_rc_switch_raw_cc1101:
240 code: "0${fan_code}0111101"
241 protocol: { pulse_length: 250, sync: [35,1], zero: [1,2], one: [2,1], inverted: true }
242 repeat: { times: 10, wait_time: 0s }
243 - id: fan_speed1_frames
244 then:
245 - remote_transmitter.transmit_rc_switch_raw_cc1101:
246 code: "0${fan_code}0110111"
247 protocol: { pulse_length: 250, sync: [35,1], zero: [1,2], one: [2,1], inverted: true }
248 repeat: { times: 10, wait_time: 0s }
249 - id: fan_speed2_frames
250 then:
251 - remote_transmitter.transmit_rc_switch_raw_cc1101:
252 code: "0${fan_code}0110101"
253 protocol: { pulse_length: 250, sync: [35,1], zero: [1,2], one: [2,1], inverted: true }
254 repeat: { times: 10, wait_time: 0s }
255 - id: fan_speed3_frames
256 then:
257 - remote_transmitter.transmit_rc_switch_raw_cc1101:
258 code: "0${fan_code}0101111"
259 protocol: { pulse_length: 250, sync: [35,1], zero: [1,2], one: [2,1], inverted: true }
260 repeat: { times: 10, wait_time: 0s }
261 - id: fan_speed4_frames
262 then:
263 - remote_transmitter.transmit_rc_switch_raw_cc1101:
264 code: "0${fan_code}0100111"
265 protocol: { pulse_length: 250, sync: [35,1], zero: [1,2], one: [2,1], inverted: true }
266 repeat: { times: 10, wait_time: 0s }
267 - id: fan_speed5_frames
268 then:
269 - remote_transmitter.transmit_rc_switch_raw_cc1101:
270 code: "0${fan_code}0011101"
271 protocol: { pulse_length: 250, sync: [35,1], zero: [1,2], one: [2,1], inverted: true }
272 repeat: { times: 10, wait_time: 0s }
273 - id: fan_speed6_frames
274 then:
275 - remote_transmitter.transmit_rc_switch_raw_cc1101:
276 code: "0${fan_code}0011111"
277 protocol: { pulse_length: 250, sync: [35,1], zero: [1,2], one: [2,1], inverted: true }
278 repeat: { times: 10, wait_time: 0s }
279 - id: fan_toggle_light_frames
280 then:
281 - remote_transmitter.transmit_rc_switch_raw_cc1101:
282 code: "0${fan_code}0111110"
283 protocol: { pulse_length: 250, sync: [35,1], zero: [1,2], one: [2,1], inverted: true }
284 repeat: { times: 10, wait_time: 0s }
285 - id: fan_reverse_frames
286 then:
287 - remote_transmitter.transmit_rc_switch_raw_cc1101:
288 code: "0${fan_code}0111011"
289 protocol: { pulse_length: 250, sync: [35,1], zero: [1,2], one: [2,1], inverted: true }
290 repeat: { times: 10, wait_time: 0s }
291
diff --git a/esphome/config/my_components/mycc1101/__init__.py b/esphome/config/my_components/mycc1101/__init__.py
new file mode 100644
index 0000000..14261fb
--- /dev/null
+++ b/esphome/config/my_components/mycc1101/__init__.py
@@ -0,0 +1,22 @@
1import esphome.codegen as cg
2from esphome.components import spi, remote_base
3import esphome.config_validation as cv
4from esphome.const import CONF_ID, CONF_PROTOCOL, CONF_CODE
5from esphome.components import cc1101
6from types import FunctionType
7
8cc1101.MULTI_CONF_NO_DEFAULT = True
9AUTO_LOAD = ["cc1101"]
10DEPENDENCIES = cc1101.DEPENDENCIES
11
12ns = cg.esphome_ns.namespace("cc1101")
13MyCC1101Component = ns.class_("MyCC1101Component", cc1101.CC1101Component)#, cg.Component, spi.SPIDevice)
14
15CONFIG_SCHEMA = cc1101.CONFIG_SCHEMA.extend(
16 {
17 cv.GenerateID(): cv.declare_id(MyCC1101Component),
18 }
19)
20
21to_code = cc1101.to_code
22
diff --git a/esphome/config/my_components/mycc1101/mycc1101.h b/esphome/config/my_components/mycc1101/mycc1101.h
new file mode 100644
index 0000000..95f714d
--- /dev/null
+++ b/esphome/config/my_components/mycc1101/mycc1101.h
@@ -0,0 +1,39 @@
1#pragma once
2
3#include "esphome/components/cc1101/cc1101.h"
4#include "esphome/components/cc1101/cc1101defs.h"
5
6namespace esphome {
7namespace cc1101 {
8
9static const char *const TAG = "mycc1101";
10
11class MyCC1101Component : public CC1101Component {
12 public:
13 void idle() {
14 ESP_LOGD(TAG, "idle");
15 this->send_(Command::IDLE);
16 }
17
18 void power_down() {
19 ESP_LOGD(TAG, "power_down");
20 this->send_(Command::IDLE);
21 this->send_(Command::PWD);
22 }
23
24 void wakeup() {
25 ESP_LOGD(TAG, "wakeup");
26 this->cs_->digital_write(false);
27 delayMicroseconds(10);
28 this->cs_->digital_write(true);
29 delayMicroseconds(200);
30
31 this->send_(Command::IDLE);
32
33 // set patable after after wakeup
34 this->set_output_power(this->output_power_requested_);
35 }
36};
37
38} // namespace cc1101
39} // namespace esphome