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
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
| #
# SlimmeLezer+ configuration with SmartEVSE REST support.
# Extended from github://zuidwijk/slimmelezer-wt32-eth01/wt32.yaml@main
#
# Added:
# - SmartEVSE Integration switch (available in HA)
# - SmartEVSE API connectivity status sensor (available in HA)
# - Electricity tariff sensor (available in HA, useful for automations)
# - Send data to SmartEVSE using http post REST interface
# - HomeWizard HWE-P1 API emulation (for Indevolt and other batteries)
# - mDNS announcement as HomeWizard P1 meter
#
# Please update 'smartevse_host' below to match your SmartEVSE
#
substitutions:
device_name: slimmelezer
smartevse_host: 192.168.*.* # <== YOUR SMARTEVSE IP ADDRESS HERE
esphome:
name: ${device_name}
name_add_mac_suffix: false
comment: SlimmeLezer+ / SmartEVSE / HomeWizard API
project:
name: zuidwijk.slimmelezer
version: "1.2"
on_boot:
# ── Bestaande boot logica (decryptie sleutel) ────────────────────────────
- priority: 600.0
then:
- if:
condition:
lambda: return id(has_key);
then:
- lambda: |-
std::string key(id(stored_decryption_key), 32);
id(dsmr_instance).set_decryption_key(key.c_str());
else:
- logger.log:
level: info
format: "Not using decryption key. If you need to set a key use Home Assistant service 'ESPHome: ${device_name}_set_dsmr_key'"
# ── HomeWizard API registreren (na webserver start) ──────────────────────
- priority: -100.0
then:
- lambda: |-
auto *server = esphome::web_server_base::global_web_server_base->get_server();
// GET /api/v1/telegram → ruwe DSMR telegram tekst
server->on("/api/v1/telegram", HTTP_GET, [](AsyncWebServerRequest *req) {
req->send(200, "text/plain", id(last_telegram).c_str());
});
// GET /api/v1/data eerst registreren (meest specifieke route)
server->on("/api/v1/data", HTTP_GET, [](AsyncWebServerRequest *req) {
// wifi dBm (-100..0) → percentage (0..100)
int wifi_pct = (int)clamp((id(hw_wifi_signal).state + 100.0f) * 2.0f, 0.0f, 100.0f);
int smr_ver = atoi(id(hw_p1_version).state.c_str());
// kW → W
float p_net = (id(hw_power_delivered).state - id(hw_power_returned).state) * 1000.0f;
float l1_w = (id(hw_power_del_l1).state - id(power_returned_l1).state) * 1000.0f;
float l2_w = (id(hw_power_del_l2).state - id(power_returned_l2).state) * 1000.0f;
float l3_w = (id(hw_power_del_l3).state - id(power_returned_l3).state) * 1000.0f;
// Gesigneerde stroom per fase (negatief bij teruglevering)
float i1 = id(power_returned_l1).state > 0 ? -id(current_l1).state : id(current_l1).state;
float i2 = id(power_returned_l2).state > 0 ? -id(current_l2).state : id(current_l2).state;
float i3 = id(power_returned_l3).state > 0 ? -id(current_l3).state : id(current_l3).state;
// Totaal import/export (t1 + t2)
float total_import = id(hw_energy_t1).state + id(hw_energy_t2).state;
float total_export = id(hw_return_t1).state + id(hw_return_t2).state;
// gas_timestamp als YYMMDDhhmmss
time_t now = time(nullptr);
struct tm *ti = localtime(&now);
long long gas_ts = (long long)(ti->tm_year % 100) * 10000000000LL
+ (ti->tm_mon + 1) * 100000000LL
+ ti->tm_mday * 1000000LL
+ ti->tm_hour * 10000LL
+ ti->tm_min * 100LL
+ ti->tm_sec;
// Cursor-gebaseerde JSON opbouw: conditionele velden worden
// weggelaten als de waarde niet beschikbaar is (isnan)
static char buf[1280];
int p = 0;
#define A(...) p += snprintf(buf + p, sizeof(buf) - p, __VA_ARGS__)
#define AF(key, val) if (!isnan(val)) A("\"" key "\":%.0f,", val)
A("{");
A("\"unique_id\":\"%s\",", id(hw_equipment_id).state.c_str());
A("\"wifi_ssid\":\"%s\",", WiFi.SSID().c_str());
A("\"wifi_strength\":%d,", wifi_pct);
A("\"smr_version\":%d,", smr_ver);
A("\"meter_model\":\"%s\",", id(hw_identification).state.c_str());
A("\"active_tariff\":%d,", atoi(id(hw_tariff).state.c_str()));
A("\"total_power_import_kwh\":%.3f,", total_import);
A("\"total_power_import_t1_kwh\":%.3f,", id(hw_energy_t1).state);
A("\"total_power_import_t2_kwh\":%.3f,", id(hw_energy_t2).state);
A("\"total_power_export_kwh\":%.3f,", total_export);
A("\"total_power_export_t1_kwh\":%.3f,", id(hw_return_t1).state);
A("\"total_power_export_t2_kwh\":%.3f,", id(hw_return_t2).state);
A("\"active_power_w\":%.0f,", p_net);
A("\"active_power_l1_w\":%.0f,", l1_w);
A("\"active_power_l2_w\":%.0f,", l2_w);
A("\"active_power_l3_w\":%.0f,", l3_w);
A("\"active_voltage_l1_v\":%.1f,", id(hw_voltage_l1).state);
A("\"active_voltage_l2_v\":%.1f,", id(hw_voltage_l2).state);
A("\"active_voltage_l3_v\":%.1f,", id(hw_voltage_l3).state);
A("\"active_current_l1_a\":%.1f,", i1);
A("\"active_current_l2_a\":%.1f,", i2);
A("\"active_current_l3_a\":%.1f,", i3);
AF("voltage_sag_l1_count", id(hw_sag_l1).state);
AF("voltage_sag_l2_count", id(hw_sag_l2).state);
AF("voltage_sag_l3_count", id(hw_sag_l3).state);
AF("voltage_swell_l1_count", id(hw_swell_l1).state);
AF("voltage_swell_l2_count", id(hw_swell_l2).state);
AF("voltage_swell_l3_count", id(hw_swell_l3).state);
AF("any_power_fail_count", id(hw_power_fail).state);
AF("long_power_fail_count", id(hw_long_power_fail).state);
A("\"total_gas_m3\":%.3f,", id(hw_gas).state);
A("\"gas_timestamp\":%lld,", gas_ts);
A("\"unique_gas_id\":\"%s\",", id(hw_gas_equipment_id).state.c_str());
A("\"external\":[{"
"\"unique_id\":\"%s\","
"\"type\":\"gas_meter\","
"\"timestamp\":%lld,"
"\"value\":%.3f,"
"\"unit\":\"m3\""
"}]",
id(hw_gas_equipment_id).state.c_str(),
gas_ts,
id(hw_gas).state);
A("}");
#undef A
#undef AF
req->send(200, "application/json", buf);
});
// GET /api → device-identificatie als HWE-P1 (na /api/v1/data registreren)
server->on("/api", HTTP_GET, [](AsyncWebServerRequest *req) {
req->send(200, "application/json",
"{\"product_type\":\"HWE-P1\","
"\"product_name\":\"P1 Meter\","
"\"serial\":\"a3f8c21d904e\","
"\"firmware_version\":\"5.18\","
"\"api_version\":\"v1\"}");
});
esp8266:
restore_from_flash: true
board: d1_mini
# Enable logging
logger:
baud_rate: 0
logs:
component: ERROR
http_request.arduino: ERROR # onderdruk de framework warning
# Enable Home Assistant API
api:
services:
service: set_dsmr_key
variables:
private_key: string
then:
- logger.log:
format: Setting private key %s. Set to empty string to disable
args: [private_key.c_str()]
- globals.set:
id: has_key
value: !lambda "return private_key.length() == 32;"
- lambda: |-
if (private_key.length() == 32)
memcpy(id(stored_decryption_key), private_key.c_str(), 32);
id(dsmr_instance).set_decryption_key(private_key.c_str());
ota:
platform: esphome
dashboard_import:
package_import_url: github://zuidwijk/dsmr/slimmelezer.yaml@main
import_full_config: true
uart:
id: uart_dsmr
baud_rate: 115200
rx_pin: D7
rx_buffer_size: 1700
web_server:
port: 80
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
min_auth_mode: WPA2
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: ${device_name}
captive_portal:
# mDNS: kondigt de SlimmeLezer+ aan als HomeWizard HWE-P1
mdns:
services:
- service: _hwenergy
protocol: _tcp
port: 80
txt:
api_enabled: "1"
path: /api/v1
product_name: P1 Meter
product_type: HWE-P1
serial: b4f8f21d965a
globals:
- id: has_key
type: bool
restore_value: yes
initial_value: "false"
- id: stored_decryption_key
type: char[32]
restore_value: yes
- id: smartevse_integration # SmartEVSE addition
type: bool
- id: smartevse_error # SmartEVSE addition
type: int
- id: last_telegram # HomeWizard API telegram endpoint
type: std::string
restore_value: no
initial_value: '""'
dsmr:
uart_id: uart_dsmr
id: dsmr_instance
max_telegram_length: 1700
# For Luxembourg users set here your decryption key
#decryption_key: !secret decryption_key // enable this when using decryption for Luxembourg; key like '00112233445566778899AABBCCDDEEFF'
sensor:
- platform: dsmr
energy_delivered_lux:
name: "Energy Consumed Luxembourg"
energy_delivered_tariff1:
id: hw_energy_t1 # HomeWizard API
name: "Energy Consumed Tariff 1"
energy_delivered_tariff2:
id: hw_energy_t2 # HomeWizard API
name: "Energy Consumed Tariff 2"
energy_returned_lux:
name: "Energy Produced Luxembourg"
energy_returned_tariff1:
id: hw_return_t1 # HomeWizard API
name: "Energy Produced Tariff 1"
energy_returned_tariff2:
id: hw_return_t2 # HomeWizard API
name: "Energy Produced Tariff 2"
power_delivered:
id: hw_power_delivered # HomeWizard API
name: "Power Consumed"
accuracy_decimals: 3
power_returned:
id: hw_power_returned # HomeWizard API
name: "Power Produced"
accuracy_decimals: 3
electricity_failures:
id: hw_power_fail # HomeWizard API
name: "Electricity Failures"
icon: mdi:alert
electricity_long_failures:
id: hw_long_power_fail # HomeWizard API
name: "Long Electricity Failures"
icon: mdi:alert
voltage_sag_l1:
id: hw_sag_l1 # HomeWizard API
name: "Voltage Sags Phase 1"
voltage_sag_l2:
id: hw_sag_l2 # HomeWizard API
name: "Voltage Sags Phase 2"
voltage_sag_l3:
id: hw_sag_l3 # HomeWizard API
name: "Voltage Sags Phase 3"
voltage_swell_l1:
id: hw_swell_l1 # HomeWizard API
name: "Voltage Swells Phase 1"
voltage_swell_l2:
id: hw_swell_l2 # HomeWizard API
name: "Voltage Swells Phase 2"
voltage_swell_l3:
id: hw_swell_l3 # HomeWizard API
name: "Voltage Swells Phase 3"
voltage_l1:
id: hw_voltage_l1 # HomeWizard API
name: "Voltage Phase 1"
voltage_l2:
id: hw_voltage_l2 # HomeWizard API
name: "Voltage Phase 2"
voltage_l3:
id: hw_voltage_l3 # HomeWizard API
name: "Voltage Phase 3"
current_l1:
id: current_l1 # SmartEVSE + HomeWizard API
name: "Current Phase 1"
current_l2:
id: current_l2 # SmartEVSE + HomeWizard API
name: "Current Phase 2"
current_l3:
id: current_l3 # SmartEVSE + HomeWizard API
name: "Current Phase 3"
power_delivered_l1:
id: hw_power_del_l1 # HomeWizard API
name: "Power Consumed Phase 1"
accuracy_decimals: 3
power_delivered_l2:
id: hw_power_del_l2 # HomeWizard API
name: "Power Consumed Phase 2"
accuracy_decimals: 3
power_delivered_l3:
id: hw_power_del_l3 # HomeWizard API
name: "Power Consumed Phase 3"
accuracy_decimals: 3
power_returned_l1:
id: power_returned_l1 # SmartEVSE + HomeWizard API
name: "Power Produced Phase 1"
accuracy_decimals: 3
power_returned_l2:
id: power_returned_l2 # SmartEVSE + HomeWizard API
name: "Power Produced Phase 2"
accuracy_decimals: 3
power_returned_l3:
id: power_returned_l3 # SmartEVSE + HomeWizard API
name: "Power Produced Phase 3"
accuracy_decimals: 3
gas_delivered:
id: hw_gas # HomeWizard API
name: "Gas Consumed"
gas_delivered_be:
name: "Gas Consumed Belgium"
- platform: uptime
name: "SlimmeLezer Uptime"
update_interval: 60s
- platform: wifi_signal
id: hw_wifi_signal # HomeWizard API
name: "SlimmeLezer Wi-Fi Signal"
update_interval: 60s
text_sensor:
- platform: dsmr
identification:
id: hw_identification # HomeWizard API
name: "DSMR Identification"
equipment_id:
id: hw_equipment_id # HomeWizard API (unique_id)
name: "Equipment ID"
gas_equipment_id:
id: hw_gas_equipment_id # HomeWizard API (unique_gas_id)
name: "Gas Equipment ID"
p1_version:
id: hw_p1_version # HomeWizard API
name: "DSMR Version"
p1_version_be:
name: "DSMR Version Belgium"
electricity_tariff: # SmartEVSE + HomeWizard API
id: hw_tariff
name: "Electricity tariff"
telegram: # HomeWizard API telegram endpoint
id: hw_telegram
internal: true
on_value:
then:
- lambda: |-
id(last_telegram) = x;
- platform: wifi_info
ip_address:
name: "SlimmeLezer IP Address"
ssid:
name: "SlimmeLezer Wi-Fi SSID"
bssid:
name: "SlimmeLezer Wi-Fi BSSID"
- platform: version
name: "ESPHome Version"
hide_timestamp: true
# SmartEVSE additions
binary_sensor:
- platform: template
name: "SmartEVSE API"
device_class: connectivity
lambda: "return id(smartevse_error) < 5;"
switch:
- platform: template
name: "SmartEVSE Integration"
optimistic: true
turn_on_action:
- globals.set:
id: smartevse_integration
value: "true"
- globals.set:
id: smartevse_error
value: "5"
turn_off_action:
- globals.set:
id: smartevse_integration
value: "false"
- globals.set:
id: smartevse_error
value: "5"
icon: "mdi:ev-station"
restore_mode: RESTORE_DEFAULT_ON
http_request:
timeout: 1500ms
verify_ssl: false
esp8266_disable_ssl_support: true
interval:
- interval: 2sec
then:
- if:
condition:
lambda: |-
return (id(smartevse_integration) &&
!isnan(id(current_l1).state) &&
!isnan(id(current_l2).state) &&
!isnan(id(current_l3).state));
then:
- http_request.post:
url: !lambda |-
float s1 = id(power_returned_l1).state > 0 ? -id(current_l1).state : id(current_l1).state;
float s2 = id(power_returned_l2).state > 0 ? -id(current_l2).state : id(current_l2).state;
float s3 = id(power_returned_l3).state > 0 ? -id(current_l3).state : id(current_l3).state;
static char url[128];
snprintf(url, sizeof(url),
"http://${smartevse_host}/currents?L1=%.0f&L2=%.0f&L3=%.0f",
s1 * 10, s2 * 10, s3 * 10);
return url;
request_headers:
Content-Length: 0
on_response:
then:
lambda: |-
if (id(smartevse_error) != 0) {
id(smartevse_error) = 0;
}
on_error:
then:
lambda: |-
if (id(smartevse_error) < 5) {
id(smartevse_error) += 1;
} |