-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathesphome_tethercell_generic.yaml
More file actions
110 lines (105 loc) · 4.55 KB
/
esphome_tethercell_generic.yaml
File metadata and controls
110 lines (105 loc) · 4.55 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
substitutions:
uuid: # based on uuid source forked at https://github.com/w00dst0ck/node-tethercell/blob/master/tethercell.txt
service: 5EC0FFF0-3CF2-A682-E211-2AF96EFDF667
family: 5EC0FFF1-3CF2-A682-E211-2AF96EFDF667
fet_state: 5EC0FFF2-3CF2-A682-E211-2AF96EFDF667
battery_voltage: 5EC0FFF3-3CF2-A682-E211-2AF96EFDF667
timers: 5EC0FFF4-3CF2-A682-E211-2AF96EFDF667
timer_access_index: 5EC0FFF5-3CF2-A682-E211-2AF96EFDF667
battery_voltage_most_recent_index: 5EC0FFF6-3CF2-A682-E211-2AF96EFDF667
battery_voltage_history: 5EC0FFF7-3CF2-A682-E211-2AF96EFDF667
password: 5EC0FFF8-3CF2-A682-E211-2AF96EFDF667
device_name: 5EC0FFF9-3CF2-A682-E211-2AF96EFDF667
utc_time: 5EC0FFFA-3CF2-A682-E211-2AF96EFDF667
advertising_period: 5EC0FFFB-3CF2-A682-E211-2AF96EFDF667
authorization: 5EC0FFFC-3CF2-A682-E211-2AF96EFDF667
ble_client:
- mac_address: ${tethercell_mac}
id: tethercell_device_${tethercell_number}
auto_connect: true
on_connect:
then:
- lambda: |-
ESP_LOGI("ble_client_lambda", "Client connected to Tethercell ${tethercell_number}");
- lambda: |-
ESP_LOGI("ble_client_lambda", "Sending auth to Tethercell ${tethercell_number}");
- ble_client.ble_write: # send the authentication PIN to activate the service announcement
id: tethercell_device_${tethercell_number}
service_uuid: ${uuid.service}
characteristic_uuid: ${uuid.authorization}
value: !lambda |-
uint32_t val = strtoul("${tethercell_pin}", nullptr, 10);
return std::vector<uint8_t>{
(uint8_t)((val >> 24) & 0xFF),
(uint8_t)((val >> 16) & 0xFF),
(uint8_t)((val >> 8) & 0xFF),
(uint8_t)(val & 0xFF)
};
on_disconnect:
then:
- lambda: |-
ESP_LOGI("ble_client_lambda", "Client disconnected from Tethercell ${tethercell_number}");
sensor:
- platform: ble_client
type: characteristic
ble_client_id: tethercell_device_${tethercell_number}
name: "Tethercell ${tethercell_number} Battery voltage"
id: sensor_tethercell_${tethercell_number}_battery_voltage
service_uuid: ${uuid.service}
characteristic_uuid: ${uuid.battery_voltage}
update_interval: 300s
icon: mdi:battery-medium
unit_of_measurement: "V"
accuracy_decimals: 2
lambda: |-
if (x.size() < 2) {
return NAN;
}
uint16_t value = (uint16_t(x[1]) << 8) | uint16_t(x[0]);
return 1.36f * (float(value) / 1662.0f);
switch:
- platform: template
name: "Tethercell ${tethercell_number} FET"
id: switch_tethercell_${tethercell_number}_fet
optimistic: true
icon: mdi:battery-bluetooth
turn_on_action:
- ble_client.ble_write: # send authentication pin
id: tethercell_device_${tethercell_number}
service_uuid: ${uuid.service}
characteristic_uuid: ${uuid.authorization}
value: !lambda |-
uint32_t val = strtoul("${tethercell_pin}", nullptr, 10);
return std::vector<uint8_t>{
(uint8_t)((val >> 24) & 0xFF),
(uint8_t)((val >> 16) & 0xFF),
(uint8_t)((val >> 8) & 0xFF),
(uint8_t)(val & 0xFF)
};
- ble_client.ble_write: # send fet state on
id: tethercell_device_${tethercell_number}
service_uuid: ${uuid.service}
characteristic_uuid: ${uuid.fet_state}
value: [0x01]
- lambda: |-
ESP_LOGI("ble_client_lambda", "Send FET ON to Tethercell ${tethercell_number}");
turn_off_action:
- ble_client.ble_write: # send authentication pin
id: tethercell_device_${tethercell_number}
service_uuid: ${uuid.service}
characteristic_uuid: ${uuid.authorization}
value: !lambda |-
uint32_t val = strtoul("${tethercell_pin}", nullptr, 10);
return std::vector<uint8_t>{
(uint8_t)((val >> 24) & 0xFF),
(uint8_t)((val >> 16) & 0xFF),
(uint8_t)((val >> 8) & 0xFF),
(uint8_t)(val & 0xFF)
};
- ble_client.ble_write: # send fet state off
id: tethercell_device_${tethercell_number}
service_uuid: ${uuid.service}
characteristic_uuid: ${uuid.fet_state}
value: [0x00]
- lambda: |-
ESP_LOGI("ble_client_lambda", "Send FET OFF to Tethercell ${tethercell_number}");