-
Notifications
You must be signed in to change notification settings - Fork 0
/
slimmelezer.yaml
229 lines (213 loc) · 7.9 KB
/
slimmelezer.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
substitutions:
devicename: slimmelezer
friendly_name: Slimme Lezer
device_description: "DIY P1 module to read your smart meter"
################ Generics ################
esphome:
name: ${devicename}
friendly_name: ${friendly_name}
comment: "${device_description}"
esp8266:
board: d1_mini
restore_from_flash: true
wifi:
manual_ip:
static_ip: !secret wifi_static_ip_p1reader
# General settings: captive portal, logger, api, ota, time, restart switch, wifi
# General sensors: status, uptime, version, wifi info etc
packages:
general_settings: !include includes/general_settings.yaml
general_sensors: !include includes/general_sensors.yaml
logger:
# Must be 0 to disable the serial logging. This cannot work
# the same time uart on pin 13 / D7 is working.
baud_rate: 0
level: info
web_server:
################ Components ################
dsmr:
id: dsmr_instance
http_request:
timeout: 2s
esp8266_disable_ssl_support: true
uart:
- id: uart_bus
baud_rate: 115200
rx_pin: D7
################ Sensors ################
sensor:
- platform: dsmr
energy_delivered_tariff1:
id: dsmr_electricity_delivered_1
name: "Energy Consumed Tariff 1"
state_class: total_increasing
internal: true
energy_returned_tariff1:
id: dsmr_electricity_returned_1
name: "Energy Produced Tariff 1"
state_class: total_increasing
internal: true
energy_delivered_tariff2:
id: dsmr_electricity_delivered_2
name: "Energy Consumed Tariff 2"
state_class: total_increasing
internal: true
energy_returned_tariff2:
id: dsmr_electricity_returned_2
name: "Energy Produced Tariff 2"
state_class: total_increasing
internal: true
power_delivered:
accuracy_decimals: 3
id: dsmr_electricity_currently_delivered
name: "Power Consumed"
power_returned:
accuracy_decimals: 3
id: dsmr_electricity_currently_returned
name: "Power Produced"
voltage_l1:
id: dsmr_phase_voltage_l1
name: "Voltage Phase 1"
voltage_l2:
id: dsmr_phase_voltage_l2
name: "Voltage Phase 2"
voltage_l3:
id: dsmr_phase_voltage_l3
name: "Voltage Phase 3"
current_l1:
id: dsmr_phase_power_current_l1
name: "Current Phase 1"
current_l2:
id: dsmr_phase_power_current_l2
name: "Current Phase 2"
current_l3:
id: dsmr_phase_power_current_l3
name: "Current Phase 3"
power_delivered_l1:
accuracy_decimals: 3
id: dsmr_phase_currently_delivered_l1
name: "Power Consumed Phase 1"
power_delivered_l2:
accuracy_decimals: 3
id: dsmr_phase_currently_delivered_l2
name: "Power Consumed Phase 2"
power_delivered_l3:
accuracy_decimals: 3
id: dsmr_phase_currently_delivered_l3
name: "Power Consumed Phase 3"
power_returned_l1:
accuracy_decimals: 3
id: dsmr_phase_currently_returned_l1
name: "Power Produced Phase 1"
power_returned_l2:
accuracy_decimals: 3
id: dsmr_phase_currently_returned_l2
name: "Power Produced Phase 2"
power_returned_l3:
accuracy_decimals: 3
id: dsmr_phase_currently_returned_l3
name: "Power Produced Phase 3"
gas_delivered:
id: dsmr_extra_device_delivered
name: "Gas Consumed"
state_class: total_increasing
- platform: template
id: template_current_l1
name: "Template Current L1"
update_interval: 2s
lambda: |-
float l1 = id(dsmr_phase_currently_returned_l1).state > 0 ? - id(dsmr_phase_power_current_l1).state : id(dsmr_phase_power_current_l1).state;
return l1;
- platform: template
id: template_current_l2
name: "Template Current L2"
update_interval: 2s
lambda: |-
float l2 = id(dsmr_phase_currently_returned_l2).state > 0 ? - id(dsmr_phase_power_current_l2).state : id(dsmr_phase_power_current_l2).state;
return l2;
- platform: template
id: template_current_l3
name: "Template Current L3"
update_interval: 2s
lambda: |-
float l3 = id(dsmr_phase_currently_returned_l3).state > 0 ? - id(dsmr_phase_power_current_l3).state : id(dsmr_phase_power_current_l3).state;
return l3;
text_sensor:
- platform: dsmr
timestamp:
id: dsmr_timestamp
internal: true
- platform: template
id: dsmr_timestamp_formatted
internal: true
update_interval: 2s
lambda: |-
esphome::optional<std::string> result;
std::string input = id(dsmr_timestamp).state;
if (!input.empty()) {
std::string year = "20" + input.substr(0, 2);
std::string month = input.substr(2, 2);
std::string day = input.substr(4, 2);
std::string hour = input.substr(6, 2);
std::string minute = input.substr(8, 2);
std::string second = input.substr(10, 2);
std::string indicator = input.substr(12, 1);
std::string timezone = "+00:00";
if (indicator == "W") {
timezone = "+01:00";
} else if (indicator == "S") {
timezone = "+02:00";
}
result = year + "-" + month + "-" + day + "T" + hour + ":" + minute + ":" + second + timezone;
}
return result;
################ Actions ################
interval:
- interval: 10sec
then:
- http_request.post:
url: !secret dsmr_reader_url
# url: http://x.x.x.x/api/v2/datalogger/dsmrreading
headers:
Authorization: !secret dsmr_reader_token
# Authorization: Token ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890
Content-Type: application/json
json: |-
root["electricity_currently_delivered"] = id(dsmr_electricity_currently_delivered).state;
root["electricity_currently_returned"] = id(dsmr_electricity_currently_returned).state;
root["electricity_delivered_1"] = id(dsmr_electricity_delivered_1).state;
root["electricity_delivered_2"] = id(dsmr_electricity_delivered_2).state;
root["electricity_returned_1"] = id(dsmr_electricity_returned_1).state;
root["electricity_returned_2"] = id(dsmr_electricity_returned_2).state;
root["extra_device_delivered"] = id(dsmr_extra_device_delivered).state;
root["extra_device_timestamp"] = id(dsmr_timestamp_formatted).state;
root["phase_currently_delivered_l1"] = id(dsmr_phase_currently_delivered_l1).state;
root["phase_currently_delivered_l2"] = id(dsmr_phase_currently_delivered_l2).state;
root["phase_currently_delivered_l3"] = id(dsmr_phase_currently_delivered_l3).state;
root["phase_currently_returned_l1"] = id(dsmr_phase_currently_returned_l1).state;
root["phase_currently_returned_l2"] = id(dsmr_phase_currently_returned_l2).state;
root["phase_currently_returned_l3"] = id(dsmr_phase_currently_returned_l3).state;
root["phase_power_current_l1"] = id(dsmr_phase_power_current_l1).state;
root["phase_power_current_l2"] = id(dsmr_phase_power_current_l2).state;
root["phase_power_current_l3"] = id(dsmr_phase_power_current_l3).state;
root["phase_voltage_l1"] = id(dsmr_phase_voltage_l1).state;
root["phase_voltage_l2"] = id(dsmr_phase_voltage_l2).state;
root["phase_voltage_l3"] = id(dsmr_phase_voltage_l3).state;
root["timestamp"] = id(dsmr_timestamp_formatted).state;
- interval: 2sec
then:
- http_request.post:
headers:
Content-Length: 0
url: !lambda |-
std::string url;
float l1 = id(template_current_l1).state;
float l2 = id(template_current_l2).state;
float l3 = id(template_current_l3).state;
url.append("http://192.168.88.216/currents?L1=");
url.append(to_string(l1*10));
url.append("&L2=");
url.append(to_string(l2*10));
url.append("&L3=");
url.append(to_string(l3*10));
return url.c_str();