-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrenogy_batteries.yaml
239 lines (197 loc) · 7.31 KB
/
renogy_batteries.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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
esphome:
name: renogy-batteries
includes:
- renogy_battery_utilities.h
esp32:
board: nodemcu-32s
framework:
type: arduino
substitutions:
# todo: update this with the MAC address for your bluetooth device
ble_mac_address: FF:FF:FF:FF:FF:FF
#todo: add or remove other battery Ids, based on your usage. Also, see where these are used and add or remove nodes accordingly
battery_id_1: "48"
battery_id_2: "49"
battery_id_3: "50"
# Enable logging
logger:
# Enable Home Assistant API
api:
password: "super_secret" # it is recommended that you put this in a secrets.yaml file and reference it here
# Enable OTA updates so you don't have to plug in your ESP32 to your dev box after the first upload
ota:
- platform: esphome
password: "super_duper_secret" # it is recommended that you put this in a secrets.yaml file and reference it here
# Configure the ESP32 to connect to your wifi network
wifi:
ssid: "my_ssid"
password: "some_other_secret" # it is recommended that you put this in a secrets.yaml file and reference it here
esp32_ble_tracker:
scan_parameters:
# We currently use the defaults to ensure Bluetooth
# can co-exist with WiFi. In the future we may be able to
# enable the built-in coexistence logic in ESP-IDF
active: true
sensor:
# Renogy battery 1
- platform: template
# NOTE: The _name_ (not id) is what is turned into an Id in HomeAssistant. The Id field is only used within the scope of ESPHome (per HA devs)
name: "Renogy Battery ${battery_id_1} Current"
id: renogy_battery_${battery_id_1}_current
device_class: current
unit_of_measurement: A
accuracy_decimals: 1
- platform: template
name: "Renogy Battery ${battery_id_1} Voltage"
id: renogy_battery_${battery_id_1}_voltage
device_class: voltage
unit_of_measurement: V
accuracy_decimals: 1
- platform: template
name: "Renogy Battery ${battery_id_1} Present Capacity"
id: renogy_battery_${battery_id_1}_present_capacity
unit_of_measurement: Ah
accuracy_decimals: 1
- platform: template
name: "Renogy Battery ${battery_id_1} Total Capacity"
id: renogy_battery_${battery_id_1}_total_capacity
unit_of_measurement: Ah
accuracy_decimals: 1
- platform: template
name: "Renogy Battery ${battery_id_1} Charge Level"
id: renogy_battery_${battery_id_1}_charge_level
icon: mdi:percent
unit_of_measurement: "%"
accuracy_decimals: 1
# Renogy battery 2
- platform: template
name: "Renogy Battery ${battery_id_2} Current"
id: renogy_battery_${battery_id_2}_current
device_class: current
unit_of_measurement: A
accuracy_decimals: 1
- platform: template
name: "Renogy Battery ${battery_id_2} Voltage"
id: renogy_battery_${battery_id_2}_voltage
device_class: voltage
unit_of_measurement: V
accuracy_decimals: 1
- platform: template
name: "Renogy Battery ${battery_id_2} Present Capacity"
id: renogy_battery_${battery_id_2}_present_capacity
unit_of_measurement: Ah
accuracy_decimals: 1
- platform: template
name: "Renogy Battery ${battery_id_2} Total Capacity"
id: renogy_battery_${battery_id_2}_total_capacity
unit_of_measurement: Ah
accuracy_decimals: 1
- platform: template
name: "Renogy Battery ${battery_id_2} Charge Level"
id: renogy_battery_${battery_id_2}_charge_level
icon: mdi:percent
unit_of_measurement: "%"
accuracy_decimals: 1
# Renogy battery 3
- platform: template
name: "Renogy Battery ${battery_id_3} Current"
id: renogy_battery_${battery_id_3}_current
device_class: current
unit_of_measurement: A
accuracy_decimals: 1
- platform: template
name: "Renogy Battery ${battery_id_3} Voltage"
id: renogy_battery_${battery_id_3}_voltage
device_class: voltage
unit_of_measurement: V
accuracy_decimals: 1
- platform: template
name: "Renogy Battery ${battery_id_3} Present Capacity"
id: renogy_battery_${battery_id_3}_present_capacity
unit_of_measurement: Ah
accuracy_decimals: 1
- platform: template
name: "Renogy Battery ${battery_id_3} Total Capacity"
id: renogy_battery_${battery_id_3}_total_capacity
unit_of_measurement: Ah
accuracy_decimals: 1
- platform: template
name: "Renogy Battery ${battery_id_3} Charge Level"
id: renogy_battery_${battery_id_3}_charge_level
icon: mdi:percent
unit_of_measurement: "%"
accuracy_decimals: 1
- platform: ble_client
ble_client_id: renogy_battery_esp32_bc
id: renogy_battery_esp32_sensor
internal: true
type: characteristic
service_uuid: FFF0
characteristic_uuid: FFF1
notify: true
update_interval: never
# on_notify:
# then:
# - lambda: |-
# ESP_LOGD("ble_client.notify", "x: %.2f", x);
lambda: |-
// A variable x of type esp32_ble_tracker::ESPBTDevice is passed to the automation for use in lambdas. (from docs)
// it actually behaves like a byte array though, so I'm not sure about those docs...
int receivedSize = x.size();
ESP_LOGD("ble_client_lambda", "Received bytes size: %d", receivedSize);
// Log each byte in the array
for (size_t i = 0; i < receivedSize; ++i) {
ESP_LOGD("main", "Response Byte %d: 0x%02X", i, x[i]);
}
// if something went wrong, we didn't get the data we expected, so bail out here
if (receivedSize < 17) return NAN;
// parse the data using this method from renogy_utilities.h
HandleBatteryData(x);
return 0.0; // this sensor isn't actually used other than to hook into raw value and publish to template sensors
ble_client:
- mac_address: ${ble_mac_address} # this pulls the value from the substitution entry above
name: Renogy Battery
id: renogy_battery_esp32_bc
auto_connect: true
on_connect:
then:
- logger.log:
format: "BLE client connected to battery"
level: DEBUG
on_disconnect:
then:
- logger.log:
format: "BLE client disconnected from battery"
level: DEBUG
# every 30 seconds, pull each battery with a 5s delay between each one. todo: update these timings as needed
interval:
- interval: 30s
then:
- ble_client.ble_write:
characteristic_uuid: "FFD1"
service_uuid: "FFD0"
id: renogy_battery_esp32_bc
value: !lambda |-
vector<uint8_t> request = GetBatteryRequest(${battery_id_1});
return request;
- delay: 5s
- ble_client.ble_write:
characteristic_uuid: "FFD1"
service_uuid: "FFD0"
id: renogy_battery_esp32_bc
value: !lambda |-
vector<uint8_t> request = GetBatteryRequest(${battery_id_2});
return request;
- delay: 5s
- ble_client.ble_write:
characteristic_uuid: "FFD1"
service_uuid: "FFD0"
id: renogy_battery_esp32_bc
value: !lambda |-
vector<uint8_t> request = GetBatteryRequest(${battery_id_3});
return request;
binary_sensor:
- platform: ble_presence
mac_address: ${ble_mac_address} # this pulls the value from the substitution entry above
name: "Renogy BLE Presence"
entity_category: "DIAGNOSTIC"