forked from 1technophile/OpenMQTTGateway
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ZmqttDiscovery.ino
1333 lines (1221 loc) · 71.1 KB
/
ZmqttDiscovery.ino
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
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
OpenMQTTGateway Addon - ESP8266 or Arduino program for home automation
Act as a gateway between your 433mhz, infrared IR, BLE, LoRa signal and one interface like an MQTT broker
Send and receiving command by MQTT
This is the Home Assistant MQTT Discovery addon.
Copyright: (c) Rafal Herok
This file is part of OpenMQTTGateway.
OpenMQTTGateway is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenMQTTGateway is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "User_config.h"
#ifdef ZmqttDiscovery
String getMacAddress() {
uint8_t baseMac[6];
char baseMacChr[13] = {0};
# if defined(ESP8266)
WiFi.macAddress(baseMac);
sprintf(baseMacChr, "%02X%02X%02X%02X%02X%02X", baseMac[0], baseMac[1], baseMac[2], baseMac[3], baseMac[4], baseMac[5]);
# elif defined(ESP32)
esp_read_mac(baseMac, ESP_MAC_WIFI_STA);
sprintf(baseMacChr, "%02X%02X%02X%02X%02X%02X", baseMac[0], baseMac[1], baseMac[2], baseMac[3], baseMac[4], baseMac[5]);
# else
sprintf(baseMacChr, "%02X%02X%02X%02X%02X%02X", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
# endif
return String(baseMacChr);
}
String getUniqueId(String name, String sufix) {
String uniqueId = (String)getMacAddress() + "-" + name + sufix;
return String(uniqueId);
}
# ifdef ZgatewayBT
/**
* Create a discover messages form a list of attribute
*
* @param mac the MAC address
* @param sensorList[][0] = component type
* @param sensorList[][1] = name
* @param sensorList[][2] = availability topic
* @param sensorList[][3] = device class
* @param sensorList[][4] = value template
* @param sensorList[][5] = payload on
* @param sensorList[][6] = payload off
* @param sensorList[][7] = unit of measurement
* @param sensorList[][8] = unit of measurement
* @param sensorCount number of sensor
* @param device_name name of sensors
* @param device_manufacturer name of manufacturer
* @param device_model the model
* */
void createDiscoveryFromList(const char* mac,
const char* sensorList[][9],
int sensorCount,
const char* device_name,
const char* device_manufacturer,
const char* device_model) {
for (int i = 0; i < sensorCount; i++) {
String discovery_topic = String(subjectBTtoMQTT) + "/" + String(mac);
String unique_id = String(mac) + "-" + sensorList[i][1];
createDiscovery(sensorList[i][0],
discovery_topic.c_str(), sensorList[i][1], unique_id.c_str(),
will_Topic, sensorList[i][3], sensorList[i][4],
sensorList[i][5], sensorList[i][6], sensorList[i][7],
0, "", "", false, "",
device_name, device_manufacturer, device_model, mac, false,
sensorList[i][8] //The state class
);
}
}
# endif
/**
* @brief Create a message for Discovery Device Trigger. For HA @see https://www.home-assistant.io/integrations/device_trigger.mqtt/
* @param use_gateway_info Boolean where true mean use the OMG information as Device Information
* @param topic The Topic where the trigger will publish the content
* @param type The type of the trigger, e.g. button_short_press. Entries supported by the HA Frontend: button_short_press, button_short_release, button_long_press, button_long_release, button_double_press, button_triple_press, button_quadruple_press, button_quintuple_press. If set to an unsupported value, will render as subtype type, e.g. button_1 spammed with type set to spammed and subtype set to button_1
* @param subtype The subtype of the trigger, e.g. button_1. Entries supported by the HA frontend: turn_on, turn_off, button_1, button_2, button_3, button_4, button_5, button_6. If set to an unsupported value, will render as subtype type, e.g. left_button pressed with type set to button_short_press and subtype set to left_button
* @param unique_id Valid only if gateway entry is false, The IDs that uniquely identify the device. For example a serial number.
* @param device_name Valid only if gateway entry is false, The name of the device.
* @param device_manufacturer Valid only if gateway entry is false, The manufacturer of the device.
* @param device_model Valid only if gateway entry is false, The model of the device.
* @param device_id Valid only if gateway entry is false, The connection of the device to the outside world
*/
void announceDeviceTrigger(bool use_gateway_info, char* topic, char* type, char* subtype, char* unique_id, char* device_name, char* device_manufacturer, char* device_model, char* device_id) {
//Create The Json
StaticJsonDocument<JSON_MSG_BUFFER> jsonBuffer;
JsonObject sensor = jsonBuffer.to<JsonObject>();
// SET Default Configuration
sensor["automation_type"] = "trigger"; // The type of automation, must be ‘trigger’.
//SET TYPE
if (type && type[0] != 0) {
sensor["type"] = type;
} else {
sensor["type"] = "button_short_press";
}
//SET SUBTYPE
if (subtype && subtype[0] != 0) {
sensor["subtype"] = subtype;
} else {
sensor["subtype"] = "turn_on";
}
/* Set The topic */
if (topic && topic[0]) {
char state_topic[mqtt_topic_max_size];
strcpy(state_topic, mqtt_topic);
strcat(state_topic, gateway_name);
strcat(state_topic, topic);
sensor["topic"] = state_topic;
}
/* Set The Devices */
StaticJsonDocument<JSON_MSG_BUFFER> jsonDeviceBuffer;
JsonObject device = jsonDeviceBuffer.to<JsonObject>();
JsonArray identifiers = device.createNestedArray("identifiers");
if (use_gateway_info) {
device["name"] = gateway_name;
# ifndef GATEWAY_MODEL
String model = "";
serializeJson(modules, model);
device["model"] = model;
# else
device["model"] = GATEWAY_MODEL;
# endif
device["manufacturer"] = GATEWAY_MANUFACTURER;
device["sw_version"] = OMG_VERSION;
identifiers.add(getMacAddress());
} else {
char deviceid[13];
memcpy(deviceid, &unique_id[0], 12);
deviceid[12] = '\0';
identifiers.add(deviceid);
/*Set Connection */
if (device_id && device_id[0] != 0) {
JsonArray connections = device.createNestedArray("connections");
JsonArray connection_mac = connections.createNestedArray();
connection_mac.add("mac");
connection_mac.add(device_id);
}
//Set manufacturer
if (device_manufacturer && device_manufacturer[0]) {
device["manufacturer"] = device_manufacturer;
}
//Set name
if (device_name && device_name[0]) {
device["name"] = device_name;
}
// set The Model
if (device_model && device_model[0]) {
device["model"] = device_model;
}
device["via_device"] = gateway_name; //device name of the board
}
sensor["device"] = device; //device representing the board
/* Publish on the topic */
String topic_to_publish = String(discovery_prefix) + "/device_automation/" + String(unique_id) + "/config";
Log.trace(F("Announce Device Trigger %s" CR), topic_to_publish.c_str());
pub_custom_topic((char*)topic_to_publish.c_str(), sensor, true);
}
/*
* Remove a substring p from a given string s
*/
std::string remove_substring(std::string s, const std::string& p) {
std::string::size_type n = p.length();
for (std::string::size_type i = s.find(p);
i != std::string::npos;
i = s.find(p))
s.erase(i, n);
return s;
}
/**
* @brief Generate message and publish it on an MQTT discovery explorer. For HA @see https://www.home-assistant.io/docs/mqtt/discovery/
*
* @param sensor_type the Type
* @param st_topic set state topic,
* @param s_name set name,
* @param unique_id set uniqueId
* @param availability_topic set availability_topic,
* @param device_class set device_class,
* @param value_template set value_template,
* @param payload_on set payload_on,
* @param payload_off set payload_off,
* @param unit_of_meas set unit_of_meas,
* @param off_delay set off_delay
* @param payload_available set payload_available,
* @param payload_not_available set payload_not_available
* @param gateway_entity set is a gateway entity,
* @param cmd_topic set command topic
* @param device_name set device name,
* @param device_manufacturer set device manufacturer,
* @param device_model set device model,
* @param device_id set device(BLE)/entity(RTL_433) identification,
* @param retainCmd set retain
* @param state_class set state class
*
* */
void createDiscovery(const char* sensor_type,
const char* st_topic, const char* s_name, const char* unique_id,
const char* availability_topic, const char* device_class, const char* value_template,
const char* payload_on, const char* payload_off, const char* unit_of_meas,
int off_delay,
const char* payload_available, const char* payload_not_available, bool gateway_entity, const char* cmd_topic,
const char* device_name, const char* device_manufacturer, const char* device_model, const char* device_id, bool retainCmd,
const char* state_class, const char* state_off, const char* state_on, const char* enum_options, const char* command_template) {
StaticJsonDocument<JSON_MSG_BUFFER_MAX> jsonBuffer;
JsonObject sensor = jsonBuffer.to<JsonObject>();
// If a component cannot render it's state (f.i. KAKU relays) no state topic
// should be added. Without a state topic HA will use optimistic mode for the
// component by default. The Home Assistant UI for optimistic switches
// (separate on and off icons) allows for multiple
// subsequent on commands. This is required for dimming on KAKU relays like
// the ACM-300.
if (st_topic && st_topic[0]) {
char state_topic[mqtt_topic_max_size];
// If not an entity belonging to the gateway we put wild card for the location and gateway name
// allowing to have the entity detected by several gateways and a consistent discovery topic among the gateways
if (gateway_entity) {
strcpy(state_topic, mqtt_topic);
strcat(state_topic, gateway_name);
} else {
strcpy(state_topic, "+/+");
}
strcat(state_topic, st_topic);
if (strcmp(sensor_type, "cover") == 0) {
sensor["tilt_status_t"] = state_topic; // tilt_status_topic for cover
} else {
sensor["stat_t"] = state_topic;
}
}
if (availability_topic && availability_topic[0] && gateway_entity) {
char avty_topic[mqtt_topic_max_size];
strcpy(avty_topic, mqtt_topic);
strcat(avty_topic, gateway_name);
strcat(avty_topic, availability_topic);
sensor["avty_t"] = avty_topic;
}
if (device_class && device_class[0]) {
// We check if the class belongs to HAAS classes list
int num_classes = sizeof(availableHASSClasses) / sizeof(availableHASSClasses[0]);
for (int i = 0; i < num_classes; i++) { // see class list and size into config_mqttDiscovery.h
if (strcmp(availableHASSClasses[i], device_class) == 0) {
sensor["dev_cla"] = device_class; //device_class
}
}
}
if (unit_of_meas && unit_of_meas[0]) {
// We check if the class belongs to HAAS units list
int num_units = sizeof(availableHASSUnits) / sizeof(availableHASSUnits[0]);
for (int i = 0; i < num_units; i++) { // see units list and size into config_mqttDiscovery.h
if (strcmp(availableHASSUnits[i], unit_of_meas) == 0) {
sensor["unit_of_meas"] = unit_of_meas; //unit_of_measurement*/
}
}
}
sensor["name"] = s_name; //name
sensor["uniq_id"] = unique_id; //unique_id
if (retainCmd)
sensor["retain"] = retainCmd; // Retain command
if (value_template && value_template[0]) {
if (strstr(value_template, " | is_defined") != NULL && SYSConfig.ohdiscovery) {
sensor["val_tpl"] = remove_substring(value_template, " | is_defined"); //OpenHAB compatible HA auto discovery
} else {
if (strcmp(sensor_type, "cover") == 0) {
sensor["tilt_status_tpl"] = value_template; // tilt_status_template for cover
} else {
sensor["val_tpl"] = value_template; //HA Auto discovery
}
}
}
if (payload_on && payload_on[0]) {
if (strcmp(sensor_type, "button") == 0) {
sensor["pl_prs"] = payload_on; // payload_press for a button press
} else if (strcmp(sensor_type, "number") == 0) {
sensor["cmd_tpl"] = payload_on; // payload_on for a switch
} else if (strcmp(sensor_type, "update") == 0) {
sensor["pl_inst"] = payload_on; // payload_install for update
} else if (strcmp(sensor_type, "cover") == 0) {
int value = std::stoi(payload_on);
sensor["tilt_opnd_val"] = value; // tilt_open_value for cover
} else {
sensor["pl_on"] = payload_on; // payload_on for the rest
}
}
if (payload_off && payload_off[0]) {
if (strcmp(sensor_type, "cover") == 0) {
sensor["pl_cls"] = payload_off; // payload_close for cover
} else {
sensor["pl_off"] = payload_off; //payload_off
}
}
if (command_template && command_template[0]) {
if (strcmp(sensor_type, "cover") == 0) {
sensor["tilt_cmd_tpl"] = command_template; //command_template
} else {
sensor["cmd_tpl"] = command_template; //command_template
}
}
if (strcmp(sensor_type, "device_tracker") == 0)
sensor["source_type"] = "bluetooth_le"; // payload_install for update
if (off_delay != 0)
sensor["off_delay"] = off_delay; //off_delay
if (payload_available[0])
sensor["pl_avail"] = payload_available; // payload_on
if (payload_not_available[0])
sensor["pl_not_avail"] = payload_not_available; //payload_off
if (state_class && state_class[0])
sensor["stat_cla"] = state_class; //add the state class on the sensors ( https://developers.home-assistant.io/docs/core/entity/sensor/#available-state-classes )
if (state_on != nullptr)
if (strcmp(state_on, "true") == 0) {
sensor["stat_on"] = true;
} else {
sensor["stat_on"] = state_on;
}
if (state_off != nullptr)
if (strcmp(state_off, "false") == 0) {
sensor["stat_off"] = false;
} else {
sensor["stat_off"] = state_off;
}
if (cmd_topic[0]) {
char command_topic[mqtt_topic_max_size];
strcpy(command_topic, mqtt_topic);
strcat(command_topic, gateway_name);
strcat(command_topic, cmd_topic);
if (strcmp(sensor_type, "cover") == 0) {
sensor["tilt_cmd_t"] = command_topic; // tilt_command_topic for cover
} else {
sensor["cmd_t"] = command_topic; //command_topic
}
}
if (enum_options != nullptr) {
sensor["options"] = enum_options;
}
StaticJsonDocument<JSON_MSG_BUFFER> jsonDeviceBuffer;
JsonObject device = jsonDeviceBuffer.to<JsonObject>();
JsonArray identifiers = device.createNestedArray("ids");
if (gateway_entity) {
//device representing the board
device["name"] = String(gateway_name);
# ifndef GATEWAY_MODEL
String model = "";
serializeJson(modules, model);
device["mdl"] = model;
# else
device["mdl"] = GATEWAY_MODEL;
# endif
device["mf"] = GATEWAY_MANUFACTURER;
if (ethConnected) {
# ifdef ESP32_ETHERNET
device["cu"] = String("http://") + String(ETH.localIP().toString()) + String("/"); //configuration_url
# endif
} else {
device["cu"] = String("http://") + String(WiFi.localIP().toString()) + String("/"); //configuration_url
}
device["sw"] = OMG_VERSION;
identifiers.add(String(getMacAddress()));
} else {
//The Connections
if (device_id[0]) {
JsonArray connections = device.createNestedArray("cns");
JsonArray connection_mac = connections.createNestedArray();
connection_mac.add("mac");
connection_mac.add(device_id);
//Device representing the actual sensor/switch device
//The Device ID
identifiers.add(device_id);
}
if (device_manufacturer[0]) {
device["mf"] = device_manufacturer;
}
if (device_model[0]) {
device["mdl"] = device_model;
}
// generate unique device name by adding the second half of the device_id only if device_name and device_id are different and we don't want to use the BLE name
if (device_name[0]) {
if (strcmp(device_id, device_name) != 0 && device_id[0] && !ForceDeviceName) {
device["name"] = device_name + String("-") + String(device_id + 6);
} else {
device["name"] = device_name;
}
}
device["via_device"] = String(gateway_name); //device name of the board
}
sensor["device"] = device;
String topic = String(discovery_prefix) + "/" + String(sensor_type) + "/" + String(unique_id) + "/config";
Log.trace(F("Announce Device %s on %s" CR), String(sensor_type).c_str(), topic.c_str());
pub_custom_topic((char*)topic.c_str(), sensor, true);
}
void eraseTopic(const char* sensor_type, const char* unique_id) {
if (sensor_type == NULL || unique_id == NULL) {
return;
}
String topic = String(discovery_prefix) + "/" + String(sensor_type) + "/" + String(unique_id) + "/config";
Log.trace(F("Erase entity discovery %s on %s" CR), String(sensor_type).c_str(), topic.c_str());
pubMQTT((char*)topic.c_str(), "", true);
}
# ifdef ZgatewayBT
void btPresenceParametersDiscovery() {
createDiscovery("number", //set Type
subjectBTtoMQTT, "BT: Presence/Tracker timeout", (char*)getUniqueId("presenceawaytimer", "").c_str(), //set state_topic,name,uniqueId
will_Topic, "", "{{ value_json.presenceawaytimer/60000 }}", //set availability_topic,device_class,value_template,
"{\"presenceawaytimer\":{{value*60000}},\"save\":true}", "", "min", //set,payload_on,payload_off,unit_of_meas,
0, //set off_delay
Gateway_AnnouncementMsg, will_Message, true, subjectMQTTtoBTset, //set,payload_available,payload_not available ,is a gateway entity, command topic
"", "", "", "", false, // device name, device manufacturer, device model, device ID, retain,
stateClassNone //State Class
);
}
void btScanParametersDiscovery() {
if (!BTConfig.adaptiveScan) {
createDiscovery("number", //set Type
subjectBTtoMQTT, "BT: Interval between scans", (char*)getUniqueId("interval", "").c_str(), //set state_topic,name,uniqueId
will_Topic, "", "{{ value_json.interval/1000 }}", //set availability_topic,device_class,value_template,
"{\"interval\":{{value*1000}},\"save\":true}", "", "s", //set,payload_on,payload_off,unit_of_meas,
0, //set off_delay
Gateway_AnnouncementMsg, will_Message, true, subjectMQTTtoBTset, //set,payload_available,payload_not available ,is a gateway entity, command topic
"", "", "", "", false, // device name, device manufacturer, device model, device ID, retain,
stateClassNone //State Class
);
createDiscovery("number", //set Type
subjectBTtoMQTT, "BT: Interval between active scans", (char*)getUniqueId("intervalacts", "").c_str(), //set state_topic,name,uniqueId
will_Topic, "", "{{ value_json.intervalacts/1000 }}", //set availability_topic,device_class,value_template,
"{\"intervalacts\":{{value*1000}},\"save\":true}", "", "s", //set,payload_on,payload_off,unit_of_meas,
0, //set off_delay
Gateway_AnnouncementMsg, will_Message, true, subjectMQTTtoBTset, //set,payload_available,payload_not available ,is a gateway entity, command topic
"", "", "", "", false, // device name, device manufacturer, device model, device ID, retain,
stateClassNone //State Class
);
}
}
# endif
void pubMqttDiscovery() {
Log.trace(F("omgStatusDiscovery" CR));
createDiscovery("binary_sensor", //set Type
will_Topic, "SYS: Connectivity", (char*)getUniqueId("connectivity", "").c_str(), //set state_topic,name,uniqueId
will_Topic, "connectivity", "", //set availability_topic,device_class,value_template,
Gateway_AnnouncementMsg, will_Message, "", //set,payload_on,payload_off,unit_of_meas,
0, //set off_delay
Gateway_AnnouncementMsg, will_Message, true, "", //set,payload_available,payload_not available ,is a gateway entity, command topic
"", "", "", "", false, // device name, device manufacturer, device model, device ID, retain
stateClassNone //State Class
);
createDiscovery("sensor", //set Type
subjectSYStoMQTT, "SYS: Uptime", (char*)getUniqueId("uptime", "").c_str(), //set state_topic,name,uniqueId
will_Topic, "duration", "{{ value_json.uptime }}", //set availability_topic,device_class,value_template,
"", "", "s", //set,payload_on,payload_off,unit_of_meas,
0, //set off_delay
Gateway_AnnouncementMsg, will_Message, true, "", //set,payload_available,payload_not available ,is a gateway entity, command topic
"", "", "", "", false, // device name, device manufacturer, device model, device ID, retain
stateClassMeasurement //State Class
);
createDiscovery("sensor", //set Type
subjectSYStoMQTT, "SYS: Free memory", (char*)getUniqueId("freemem", "").c_str(), //set state_topic,name,uniqueId
will_Topic, "data_size", "{{ value_json.freemem }}", //set availability_topic,device_class,value_template,
"", "", "B", //set,payload_on,payload_off,unit_of_meas,
0, //set off_delay
Gateway_AnnouncementMsg, will_Message, true, "", //set,payload_available,payload_not available ,is a gateway entity, command topic
"", "", "", "", false, // device name, device manufacturer, device model, device ID, retain
stateClassMeasurement //State Class
);
createDiscovery("sensor", //set Type
subjectSYStoMQTT, "SYS: IP", (char*)getUniqueId("ip", "").c_str(), //set state_topic,name,uniqueId
will_Topic, "", "{{ value_json.ip }}", //set availability_topic,device_class,value_template,
"", "", "", //set,payload_on,payload_off,unit_of_meas,
0, //set off_delay
Gateway_AnnouncementMsg, will_Message, true, "", //set,payload_available,payload_not available ,is a gateway entity, command topic
"", "", "", "", false, // device name, device manufacturer, device model, device ID, retain
stateClassNone //State Class
);
createDiscovery("switch", //set Type
subjectSYStoMQTT, "SYS: Auto discovery", (char*)getUniqueId("disc", "").c_str(), //set state_topic,name,uniqueId
will_Topic, "", "{{ value_json.disc }}", //set availability_topic,device_class,value_template,
"{\"disc\":true,\"save\":true}", "{\"disc\":false,\"save\":true}", "", //set,payload_on,payload_off,unit_of_meas,
0, //set off_delay
Gateway_AnnouncementMsg, will_Message, true, subjectMQTTtoSYSset, //set,payload_avalaible,payload_not avalaible ,is a gateway entity, command topic
"", "", "", "", false, // device name, device manufacturer, device model, device MAC, retain,
stateClassNone, //State Class
"false", "true" //state_off, state_on
);
createDiscovery("switch", //set Type
subjectSYStoMQTT, "SYS: OpenHAB discovery", (char*)getUniqueId("ohdisc", "").c_str(), //set state_topic,name,uniqueId
will_Topic, "", "{{ value_json.ohdisc }}", //set availability_topic,device_class,value_template,
"{\"ohdisc\":true,\"save\":true}", "{\"ohdisc\":false,\"save\":true}", "", //set,payload_on,payload_off,unit_of_meas,
0, //set off_delay
Gateway_AnnouncementMsg, will_Message, true, subjectMQTTtoSYSset, //set,payload_avalaible,payload_not avalaible ,is a gateway entity, command topic
"", "", "", "", false, // device name, device manufacturer, device model, device MAC, retain,
stateClassNone, //State Class
"false", "true" //state_off, state_on
);
# ifdef RGB_INDICATORS
createDiscovery("number", //set Type
subjectSYStoMQTT, "SYS: LED Brightness", (char*)getUniqueId("rgbb", "").c_str(), //set state_topic,name,uniqueId
will_Topic, "", "{{ (value_json.rgbb/2.55) | round(0) }}", //set availability_topic,device_class,value_template,
"{\"rgbb\":{{ (value*2.55) | round(0) }},\"save\":true}", "", "", //set,payload_on,payload_off,unit_of_meas,
0, //set off_delay
Gateway_AnnouncementMsg, will_Message, true, subjectMQTTtoSYSset, //set,payload_available,payload_not available ,is a gateway entity, command topic
"", "", "", "", false, // device name, device manufacturer, device model, device ID, retain,
stateClassNone //State Class
);
# endif
# ifdef ZdisplaySSD1306
createDiscovery("switch", //set Type
subjectSSD1306toMQTT, "SSD1306: Control", (char*)getUniqueId("onstate", "").c_str(), //set state_topic,name,uniqueId
will_Topic, "", "{{ value_json.onstate }}", //set availability_topic,device_class,value_template,
"{\"onstate\":true,\"save\":true}", "{\"onstate\":false,\"save\":true}", "", //set,payload_on,payload_off,unit_of_meas,
0, //set off_delay
Gateway_AnnouncementMsg, will_Message, true, subjectMQTTtoSSD1306set, //set,payload_available,payload_not available ,is a gateway entity, command topic
"", "", "", "", false, // device name, device manufacturer, device model, device MAC, retain
stateClassNone, //State Class
"false", "true" //state_off, state_on
);
createDiscovery("switch", //set Type
subjectWebUItoMQTT, "SSD1306: Display metric", (char*)getUniqueId("displayMetric", "").c_str(), //set state_topic,name,uniqueId
will_Topic, "", "{{ value_json.displayMetric }}", //set availability_topic,device_class,value_template,
"{\"displayMetric\":true,\"save\":true}", "{\"displayMetric\":false,\"save\":true}", "", //set,payload_on,payload_off,unit_of_meas,
0, //set off_delay
Gateway_AnnouncementMsg, will_Message, true, subjectMQTTtoWebUIset, //set,payload_available,payload_not available ,is a gateway entity, command topic
"", "", "", "", false, // device name, device manufacturer, device model, device MAC, retain
stateClassNone, //State Class
"false", "true" //state_off, state_on
);
createDiscovery("number", //set Type
subjectSSD1306toMQTT, "SSD1306: Brightness", (char*)getUniqueId("brightness", "").c_str(), //set state_topic,name,uniqueId
will_Topic, "", "{{ value_json.brightness }}", //set availability_topic,device_class,value_template,
"{\"brightness\":{{value}},\"save\":true}", "", "", //set,payload_on,payload_off,unit_of_meas,
0, //set off_delay
Gateway_AnnouncementMsg, will_Message, true, subjectMQTTtoSSD1306set, //set,payload_available,payload_not available,is a gateway entity, command topic
"", "", "", "", false, // device name, device manufacturer, device model, device ID, retain
stateClassNone //State Class
);
# endif
# ifndef ESP32_ETHERNET
createDiscovery("sensor", //set Type
subjectSYStoMQTT, "SYS: RSSI", (char*)getUniqueId("rssi", "").c_str(), //set state_topic,name,uniqueId
will_Topic, "signal_strength", "{{ value_json.rssi }}", //set availability_topic,device_class,value_template,
"", "", "dB", //set,payload_on,payload_off,unit_of_meas,
0, //set off_delay
Gateway_AnnouncementMsg, will_Message, true, "", //set,payload_available,payload_not available ,is a gateway entity, command topic
"", "", "", "", false, // device name, device manufacturer, device model, device ID, retain
stateClassNone //State Class
);
# endif
# if defined(ESP32) && !defined(NO_INT_TEMP_READING)
createDiscovery("sensor", //set Type
subjectSYStoMQTT, "SYS: Internal temperature", (char*)getUniqueId("tempc", "").c_str(), //set state_topic,name,uniqueId
will_Topic, "temperature", "{{ value_json.tempc | round(1)}}", //set availability_topic,device_class,value_template,
"", "", "°C", //set,payload_on,payload_off,unit_of_meas,
0, //set off_delay
Gateway_AnnouncementMsg, will_Message, true, "", //set,payload_avalaible,payload_not avalaible ,is a gateway entity, command topic
"", "", "", "", false, // device name, device manufacturer, device model, device MAC
stateClassMeasurement //State Class
);
# if defined(ZboardM5STICKC) || defined(ZboardM5STICKCP) || defined(ZboardM5TOUGH)
createDiscovery("sensor", //set Type
subjectSYStoMQTT, "SYS: Bat voltage", (char*)getUniqueId("m5batvoltage", "").c_str(), //set state_topic,name,uniqueId
will_Topic, "voltage", "{{ value_json.m5batvoltage }}", //set availability_topic,device_class,value_template,
"", "", "V", //set,payload_on,payload_off,unit_of_meas,
0, //set off_delay
Gateway_AnnouncementMsg, will_Message, true, "", //set,payload_available,payload_not available ,is a child device, command topic
"", "", "", "", false, // device name, device manufacturer, device model, device ID, retain
stateClassNone //State Class
);
createDiscovery("sensor", //set Type
subjectSYStoMQTT, "SYS: Bat current", (char*)getUniqueId("m5batcurrent", "").c_str(), //set state_topic,name,uniqueId
will_Topic, "current", "{{ value_json.m5batcurrent }}", //set availability_topic,device_class,value_template,
"", "", "A", //set,payload_on,payload_off,unit_of_meas,
0, //set off_delay
Gateway_AnnouncementMsg, will_Message, true, "", //set,payload_available,payload_not available ,is a child device, command topic
"", "", "", "", false, // device name, device manufacturer, device model, device ID, retain
stateClassNone //State Class
);
createDiscovery("sensor", //set Type
subjectSYStoMQTT, "SYS: Vin voltage", (char*)getUniqueId("m5vinvoltage", "").c_str(), //set state_topic,name,uniqueId
will_Topic, "voltage", "{{ value_json.m5vinvoltage }}", //set availability_topic,device_class,value_template,
"", "", "V", //set,payload_on,payload_off,unit_of_meas,
0, //set off_delay
Gateway_AnnouncementMsg, will_Message, true, "", //set,payload_available,payload_not available ,is a child device, command topic
"", "", "", "", false, // device name, device manufacturer, device model, device ID, retain
stateClassNone //State Class
);
createDiscovery("sensor", //set Type
subjectSYStoMQTT, "SYS: Vin current", (char*)getUniqueId("m5vincurrent", "").c_str(), //set state_topic,name,uniqueId
will_Topic, "current", "{{ value_json.m5vincurrent }}", //set availability_topic,device_class,value_template,
"", "", "A", //set,payload_on,payload_off,unit_of_meas,
0, //set off_delay
Gateway_AnnouncementMsg, will_Message, true, "", //set,payload_available,payload_not available ,is a child device, command topic
"", "", "", "", false, // device name, device manufacturer, device model, device ID, retain
stateClassNone //State Class
);
# endif
# ifdef ZboardM5STACK
createDiscovery("sensor", //set Type
subjectSYStoMQTT, "SYS: Batt level", (char*)getUniqueId("m5battlevel", "").c_str(), //set state_topic,name,uniqueId
will_Topic, "battery", "{{ value_json.m5battlevel }}", //set availability_topic,device_class,value_template,
"", "", "%", //set,payload_on,payload_off,unit_of_meas,
0, //set off_delay
Gateway_AnnouncementMsg, will_Message, true, "", //set,payload_available,payload_not available ,is a child device, command topic
"", "", "", "", false, // device name, device manufacturer, device model, device ID, retain
stateClassNone //State Class
);
createDiscovery("binary_sensor", //set Type
subjectSYStoMQTT, "SYS: Is Charging", (char*)getUniqueId("m5ischarging", "").c_str(), //set state_topic,name,uniqueId
will_Topic, "{{ value_json.m5ischarging }}", "", //set availability_topic,device_class,value_template,
"", "", "%", //set,payload_on,payload_off,unit_of_meas,
0, //set off_delay
Gateway_AnnouncementMsg, will_Message, true, "", //set,payload_available,payload_not available ,is a child device, command topic
"", "", "", "", false, // device name, device manufacturer, device model, device ID, retain
stateClassNone //State Class
);
createDiscovery("binary_sensor", //set Type
subjectSYStoMQTT, "SYS: Is Charge Full", (char*)getUniqueId("m5ischargefull", "").c_str(), //set state_topic,name,uniqueId
will_Topic, "{{ value_json.m5ischargefull }}", "", //set availability_topic,device_class,value_template,
"", "", "%", //set,payload_on,payload_off,unit_of_meas,
0, //set off_delay
Gateway_AnnouncementMsg, will_Message, true, "", //set,payload_available,payload_not available ,is a child device, command topic
"", "", "", "", false, // device name, device manufacturer, device model, device ID, retain
stateClassNone //State Class
);
# endif
# endif
createDiscovery("button", //set Type
will_Topic, "SYS: Restart gateway", (char*)getUniqueId("restart", "").c_str(), //set state_topic,name,uniqueId
will_Topic, "restart", "", //set availability_topic,device_class,value_template,
"{\"cmd\":\"restart\"}", "", "", //set,payload_on,payload_off,unit_of_meas,
0, //set off_delay
Gateway_AnnouncementMsg, will_Message, true, subjectMQTTtoSYSset, //set,payload_available,payload_not available ,is a gateway entity, command topic
"", "", "", "", false, // device name, device manufacturer, device model, device ID, retain
stateClassNone //State Class
);
createDiscovery("button", //set Type
will_Topic, "SYS: Erase credentials", (char*)getUniqueId("erase", "").c_str(), //set state_topic,name,uniqueId
will_Topic, "", "", //set availability_topic,device_class,value_template,
"{\"cmd\":\"erase\"}", "", "", //set,payload_on,payload_off,unit_of_meas,
0, //set off_delay
Gateway_AnnouncementMsg, will_Message, true, subjectMQTTtoSYSset, //set,payload_available,payload_not available ,is a gateway entity, command topic
"", "", "", "", false, // device name, device manufacturer, device model, device ID, retain
stateClassNone //State Class
);
# ifdef MQTT_HTTPS_FW_UPDATE
createDiscovery("update", //set Type
subjectRLStoMQTT, "SYS: Firmware Update", (char*)getUniqueId("update", "").c_str(), //set state_topic,name,uniqueId
will_Topic, "firmware", "", //set availability_topic,device_class,value_template,
LATEST_OR_DEV, "", "", //set,payload_on,payload_off,unit_of_meas,
0, //set off_delay
Gateway_AnnouncementMsg, will_Message, true, subjectMQTTtoSYSupdate, //set,payload_available,payload_not available ,is a gateway entity, command topic
"", "", "", "", false, // device name, device manufacturer, device model, device ID, retain
stateClassNone //State Class
);
# endif
# ifdef ZsensorBME280
# define BMEparametersCount 5
Log.trace(F("bme280Discovery" CR));
char* BMEsensor[BMEparametersCount][8] = {
{"sensor", "temp", "bme", "temperature", jsonTempc, "", "", "°C"},
{"sensor", "pa", "bme", "pressure", jsonPa, "", "", "hPa"},
{"sensor", "hum", "bme", "humidity", jsonHum, "", "", "%"},
{"sensor", "altim", "bme", "", jsonAltim, "", "", "m"},
{"sensor", "altift", "bme", "", jsonAltif, "", "", "ft"}
//component type,name,availability topic,device class,value template,payload on, payload off, unit of measurement
};
for (int i = 0; i < BMEparametersCount; i++) {
createDiscovery(BMEsensor[i][0],
BMETOPIC, BMEsensor[i][1], (char*)getUniqueId(BMEsensor[i][1], BMEsensor[i][2]).c_str(),
will_Topic, BMEsensor[i][3], BMEsensor[i][4],
BMEsensor[i][5], BMEsensor[i][6], BMEsensor[i][7],
0, Gateway_AnnouncementMsg, will_Message, true, "",
"", "", "", "", false, // device name, device manufacturer, device model, device ID, retain
stateClassNone //State Class
);
}
# endif
# ifdef ZsensorHTU21
# define HTUparametersCount 2
Log.trace(F("htu21Discovery" CR));
char* HTUsensor[HTUparametersCount][8] = {
{"sensor", "temp", "htu", "temperature", jsonTempc, "", "", "°C"},
{"sensor", "hum", "htu", "humidity", jsonHum, "", "", "%"}
//component type,name,availability topic,device class,value template,payload on, payload off, unit of measurement
};
for (int i = 0; i < HTUparametersCount; i++) {
//trc(HTUsensor[i][1]);
createDiscovery(HTUsensor[i][0],
HTUTOPIC, HTUsensor[i][1], (char*)getUniqueId(HTUsensor[i][1], HTUsensor[i][2]).c_str(),
will_Topic, HTUsensor[i][3], HTUsensor[i][4],
HTUsensor[i][5], HTUsensor[i][6], HTUsensor[i][7],
0, Gateway_AnnouncementMsg, will_Message, true, "",
"", "", "", "", false, // device name, device manufacturer, device model, device ID, retain
stateClassMeasurement //State Class
);
}
# endif
# ifdef ZsensorLM75
Log.trace(F("LM75Discovery" CR));
char* LM75sensor[8] = {"sensor", "temp", "htu", "temperature", jsonTempc, "", "", "°C"};
//component type,name,availability topic,device class,value template,payload on, payload off, unit of measurement
createDiscovery(LM75sensor[0],
LM75TOPIC, LM75sensor[1], (char*)getUniqueId(LM75sensor[1], LM75sensor[2]).c_str(),
will_Topic, LM75sensor[3], LM75sensor[4],
LM75sensor[5], LM75sensor[6], LM75sensor[7],
0, Gateway_AnnouncementMsg, will_Message, true, "",
"", "", "", "", false, // device name, device manufacturer, device model, device ID, retain
stateClassMeasurement //State Class
);
# endif
# ifdef ZsensorAHTx0
# define AHTparametersCount 2
Log.trace(F("AHTx0Discovery" CR));
char* AHTsensor[AHTparametersCount][8] = {
{"sensor", "temp", "aht", "temperature", jsonTempc, "", "", "°C"},
{"sensor", "hum", "aht", "humidity", jsonHum, "", "", "%"}
//component type,name,availability topic,device class,value template,payload on, payload off, unit of measurement
};
for (int i = 0; i < AHTparametersCount; i++) {
createDiscovery(AHTsensor[i][0],
AHTTOPIC, AHTsensor[i][1], (char*)getUniqueId(AHTsensor[i][1], AHTsensor[i][2]).c_str(),
will_Topic, AHTsensor[i][3], AHTsensor[i][4],
AHTsensor[i][5], AHTsensor[i][6], AHTsensor[i][7],
0, Gateway_AnnouncementMsg, will_Message, true, "",
"", "", "", "", false, // device name, device manufacturer, device model, device ID, retain
stateClassMeasurement //State Class
);
}
# endif
# ifdef ZsensorDHT
# define DHTparametersCount 2
Log.trace(F("DHTDiscovery" CR));
char* DHTsensor[DHTparametersCount][8] = {
{"sensor", "temp", "dht", "temperature", jsonTempc, "", "", "°C"},
{"sensor", "hum", "dht", "humidity", jsonHum, "", "", "%"}
//component type,name,availability topic,device class,value template,payload on, payload off, unit of measurement
};
for (int i = 0; i < DHTparametersCount; i++) {
//trc(DHTsensor[i][1]);
createDiscovery(DHTsensor[i][0],
DHTTOPIC, DHTsensor[i][1], (char*)getUniqueId(DHTsensor[i][1], DHTsensor[i][2]).c_str(),
will_Topic, DHTsensor[i][3], DHTsensor[i][4],
DHTsensor[i][5], DHTsensor[i][6], DHTsensor[i][7],
0, Gateway_AnnouncementMsg, will_Message, true, "",
"", "", "", "", false, // device name, device manufacturer, device model, device ID, retain
stateClassMeasurement //State Class
);
}
# endif
# ifdef ZsensorADC
Log.trace(F("ADCDiscovery" CR));
char* ADCsensor[8] = {"sensor", "adc", "", "", jsonAdc, "", "", ""};
//component type,name,availability topic,device class,value template,payload on, payload off, unit of measurement
//trc(ADCsensor[1]);
createDiscovery(ADCsensor[0],
ADCTOPIC, ADCsensor[1], (char*)getUniqueId(ADCsensor[1], ADCsensor[2]).c_str(),
will_Topic, ADCsensor[3], ADCsensor[4],
ADCsensor[5], ADCsensor[6], ADCsensor[7],
0, Gateway_AnnouncementMsg, will_Message, true, "",
"", "", "", "", false, // device name, device manufacturer, device model, device ID, retain
stateClassNone //State Class
);
# endif
# ifdef ZsensorBH1750
# define BH1750parametersCount 3
Log.trace(F("BH1750Discovery" CR));
char* BH1750sensor[BH1750parametersCount][8] = {
{"sensor", "lux", "BH1750", "illuminance", jsonLux, "", "", "lx"},
{"sensor", "ftCd", "BH1750", "irradiance", jsonFtcd, "", "", ""},
{"sensor", "wattsm2", "BH1750", "irradiance", jsonWm2, "", "", "wm²"}
//component type,name,availability topic,device class,value template,payload on, payload off, unit of measurement
};
for (int i = 0; i < BH1750parametersCount; i++) {
//trc(BH1750sensor[i][1]);
createDiscovery(BH1750sensor[i][0],
subjectBH1750toMQTT, BH1750sensor[i][1], (char*)getUniqueId(BH1750sensor[i][1], BH1750sensor[i][2]).c_str(),
will_Topic, BH1750sensor[i][3], BH1750sensor[i][4],
BH1750sensor[i][5], BH1750sensor[i][6], BH1750sensor[i][7],
0, Gateway_AnnouncementMsg, will_Message, true, "",
"", "", "", "", false, // device name, device manufacturer, device model, device ID, retain
stateClassMeasurement //State Class
);
}
# endif
# ifdef ZsensorMQ2
# define MQ2parametersCount 2
Log.trace(F("MQ2Discovery" CR));
char* MQ2sensor[MQ2parametersCount][8] = {
{"sensor", "gas", "MQ2", "gas", jsonVal, "", "", "ppm"},
{"binary_sensor", "MQ2", "", "gas", jsonPresence, "true", "false", ""}
//component type,name,availability topic,device class,value template,payload on, payload off, unit of measurement
};
for (int i = 0; i < MQ2parametersCount; i++) {
createDiscovery(MQ2sensor[i][0],
subjectMQ2toMQTT, MQ2sensor[i][1], (char*)getUniqueId(MQ2sensor[i][1], MQ2sensor[i][2]).c_str(),
will_Topic, MQ2sensor[i][3], MQ2sensor[i][4],
MQ2sensor[i][5], MQ2sensor[i][6], MQ2sensor[i][7],
0, Gateway_AnnouncementMsg, will_Message, true, "",
"", "", "", "", false, // device name, device manufacturer, device model, device ID, retain
stateClassNone //State Class
);
}
# endif
# ifdef ZsensorTEMT6000
# define TEMT6000parametersCount 3
Log.trace(F("TEMT6000Discovery" CR));
char* TEMT6000sensor[TEMT6000parametersCount][8] = {
{"sensor", "lux", "TEMT6000", "illuminance", jsonLux, "", "", "lx"},
{"sensor", "ftcd", "TEMT6000", "irradiance", jsonFtcd, "", "", ""},
{"sensor", "wattsm2", "TEMT6000", "irradiance", jsonWm2, "", "", "wm²"}
//component type,name,availability topic,device class,value template,payload on, payload off, unit of measurement
};
for (int i = 0; i < TEMT6000parametersCount; i++) {
//trc(TEMT6000sensor[i][1]);
createDiscovery(TEMT6000sensor[i][0],
subjectTEMT6000toMQTT, TEMT6000sensor[i][1], (char*)getUniqueId(TEMT6000sensor[i][1], TEMT6000sensor[i][2]).c_str(),
will_Topic, TEMT6000sensor[i][3], TEMT6000sensor[i][4],
TEMT6000sensor[i][5], TEMT6000sensor[i][6], TEMT6000sensor[i][7],
0, Gateway_AnnouncementMsg, will_Message, true, "",
"", "", "", "", false, // device name, device manufacturer, device model, device ID, retain
stateClassMeasurement //State Class
);
}
# endif
# ifdef ZsensorTSL2561
# define TSL2561parametersCount 3
Log.trace(F("TSL2561Discovery" CR));
char* TSL2561sensor[TSL2561parametersCount][8] = {
{"sensor", "lux", "TSL2561", "illuminance", jsonLux, "", "", "lx"},
{"sensor", "ftcd", "TSL2561", "irradiance", jsonFtcd, "", "", ""},
{"sensor", "wattsm2", "TSL2561", "irradiance", jsonWm2, "", "", "wm²"}
//component type,name,availability topic,device class,value template,payload on, payload off, unit of measurement
};
for (int i = 0; i < TSL2561parametersCount; i++) {
//trc(TSL2561sensor[i][1]);
createDiscovery(TSL2561sensor[i][0],
subjectTSL12561toMQTT, TSL2561sensor[i][1], (char*)getUniqueId(TSL2561sensor[i][1], TSL2561sensor[i][2]).c_str(),
will_Topic, TSL2561sensor[i][3], TSL2561sensor[i][4],
TSL2561sensor[i][5], TSL2561sensor[i][6], TSL2561sensor[i][7],
0, Gateway_AnnouncementMsg, will_Message, true, "",
"", "", "", "", false, // device name, device manufacturer, device model, device ID, retain
stateClassMeasurement //State Class
);
}
# endif
# ifdef ZsensorHCSR501
Log.trace(F("HCSR501Discovery" CR));
char* HCSR501sensor[8] = {"binary_sensor", "hcsr501", "", "motion", jsonPresence, "true", "false", ""};
//component type,name,availability topic,device class,value template,payload on, payload off, unit of measurement
//trc(HCSR501sensor[1]);
createDiscovery(HCSR501sensor[0],
subjectHCSR501toMQTT, HCSR501sensor[1], (char*)getUniqueId(HCSR501sensor[1], HCSR501sensor[2]).c_str(),
will_Topic, HCSR501sensor[3], HCSR501sensor[4],
HCSR501sensor[5], HCSR501sensor[6], HCSR501sensor[7],
0, Gateway_AnnouncementMsg, will_Message, true, "",
"", "", "", "", false, // device name, device manufacturer, device model, device ID, retain
stateClassNone //State Class
);
# endif
# ifdef ZsensorGPIOInput
Log.trace(F("GPIOInputDiscovery" CR));
char* GPIOInputsensor[8] = {"binary_sensor", "GPIOInput", "", "", jsonGpio, INPUT_GPIO_ON_VALUE, INPUT_GPIO_OFF_VALUE, ""};
//component type,name,availability topic,device class,value template,payload on, payload off, unit of measurement
//trc(GPIOInputsensor[1]);
createDiscovery(GPIOInputsensor[0],
subjectGPIOInputtoMQTT, GPIOInputsensor[1], (char*)getUniqueId(GPIOInputsensor[1], GPIOInputsensor[2]).c_str(),
will_Topic, GPIOInputsensor[3], GPIOInputsensor[4],
GPIOInputsensor[5], GPIOInputsensor[6], GPIOInputsensor[7],
0, Gateway_AnnouncementMsg, will_Message, true, "",
"", "", "", "", false, // device name, device manufacturer, device model, device ID, retain
stateClassNone //State Class
);
# endif
# ifdef ZsensorINA226
# define INA226parametersCount 3
Log.trace(F("INA226Discovery" CR));
char* INA226sensor[INA226parametersCount][8] = {
{"sensor", "volt", "INA226", "voltage", jsonVolt, "", "", "V"},
{"sensor", "current", "INA226", "current", jsonCurrent, "", "", "A"},
{"sensor", "power", "INA226", "power", jsonPower, "", "", "W"}
//component type,name,availability topic,device class,value template,payload on, payload off, unit of measurement
};
for (int i = 0; i < INA226parametersCount; i++) {
//trc(INA226sensor[i][1]);
createDiscovery(INA226sensor[i][0],
subjectINA226toMQTT, INA226sensor[i][1], (char*)getUniqueId(INA226sensor[i][1], INA226sensor[i][2]).c_str(),
will_Topic, INA226sensor[i][3], INA226sensor[i][4],
INA226sensor[i][5], INA226sensor[i][6], INA226sensor[i][7],
0, Gateway_AnnouncementMsg, will_Message, true, "",
"", "", "", "", false, // device name, device manufacturer, device model, device ID, retain
stateClassMeasurement //State Class
);
}
# endif
# ifdef ZsensorDS1820
// Publish any DS1820 sensors found on the OneWire bus
pubOneWire_HADiscovery();
# endif
# ifdef ZactuatorONOFF
Log.trace(F("actuatorONOFFDiscovery" CR));
char* actuatorONOFF[8] = {"switch", "actuatorONOFF", "", "", "{{ value_json.cmd }}", "{\"cmd\":1}", "{\"cmd\":0}", ""};
//component type,name,availability topic,device class,value template,payload on, payload off, unit of measurement
//trc(actuatorONOFF[1]);
createDiscovery(actuatorONOFF[0],
subjectGTWONOFFtoMQTT, actuatorONOFF[1], (char*)getUniqueId(actuatorONOFF[1], actuatorONOFF[2]).c_str(),
will_Topic, actuatorONOFF[3], actuatorONOFF[4],
actuatorONOFF[5], actuatorONOFF[6], actuatorONOFF[7],
0, Gateway_AnnouncementMsg, will_Message, true, subjectMQTTtoONOFF,
"", "", "", "", false, // device name, device manufacturer, device model, device ID, retain
stateClassNone, //State Class
"0", "1" //state_off, state_on
);
# endif
# ifdef ZsensorRN8209
# define RN8209parametersCount 4
Log.trace(F("RN8209Discovery" CR));
char* RN8209sensor[RN8209parametersCount][8] = {
{"sensor", "volt", "RN8209", "voltage", jsonVolt, "", "", "V"},