generated from esphome/esphome-project-template
-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
switchman-m5-2c.yaml
213 lines (191 loc) · 5.67 KB
/
switchman-m5-2c.yaml
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
# https://templates.blakadder.com/sonoff_SwitchMan_M5-2C.html
# These substitutions allow the end user to override certain values
substitutions:
friendly_name: 'M5-2C'
device_name: 'm5_2c'
node_name: 'm5-2c'
device_description: '2 Gang Switch (ESP32D0-MSW-T5)'
project_base: 'SONOFF'
project_name: 'Switchman M5'
project_version: '2C-80/86'
##########################################################
# Your home specific:
##########################################################
hass_device_1: light.left
hass_device_2: light.right
esphome:
name: $node_name
comment: $device_description
friendly_name: $friendly_name
# Automatically add the mac address to the name
# so you can use a single firmware for all devices
name_add_mac_suffix: true
# This will allow for (future) project identification,
# configuration and updates.
project:
name: ${project_base}.${project_name}
version: ${project_version}
esp32:
board: esp32dev
# To be able to get logs from the device via serial and api.
logger:
# API is a requirement of the dashboard import.
api:
##########################################################
# for managing bluetooth_proxy & esp32_ble_tracker
##########################################################
services:
- service: bluetooth_proxy_set_param
variables:
active: bool
then:
- lambda: |-
id(${device_name}_bluetooth_proxy).set_active(bool(active));
- service: stop_scan
then:
- esp32_ble_tracker.stop_scan
- service: start_scan
then:
- esp32_ble_tracker.start_scan
# OTA is required for Over-the-Air updating
ota:
# This should point to the public location of this yaml file.
dashboard_import:
package_import_url: github://velijv/esphome-configs/switchman-m5-2c.yaml@main
wifi:
# Set up a wifi access point using the device name above
ap:
password: "12345678"
# In combination with the `ap` this allows the user
# to provision wifi credentials to the device.
captive_portal:
##########################################################
# Most projects should not remove anything from above here
# and should just modify the name, project name/version
# and git url for the dashboard_import
##########################################################
# Sets up Bluetooth LE (Only on ESP32) to allow the user
# to provision wifi credentials to the device.
esp32_improv:
authorizer: none
# Sets up the improv via serial client for Wi-Fi provisioning.
# Handy if your device has a usb port for the user to add credentials when they first get it.
improv_serial:
next_url: https://veli.ee/esphome?device_name={{device_name}}&ip_address={{ip_address}}&esphome_version={{esphome_version}}
##########################################################
# SONOFF SWITCHMAN M5 starts here
# Enough room to fit ble_tracker and bluetooth_proxy
##########################################################
esp32_ble_tracker:
id: ${device_name}_esp32_ble_tracker
scan_parameters:
active: true
continuous: true
bluetooth_proxy:
id: ${device_name}_bluetooth_proxy
active: true
##########################################################
# Hardware config starts here
##########################################################
binary_sensor:
- platform: gpio
pin:
number: 4
inverted: true
id: ${device_name}_button_left
icon: mdi:format-horizontal-align-left
name: Left
on_click:
then:
if:
condition:
api.connected:
then:
- homeassistant.service:
service: homeassistant.toggle
data:
entity_id: $hass_device_1
- light.toggle: ${device_name}_led_left
else:
- switch.toggle: ${device_name}_switch_left
- platform: gpio
pin:
number: 15
inverted: true
id: ${device_name}_button_right
icon: mdi:format-horizontal-align-right
name: Right
on_click:
then:
if:
condition:
api.connected:
then:
- homeassistant.service:
service: homeassistant.toggle
data:
entity_id: $hass_device_2
- light.toggle: ${device_name}_led_right
else:
- switch.toggle: ${device_name}_switch_right
switch:
- platform: gpio
name: Left
icon: mdi:toggle-switch-off
id: ${device_name}_switch_left
restore_mode: RESTORE_DEFAULT_ON
pin:
number: 23
- platform: gpio
name: Right
icon: mdi:toggle-switch
id: ${device_name}_switch_right
restore_mode: RESTORE_DEFAULT_ON
pin:
number: 19
on_turn_on:
light.turn_on: ${device_name}_led_right
on_turn_off:
light.turn_off: ${device_name}_led_right
output:
- platform: ledc
pin: 18
frequency: 1000 Hz
id: red_output
- platform: ledc
pin: 5
frequency: 1000 Hz
id: blue_output
- platform: gpio
pin: 22
id: ${device_name}_output_led_right
light:
# Red LED (for both relays, can't be split...)
- platform: monochromatic
output: red_output
name: LED (both)
id: ${device_name}_led_left
default_transition_length: 500ms
restore_mode: RESTORE_DEFAULT_OFF
icon: mdi:led-on
entity_category: config
effects:
- pulse:
- strobe:
# Blue led for status
- platform: status_led
name: LED (blue)
id: ${device_name}_led_status
icon: mdi:led-outline
entity_category: config
pin:
number: 5
inverted: true
# right led
- platform: binary
id: ${device_name}_led_right
name: LED (right)
output: ${device_name}_output_led_right
restore_mode: ALWAYS_OFF
icon: mdi:led-outline
entity_category: config