Project

Algemeen

Profiel

Esphome p1meter victron version » Geschiedenis » Versie 2

Micha Kersloot, 28-06-2023 15:15

1 1 Micha Kersloot
h1. Esphome p1meter victron version
2
3 2 Micha Kersloot
based on https://github.com/NuKeMtje/ESPHomeDSMRVictron
4
and https://github.com/freakent/dbus-mqtt-devices is needed on the GX device.
5
6 1 Micha Kersloot
<pre>
7
substitutions:
8
  name: p1meter
9
  friendly_name: p1meter
10
11
esphome:
12
  name: ${name}
13
  friendly_name: ${friendly_name}
14
15
#esp8266:
16
#  board: esp01_1m
17
#
18
19
esp32:
20
  board: ttgo-t7-v13-mini32
21
  framework:
22
    type: arduino
23
24
# Enable logging
25
logger:
26
  # Serial logging is disabled by setting the logger baud rate to 0.
27
  # Otherwise the logger will occupy the hardware UART, making it unavailable
28
  # for receiving smart meter data on pin D7 (GPIO13).
29
  baud_rate: 0
30
  
31
# Enable Home Assistant API
32
api:
33
  encryption:
34
    key: "qf1fx8kUj0uTiCK59UTTZalztwe8G1uZpOosMvvrV4E="
35
36
ota:
37
  password: "71b4ad566e816a7f8acb70e75ab94b21"
38
39
wifi:
40
  ssid: !secret wifi_ssid
41
  password: !secret wifi_password
42
43
  # Enable fallback hotspot (captive portal) in case wifi connection fails
44
  ap:
45
    ssid: "P1Meter Fallback Hotspot"
46
    password: "YPlPB0mxRpxD"
47
48
captive_portal:
49
    
50
uart:
51
  id: uart_bus
52
  rx_pin:
53
#    number: 3
54
    number: GPIO16
55
    inverted: true
56
  baud_rate: 115200
57
  rx_buffer_size: 1700
58
59
dsmr:
60
  request_pin: GPIO19
61
62
globals:
63
  - id: portal_id
64
    type: std::string
65
    restore_value: no
66
    initial_value: '"<not set>"'
67
  - id: device_instance
68
    type: std::string
69
    restore_value: no
70
    initial_value: '"<not set>"'
71
72
mqtt:
73
  broker: venus
74
  discovery: false
75
  birth_message:
76
    topic: device/p1mqtt/Status
77
    payload: "{ \"clientId\": \"p1mqtt\", \"connected\": 1, \"version\": \"v1.0\", \"services\": {\"meter1\": \"grid\"} }"
78
  will_message:
79
    topic: device/p1mqtt/Status
80
    payload: "{ \"clientId\": \"p1mqtt\", \"connected\": 0, \"services\": {\"meter1\": \"grid\"} }"
81
  on_json_message:
82
    topic: device/p1mqtt/DBus
83
    then:
84
      - lambda: |-
85
          id(portal_id) = x["portalId"].as<std::string>();
86
          id(device_instance) = x["deviceInstance"]["meter1"].as<std::string>();
87
      - mqtt.publish_json:
88
          topic: !lambda |-
89
            return str_sprintf("W/%s/grid/%s/CustomName", id(portal_id).c_str(), id(device_instance).c_str());
90
          payload: |-
91
            root["value"] = "P1-MQTT Meter";
92
      - mqtt.publish_json:
93
          topic: !lambda |-
94
            return str_sprintf("W/%s/grid/%s/Role", id(portal_id).c_str(), id(device_instance).c_str());
95
          payload: |-
96
            root["value"] = "grid";
97
98
sensor:
99
  - platform: dsmr
100
    energy_delivered_tariff1:
101
      name: Energy Delivered Tariff 1
102
      id: energy_delivered_t1
103
      state_class: total_increasing
104
    energy_delivered_tariff2:
105
      name: Energy Delivered Tariff 2
106
      id: energy_delivered_t2
107
      state_class: total_increasing
108
    energy_returned_tariff1:
109
      name: Energy Returned Tariff 1
110
      id: energy_returned_t1
111
    energy_returned_tariff2:
112
      name: Energy Returned Tariff 2
113
      id: energy_returned_t2
114
    power_delivered:
115
      name: Power Consumed
116
      id: power_consumed
117
    power_returned:
118
      name: Power Returned
119
      id: power_returned
120
    electricity_failures:
121
      name: Electricity Failures
122
    electricity_long_failures:
123
      name: Electricity Long Failures
124
    voltage_l1:
125
      name: Voltage L1
126
      id: voltage_l1
127
      on_value:
128
        then:
129
        - mqtt.publish_json:
130
            topic: !lambda |-
131
              return str_sprintf("W/%s/grid/%s/Ac/L1/Voltage", id(portal_id).c_str(), id(device_instance).c_str());
132
            payload: |-
133
              root["value"] = id(voltage_l1).state;
134
    voltage_l2:
135
      name: Voltage L2
136
      id: voltage_l2
137
      on_value:
138
        then:
139
          - mqtt.publish_json:
140
              topic: !lambda |-
141
                return str_sprintf("W/%s/grid/%s/Ac/L2/Voltage", id(portal_id).c_str(), id(device_instance).c_str());
142
              payload: |-
143
                root["value"] = id(voltage_l2).state;
144
    voltage_l3:
145
      name: Voltage L3
146
      id: voltage_l3
147
      on_value:
148
        then:
149
          - mqtt.publish_json:
150
              topic: !lambda |-
151
                return str_sprintf("W/%s/grid/%s/Ac/L3/Voltage", id(portal_id).c_str(), id(device_instance).c_str());
152
              payload: |-
153
                root["value"] = id(voltage_l3).state;
154
    current_l1:
155
      name: Current L1
156
      id: current_l1
157
      on_value:
158
        then:
159
          - mqtt.publish_json:
160
              topic: !lambda |-
161
                return str_sprintf("W/%s/grid/%s/Ac/L1/Current", id(portal_id).c_str(), id(device_instance).c_str());
162
              payload: |-
163
                root["value"] = id(current_l1).state;
164
    current_l2:
165
      name: Current L2
166
      id: current_l2
167
      on_value:
168
        then:
169
          - mqtt.publish_json:
170
              topic: !lambda |-
171
                return str_sprintf("W/%s/grid/%s/Ac/L2/Current", id(portal_id).c_str(), id(device_instance).c_str());
172
              payload: |-
173
                root["value"] = id(current_l2).state;
174
    current_l3:
175
      name: Current L3
176
      id: current_l3
177
      on_value:
178
        then:
179
          - mqtt.publish_json:
180
              topic: !lambda |-
181
                return str_sprintf("W/%s/grid/%s/Ac/L3/Current", id(portal_id).c_str(), id(device_instance).c_str());
182
              payload: |-
183
                root["value"] = id(current_l3).state;
184
    power_delivered_l1:
185
      name: Power Delivered L1
186
      id: power_delivered_l1
187
    power_delivered_l2:
188
      name: Power Delivered L2
189
      id: power_delivered_l2
190
    power_delivered_l3:
191
      name: Power Delivered L3
192
      id: power_delivered_l3
193
    power_returned_l1:
194
      name: Power Returned L1
195
      id: power_returned_l1
196
    power_returned_l2:
197
      name: Power Returned L2
198
      id: power_returned_l2
199
    power_returned_l3:
200
      name: Power Returned L3
201
      id: power_returned_l3
202
    gas_delivered:
203
      name: Gas Delivered
204
  - platform: template
205
    name: "Total power"
206
    id: total_power
207
    lambda: |-
208
      return (id(power_consumed).state - id(power_returned).state)*1000.0;
209
    update_interval: 1s
210
    device_class: power
211
    state_class: measurement
212
    unit_of_measurement: W
213
    on_value:
214
      then:
215
        - mqtt.publish_json:
216
            topic: !lambda |-
217
              return str_sprintf("W/%s/grid/%s/Ac/Power", id(portal_id).c_str(), id(device_instance).c_str());
218
            payload: |-
219
              root["value"] = id(total_power).state;
220
  - platform: template
221
    name: "Power L1"
222
    id: power_l1
223
    lambda: |-
224
      return (id(power_delivered_l1).state - id(power_returned_l1).state)*1000.0;
225
    update_interval: 1s
226
    device_class: power
227
    state_class: measurement
228
    unit_of_measurement: W
229
    on_value:
230
      then:
231
        - mqtt.publish_json:
232
            topic: !lambda |-
233
              return str_sprintf("W/%s/grid/%s/Ac/L1/Power", id(portal_id).c_str(), id(device_instance).c_str());
234
            payload: |-
235
              root["value"] = id(power_l1).state;    
236
  - platform: template
237
    name: "Power L2"
238
    id: power_l2
239
    lambda: |-
240
      return (id(power_delivered_l2).state - id(power_returned_l2).state)*1000.0;
241
    update_interval: 1s
242
    device_class: power
243
    state_class: measurement
244
    unit_of_measurement: W
245
    on_value:
246
      then:
247
        - mqtt.publish_json:
248
            topic: !lambda |-
249
              return str_sprintf("W/%s/grid/%s/Ac/L2/Power", id(portal_id).c_str(), id(device_instance).c_str());
250
            payload: |-
251
              root["value"] = id(power_l2).state;
252
  - platform: template
253
    name: "Power L3"
254
    id: power_l3
255
    lambda: |-
256
      return (id(power_delivered_l3).state - id(power_returned_l3).state)*1000.0;
257
    update_interval: 1s
258
    device_class: power
259
    state_class: measurement
260
    unit_of_measurement: W
261
    on_value:
262
      then:
263
        - mqtt.publish_json:
264
            topic: !lambda |-
265
              return str_sprintf("W/%s/grid/%s/Ac/L3/Power", id(portal_id).c_str(), id(device_instance).c_str());
266
            payload: |-
267
              root["value"] = id(power_l3).state;                                       
268
  - platform: template
269
    name: "Total consumed"
270
    id: total_consumed
271
    lambda: |-
272
      return id(energy_delivered_t1).state + id(energy_delivered_t2).state;
273
    update_interval: 1s
274
    device_class: energy
275
    state_class: total_increasing
276
    unit_of_measurement: kWh
277
    on_value:
278
      then:
279
        - mqtt.publish_json:
280
            topic: !lambda |-
281
              return str_sprintf("W/%s/grid/%s/Ac/Energy/Forward", id(portal_id).c_str(), id(device_instance).c_str());
282
            payload: |-
283
              root["value"] = id(total_consumed).state;    
284
  - platform: template
285
    name: "Total injected"
286
    id: total_injected
287
    lambda: |-
288
      return id(energy_returned_t1).state + id(energy_returned_t2).state;
289
    update_interval: 1s
290
    device_class: energy
291
    state_class: total_increasing
292
    unit_of_measurement: kWh
293
    on_value:
294
      then:
295
        - mqtt.publish_json:
296
            topic: !lambda |-
297
              return str_sprintf("W/%s/grid/%s/Ac/Energy/Reverse", id(portal_id).c_str(), id(device_instance).c_str());
298
            payload: |-
299
              root["value"] = id(total_injected).state;
300
        
301
text_sensor:
302
  - platform: dsmr
303
    identification:
304
      name: Identification
305
      id: meter_id
306
      on_value:
307
        then:
308
          - mqtt.publish_json:
309
              topic: !lambda |-
310
                return str_sprintf("W/%s/grid/%s/Serial", id(portal_id).c_str(), id(device_instance).c_str());
311
              payload: |-
312
                root["value"] = id(meter_id).state;
313
    p1_version:
314
      name: Version
315
316
</pre>