-
Notifications
You must be signed in to change notification settings - Fork 0
/
mccgq02hl.yaml
141 lines (125 loc) · 3.58 KB
/
mccgq02hl.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
esphome:
name: "esp32"
friendly_name: esp32
ota:
platform: esphome
# Enable Home Assistant API
api:
encryption:
key: "key"
esp32:
board: esp32dev
framework:
type: esp-idf
esp32_ble_tracker:
logger:
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
external_components:
- source: github://dentra/esphome-components
web_server:
port: 80
# Define a function to send a message to Telegram
globals:
- id: message_text
type: std::string
initial_value: ""
substitutions:
telegram_bot_token: !secret telegram_bot_token
telegram_recipient1: !secret telegram_recipient1
telegram_recipient2: !secret telegram_recipient2
telegram_recipientX: !secret telegram_recipientX
http_request:
verify_ssl: false
useragent: esphome/device
timeout: 20s
id: telegram_request
script:
- id: send_telegram_message
then:
- http_request.post:
url: "https://api.telegram.org/bot${telegram_bot_token}/sendMessage"
headers:
Content-Type: application/json
json:
chat_id: ${telegram_recipient1}
text: !lambda 'return id(message_text);'
- delay: 1s
- http_request.post:
url: "https://api.telegram.org/bot${telegram_bot_token}/sendMessage"
headers:
Content-Type: application/json
json:
chat_id: ${telegram_recipient2}
text: !lambda 'return id(message_text);'
- delay: 1s
- http_request.post:
url: "https://api.telegram.org/bot${telegram_bot_token}/sendMessage"
headers:
Content-Type: application/json
json:
chat_id: ${telegram_recipientX}
text: !lambda 'return id(message_text);'
- delay: 1s
sensor:
- platform: ble_rssi
mac_address: "AA:AA:BB:BB:CC:CC"
name: "sensor1 RSSI"
- platform: ble_rssi
mac_address: "CC:CC:BB:BB:AA:AA"
name: "sensor2 RSSI"
binary_sensor:
- platform: miot_mccgq02hl
mac_address: "AA:AA:BB:BB:CC:CC"
bindkey: "bindkey_for_sensor1"
name: "First Door/Window Sensor"
id: first_sensor
light:
name: "first_sensor Light"
alert:
name: "first_sensor Alert"
on_state:
then:
- lambda: |-
if (id(first_sensor).state) {
id(message_text) = "First Door/Window Sensor is opened.";
} else {
id(message_text) = "First Door/Window Sensor is closed.";
}
- script.execute: send_telegram_message
- platform: miot_mccgq02hl
mac_address: "CC:CC:BB:BB:AA:AA"
bindkey: "bindkey_for_sensor2"
name: "Second Door/Window Sensor"
id: second_sensor
light:
name: "second_sensor Light"
alert:
name: "second_sensor Alert"
on_state:
then:
- lambda: |-
if (id(second_sensor).state) {
id(message_text) = "Second Door/Window Sensor is opened.";
} else {
id(message_text) = "Second Door/Window Sensor is closed.";
}
- script.execute: send_telegram_message
text_sensor:
- platform: miot_explorer
mac_address: "AA:AA:BB:BB:CC:CC"
bindkey: "bindkey_for_sensor1"
name: "First Door/Window Sensor"
battery_level:
name: "First Door/Window Battery Level"
battery_voltage:
name: "First Door/Window Battery Voltage"
- platform: miot_explorer
mac_address: "CC:CC:BB:BB:AA:AA"
bindkey: "bindkey_for_sensor2"
name: "Second Door/Window Sensor"
battery_level:
name: "Second Door/Window Battery Level"
battery_voltage:
name: "Second Door/Window Battery Voltage"