-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathd0-meter.yaml
260 lines (236 loc) · 6.88 KB
/
d0-meter.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
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
# SPDX-FileCopyrightText: 2023 Holger Steinhaus <hsteinhaus@gmx.de>
#
# SPDX-License-Identifier: GPL-3.0-only
external_components:
- source: github://mampfes/esphome_obis_d0
substitutions:
device_name: "d0-meter"
friendly_name: Grid meter
device_description: D0 to MQTT Grid meter interface
esphome:
name: ${device_name}
comment: ${device_description}
esp8266:
board: esp01_1m
logger:
baud_rate: 0
hardware_uart: UART1
level: WARN
api:
port: 6053
ota:
password: !secret ota_password
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
domain: .wifi.home
web_server:
port: 80
ota: true
uart:
id: uart0
rx_pin: GPIO3
baud_rate: 9600
data_bits: 7
parity: EVEN
stop_bits: 1
obis_d0:
id: d0_0
uart_id: uart0
sensor:
- platform: obis_d0
name: "Consumed Energy"
id: consumed_energy
obis_d0_id: d0_0
obis_code: "1-0:1.8.0*255"
unit_of_measurement: kWh
accuracy_decimals: 4
state_class: total_increasing
device_class: energy
on_value:
then:
- mqtt.publish_json:
topic: !lambda |-
return str_sprintf("W/%s/grid/%s/Ac/Energy/Forward", id(portal_id).c_str(), id(device_instance).c_str());
payload: |-
root["value"] = id(consumed_energy).state;
- platform: obis_d0
name: "Exported Energy"
id: exported_energy
obis_d0_id: d0_0
obis_code: "1-0:2.8.0*255"
unit_of_measurement: kWh
accuracy_decimals: 4
state_class: total_increasing
device_class: energy
on_value:
then:
- mqtt.publish_json:
topic: !lambda |-
return str_sprintf("W/%s/grid/%s/Ac/Energy/Reverse", id(portal_id).c_str(), id(device_instance).c_str());
payload: |-
root["value"] = id(exported_energy).state;
- platform: obis_d0
name: "Total power"
id: power_total
obis_d0_id: d0_0
obis_code: "1-0:16.7.0*255"
unit_of_measurement: W
accuracy_decimals: 2
state_class: total
device_class: power
on_value:
then:
- mqtt.publish_json:
topic: !lambda |-
return str_sprintf("W/%s/grid/%s/Ac/Power", id(portal_id).c_str(), id(device_instance).c_str());
payload: |-
root["value"] = id(power_total).state;
- platform: obis_d0
name: "Power L1"
id: power_l1
obis_d0_id: d0_0
obis_code: "1-0:36.7.0*255"
unit_of_measurement: W
accuracy_decimals: 2
state_class: total
device_class: power
on_value:
then:
- mqtt.publish_json:
topic: !lambda |-
return str_sprintf("W/%s/grid/%s/Ac/L1/Power", id(portal_id).c_str(), id(device_instance).c_str());
payload: |-
root["value"] = id(power_l1).state;
- platform: obis_d0
name: "Power L2"
id: power_l2
obis_d0_id: d0_0
obis_code: "1-0:56.7.0*255"
unit_of_measurement: W
accuracy_decimals: 2
state_class: total
device_class: power
on_value:
then:
- mqtt.publish_json:
topic: !lambda |-
return str_sprintf("W/%s/grid/%s/Ac/L2/Power", id(portal_id).c_str(), id(device_instance).c_str());
payload: |-
root["value"] = id(power_l2).state;
- platform: obis_d0
name: "Power L3"
id: power_l3
obis_d0_id: d0_0
obis_code: "1-0:76.7.0*255"
unit_of_measurement: W
accuracy_decimals: 2
state_class: total
device_class: power
on_value:
then:
- mqtt.publish_json:
topic: !lambda |-
return str_sprintf("W/%s/grid/%s/Ac/L3/Power", id(portal_id).c_str(), id(device_instance).c_str());
payload: |-
root["value"] = id(power_l3).state;
- platform: obis_d0
name: "Voltage L1"
id: voltage_l1
obis_d0_id: d0_0
obis_code: "1-0:32.7.0*255"
unit_of_measurement: V
accuracy_decimals: 1
state_class: total
device_class: power
on_value:
then:
- mqtt.publish_json:
topic: !lambda |-
return str_sprintf("W/%s/grid/%s/Ac/L1/Voltage", id(portal_id).c_str(), id(device_instance).c_str());
payload: |-
root["value"] = id(voltage_l1).state;
- platform: obis_d0
name: "Voltage L2"
id: voltage_l2
obis_d0_id: d0_0
obis_code: "1-0:52.7.0*255"
unit_of_measurement: V
accuracy_decimals: 1
state_class: total
device_class: power
on_value:
then:
- mqtt.publish_json:
topic: !lambda |-
return str_sprintf("W/%s/grid/%s/Ac/L2/Voltage", id(portal_id).c_str(), id(device_instance).c_str());
payload: |-
root["value"] = id(voltage_l2).state;
- platform: obis_d0
name: "Voltage L3"
id: voltage_l3
obis_d0_id: d0_0
obis_code: "1-0:72.7.0*255"
unit_of_measurement: V
accuracy_decimals: 1
state_class: total
device_class: power
on_value:
then:
- mqtt.publish_json:
topic: !lambda |-
return str_sprintf("W/%s/grid/%s/Ac/L3/Voltage", id(portal_id).c_str(), id(device_instance).c_str());
payload: |-
root["value"] = id(voltage_l3).state;
text_sensor:
- platform: obis_d0
name: "Device Identification"
id: meter_id
obis_d0_id: d0_0
obis_code: "1-0:96.1.0*255"
entity_category: diagnostic
on_value:
then:
- mqtt.publish_json:
topic: !lambda |-
return str_sprintf("W/%s/grid/%s/Serial", id(portal_id).c_str(), id(device_instance).c_str());
payload: |-
root["value"] = id(meter_id).state;
- platform: mqtt_subscribe
name: "Device status"
id: device_status
topic: device/d0mqtt/DBus
globals:
- id: portal_id
type: std::string
restore_value: no
initial_value: '"<not set>"'
- id: device_instance
type: std::string
restore_value: no
initial_value: '"<not set>"'
mqtt:
broker: ess.wifi.home
discovery: false
birth_message:
topic: device/d0mqtt/Status
payload: "{ \"clientId\": \"d0mqtt\", \"connected\": 1, \"version\": \"v1.0\", \"services\": {\"meter1\": \"grid\"} }"
will_message:
topic: device/d0mqtt/Status
payload: "{ \"clientId\": \"d0mqtt\", \"connected\": 0, \"services\": {\"meter1\": \"grid\"} }"
on_json_message:
topic: device/d0mqtt/DBus
then:
- lambda: |-
id(portal_id) = std::string(x["portalId"]);
id(device_instance) = std::string(x["deviceInstance"]["meter1"]);
- mqtt.publish_json:
topic: !lambda |-
return str_sprintf("W/%s/grid/%s/CustomName", id(portal_id).c_str(), id(device_instance).c_str());
payload: |-
root["value"] = "D0-MQTT Meter";
- mqtt.publish_json:
topic: !lambda |-
return str_sprintf("W/%s/grid/%s/Role", id(portal_id).c_str(), id(device_instance).c_str());
payload: |-
root["value"] = "grid";