forked from aj-nagrom/esphome-modbus-server
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathesphome-xemex-fake-modbus-server.yaml
367 lines (326 loc) · 16.5 KB
/
esphome-xemex-fake-modbus-server.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
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
substitutions:
device_name: "modbus-server-xemex"
device_comment: "Modbus Client that can simulate modbus of Xemex CSMB"
esphome:
name: ${device_name}
friendly_name: ${device_name}
comment: $device_comment
name_add_mac_suffix: false
project:
name: "MODBUS.Server-Xemex"
version: "1"
esp32:
board: nodemcu-32s
#https://www.az-delivery.de/en/products/esp32-developmentboard
framework:
type: arduino
logger:
api:
encryption:
key: !secret api_encryption_key
ota:
password: !secret ota_password
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
domain : !secret domain
ap:
ssid: ${device_name} AP
password: !secret hotspot_pass
captive_portal:
# Enable Web server
web_server:
port: 80
text_sensor:
- platform: wifi_info
ip_address:
name: "${device_name} - IP Address"
ssid:
name: "${device_name} - Wi-Fi SSID"
bssid:
name: "${device_name} - Wi-Fi BSSID"
- platform: version
name: "${device_name} - ESPHome Version"
hide_timestamp: true
# see: https://esphome.io/components/time.html
time:
- platform: homeassistant
# id: homeassistant_time
## end common.yaml
external_components:
- source: github://thomase1234/esphome-fake-xemex-csmb@master
refresh: 60s
components:
- modbus_server
uart:
- id: intmodbus
# https://cdn.shopify.com/s/files/1/1509/1638/files/ESP-32_NodeMCU_Developmentboard_Pinout.pdf
tx_pin: 18 # DI PURPLE wire
rx_pin: 19 # RO BLUE wire
baud_rate: 9600 # default for Xemex CMSB
stop_bits: 1 #default to 8E1
data_bits: 8 #default to 8E1
parity: EVEN #default to 8E1
debug:
direction: BOTH
modbus_server:
- id: modbusserver
uart_id: intmodbus
address: 1 # slave address
# - If you're using a RS485 like this one, make sure to set the re_pin and de_pin
# http://domoticx.com/wp-content/uploads/2018/01/RS485-module-shield.jpg
# re_pin: GPIO17 # optional
# de_pin: GPIO16 # optional
holding_registers:
# I've implemented some of the regs found in this PDF:
# https://xemex.eu/wp-content/uploads/2021/07/User-manual-CSMB-1.0.pdf
- start_address: 0x4000 # register for Serial Number
default: 0x1 # This is what my real Xemex CSMB returned
number: 2 # number of registers in the range
on_read: | # called whenever a register in the range is read
// 'address' contains the requested register address
// 'value' contains the stored register value
ESP_LOGI("ON_READ", "This is a lambda. address=0x%04x, value=%d", address, value);
return value; // you can return the stored value or something else.
- start_address: 0x4002 # register for Device Code
default: 20802 # default value for this register
number: 1 # number of registers in the range
on_read: | # called whenever a register in the range is read
// 'address' contains the requested register address
// 'value' contains the stored register value
ESP_LOGI("ON_READ", "This is a lambda. address=0x%04x, value=%d", address, value);
return value; // you can return the stored value or something else.
- start_address: 0x4003 # register for Device Address
default: 0x1 # default value for this register
number: 1 # number of registers in the range
on_read: | # called whenever a register in the range is read
// 'address' contains the requested register address
// 'value' contains the stored register value
ESP_LOGI("ON_READ", "This is a lambda. address=0x%04x, value=%d", address, value);
return value; // you can return the stored value or something else.
- start_address: 0x4004 # register for RS485 Baudrate Low
default: 9600 # default value for this register
number: 1 # number of registers in the range
on_read: | # called whenever a register in the range is read
// 'address' contains the requested register address
// 'value' contains the stored register value
ESP_LOGI("ON_READ", "This is a lambda. address=0x%04x, value=%d", address, value);
return value; // you can return the stored value or something else.
- start_address: 0x4005 # starting register for Protocol Version. This is the first register of a FLOAT
default: 0x3f80 # default value for this register
number: 1 # number of registers in the range
on_read: | # called whenever a register in the range is read
// 'address' contains the requested register address
// 'value' contains the stored register value
ESP_LOGI("ON_READ", "This is a lambda. address=0x%04x, value=%d", address, value);
return value; // you can return the stored value or something else.
- start_address: 0x4006 # ending register for Protocol Version. This is the second register of a FLOAT
default: 0x0000 # default value for this register
number: 1 # number of registers in the range
on_read: | # called whenever a register in the range is read
// 'address' contains the requested register address
// 'value' contains the stored register value
ESP_LOGI("ON_READ", "This is a lambda. address=0x%04x, value=%d", address, value);
return value; // you can return the stored value or something else.
- start_address: 0x4007 # starting register for Software Version. This is the first register of a FLOAT
default: 0x4000 # default value for this register
number: 1 # number of registers in the range
on_read: | # called whenever a register in the range is read
// 'address' contains the requested register address
// 'value' contains the stored register value
ESP_LOGI("ON_READ", "This is a lambda. address=0x%04x, value=%d", address, value);
return value; // you can return the stored value or something else.
- start_address: 0x4008 # ending register for Software Version. This is the second register of a FLOAT
default: 0x0000 # default value for this register
number: 1 # number of registers in the range
on_read: | # called whenever a register in the range is read
// 'address' contains the requested register address
// 'value' contains the stored register value
ESP_LOGI("ON_READ", "This is a lambda. address=0x%04x, value=%d", address, value);
return value; // you can return the stored value or something else.
- start_address: 0x4009 # starting register for Hardware Version. This is the first register of a FLOAT
default: 0x0000 # default value for this register
number: 1 # number of registers in the range
on_read: | # called whenever a register in the range is read
// 'address' contains the requested register address
// 'value' contains the stored register value
ESP_LOGI("ON_READ", "This is a lambda. address=0x%04x, value=%d", address, value);
return value; // you can return the stored value or something else.
- start_address: 0x400A # ending register for Hardware Version. This is the second register of a FLOAT
default: 0x0000 # default value for this register
number: 1 # number of registers in the range
on_read: | # called whenever a register in the range is read
// 'address' contains the requested register address
// 'value' contains the stored register value
ESP_LOGI("ON_READ", "This is a lambda. address=0x%04x, value=%d", address, value);
return value; // you can return the stored value or something else.
- start_address: 0x400B # register for Meter Amps.
default: 80 # default value for this register
number: 1 # number of registers in the range
on_read: | # called whenever a register in the range is read
// 'address' contains the requested register address
// 'value' contains the stored register value
ESP_LOGI("ON_READ", "This is a lambda. address=0x%04x, value=%d", address, value);
return value; // you can return the stored value or something else.
- start_address: 0x400C # register for CT Ratio.
default: 2000 # default value for this register
number: 1 # number of registers in the range
on_read: | # called whenever a register in the range is read
// 'address' contains the requested register address
// 'value' contains the stored register value
ESP_LOGI("ON_READ", "This is a lambda. address=0x%04x, value=%d", address, value);
return value; // you can return the stored value or something else.
- start_address: 0x400D # register for RS485 Line Settings.
default: 36 # default value for this register
number: 1 # number of registers in the range
on_read: | # called whenever a register in the range is read
// 'address' contains the requested register address
// 'value' contains the stored register value
ESP_LOGI("ON_READ", "This is a lambda. address=0x%04x, value=%d", address, value);
return value; // you can return the stored value or something else.
- start_address: 0x400E # register for RS485 Line Termination.
default: 1 # default value for this register
number: 1 # number of registers in the range
on_read: | # called whenever a register in the range is read
// 'address' contains the requested register address
// 'value' contains the stored register value
ESP_LOGI("ON_READ", "This is a lambda. address=0x%04x, value=%d", address, value);
return value; // you can return the stored value or something else.
- start_address: 0x400F # register for RS485 Baudrate High.
default: 0 # default value for this register
number: 1 # number of registers in the range
on_read: | # called whenever a register in the range is read
// 'address' contains the requested register address
// 'value' contains the stored register value
ESP_LOGI("ON_READ", "This is a lambda. address=0x%04x, value=%d", address, value);
return value; // you can return the stored value or something else.
- start_address: 0x500C # starting register for RMS Current CT1. This is the first register of a FLOAT
default: 0x0000 # default value for this register
number: 1 # number of registers in the range
on_read: | # called whenever a register in the range is read
// 'address' contains the requested register address
// 'value' contains the stored register value
ESP_LOGI("ON_READ", "CT1. address=0x%04x, value=0x%04x", address, value);
return value; // you can return the stored value or something else.
- start_address: 0x500D # ending register for RMS Current CT1. This is the second register of a FLOAT
default: 0x0000 # default value for this register
number: 1 # number of registers in the range
on_read: | # called whenever a register in the range is read
// 'address' contains the requested register address
// 'value' contains the stored register value
ESP_LOGI("ON_READ", "CT1. address=0x%04x, value=0x%04x", address, value);
return value; // you can return the stored value or something else.
- start_address: 0x500E # starting register for RMS Current CT2. This is the first register of a FLOAT
default: 0x3E73 # default value for this register 3E:73:43:33
number: 1 # number of registers in the range
on_read: | # called whenever a register in the range is read
// 'address' contains the requested register address
// 'value' contains the stored register value
ESP_LOGI("ON_READ", "CT2. address=0x%04x, value=0x%04x", address, value);
return value; // you can return the stored value or something else.
- start_address: 0x500F # ending register for RMS Current CT2. This is the second register of a FLOAT
default: 0x4333 # default value for this register
number: 1 # number of registers in the range
on_read: | # called whenever a register in the range is read
// 'address' contains the requested register address
// 'value' contains the stored register value
ESP_LOGI("ON_READ", "CT2. address=0x%04x, value=0x%04x", address, value);
return value; // you can return the stored value or something else.
- start_address: 0x5010 # starting register for RMS Current CT3. This is the first register of a FLOAT
default: 0x3E09 # default value for this register 3E:09:39:9A
number: 1 # number of registers in the range
on_read: | # called whenever a register in the range is read
// 'address' contains the requested register address
// 'value' contains the stored register value
ESP_LOGI("ON_READ", "CT3. address=0x%04x, value=0x%04x", address, value);
return value; // you can return the stored value or something else.
- start_address: 0x5011 # ending register for RMS Current CT3. This is the second register of a FLOAT
default: 0x399A # default value for this register
number: 1 # number of registers in the range
on_read: | # called whenever a register in the range is read
// 'address' contains the requested register address
// 'value' contains the stored register value
ESP_LOGI("ON_READ", "CT3. address=0x%04x, value=0x%04x", address, value);
return value; // you can return the stored value or something else.
number:
- platform: template
name: ct1current
id: ct1current
optimistic: False
update_interval: 2s
min_value: 0
max_value: 60
step: 0.1
unit_of_measurement: A
set_action:
then:
- lambda: |-
ESP_LOGD("modbus-server-xemex", "Current set to: %f", x);
// convert from float to 2 uint16_t.
union
{
uint16_t x_int[2];
float x_f;
} u;
u.x_f = x;
// setting modbusserver registers
// use https://www.h-schmidt.net/FloatConverter/IEEE754.html to doublecheck conversions
modbusserver->write_holding_register(0x500C,u.x_int[1]);
modbusserver->write_holding_register(0x500D,u.x_int[0]);
ESP_LOGD("modbus-server-xemex", "Registers for CT1 set to: 0x%04x and 0x%04x", u.x_int[1], u.x_int[0]);
// and finally set the value of this number template
id(ct1current).publish_state(x);
- platform: template
name: ct2current
id: ct2current
optimistic: False
update_interval: 2s
min_value: 0
max_value: 60
step: 0.1
unit_of_measurement: A
set_action:
then:
- lambda: |-
ESP_LOGD("modbus-server-xemex", "Current set to: %f", x);
// convert from float to 2 uint16_t.
union
{
uint16_t x_int[2];
float x_f;
} u;
u.x_f = x;
// setting modbusserver registers
// use https://www.h-schmidt.net/FloatConverter/IEEE754.html to doublecheck conversions
modbusserver->write_holding_register(0x500E,u.x_int[1]);
modbusserver->write_holding_register(0x500F,u.x_int[0]);
ESP_LOGD("modbus-server-xemex", "Registers for CT2 set to: 0x%04x and 0x%04x", u.x_int[1], u.x_int[0]);
// and finally set the value of this number template
id(ct2current).publish_state(x);
- platform: template
name: ct3current
id: ct3current
optimistic: False
update_interval: 2s
min_value: 0
max_value: 60
step: 0.1
unit_of_measurement: A
set_action:
then:
- lambda: |-
ESP_LOGD("modbus-server-xemex", "Current set to: %f", x);
// convert from float to 2 uint16_t.
union
{
uint16_t x_int[2];
float x_f;
} u;
u.x_f = x;
// setting modbusserver registers
// use https://www.h-schmidt.net/FloatConverter/IEEE754.html to doublecheck conversions
modbusserver->write_holding_register(0x5010,u.x_int[1]);
modbusserver->write_holding_register(0x5011,u.x_int[0]);
ESP_LOGD("modbus-server-xemex", "Registers for CT3 set to: 0x%04x and 0x%04x", u.x_int[1], u.x_int[0]);
// and finally set the value of this number template
id(ct3current).publish_state(x);