HASS gateway Discovery improvements (#792)
* MQTT discovery improvements -remove gatewayBT -remove device class formaldehyde (not existing in HASS) -add SYStoMQTT new parameters -attach connectivity parameter to the device -add BT gateway infos and switches -refactor modules storage and publication
This commit is contained in:
1 parent
cabc8695eb
commit
9a66c9ef09
7 files changed
+136
-104
No files matched your search
+1
-1
@@ -230,7 +230,7 @@ void FormalDiscovery(char* mac) {
|
||||
{"sensor", "Formal-batt", mac, "battery", jsonBatt, "", "", "%"},
|
||||
{"sensor", "Formal-temp", mac, "temperature", jsonTempc, "", "", "°C"},
|
||||
{"sensor", "Formal-hum", mac, "humidity", jsonHum, "", "", "%"},
|
||||
{"sensor", "Formal-for", mac, "formaldehyde", jsonFor, "", "", "%"}
|
||||
{"sensor", "Formal-for", mac, "", jsonFor, "", "", "%"}
|
||||
//component type,name,availability topic,device class,value template,payload on, payload off, unit of measurement
|
||||
};
|
||||
|
||||
|
||||
+78
-16
@@ -114,7 +114,11 @@ void createDiscovery(char* sensor_type,
|
||||
if (child_device) {
|
||||
StaticJsonBuffer<JSON_MSG_BUFFER> jsonDeviceBuffer;
|
||||
JsonObject& device = jsonDeviceBuffer.createObject();
|
||||
char JSONmessageBuffer[JSON_MSG_BUFFER];
|
||||
modules.printTo(JSONmessageBuffer, sizeof(JSONmessageBuffer));
|
||||
Log.notice(F("Received json : %s" CR), JSONmessageBuffer);
|
||||
device.set("name", gateway_name);
|
||||
device.set("model", JSONmessageBuffer);
|
||||
device.set("manufacturer", DEVICEMANUFACTURER);
|
||||
device.set("sw_version", OMG_VERSION);
|
||||
JsonArray& identifiers = device.createNestedArray("identifiers");
|
||||
@@ -128,21 +132,63 @@ void createDiscovery(char* sensor_type,
|
||||
void pubMqttDiscovery() {
|
||||
Log.trace(F("omgStatusDiscovery" CR));
|
||||
createDiscovery("binary_sensor", //set Type
|
||||
will_Topic, Gateway_Name, (char*)getUniqueId("", "").c_str(), //set state_topic,name,uniqueId
|
||||
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, false, "" //set,payload_avalaible,payload_not avalaible ,is a child device, command topic
|
||||
Gateway_AnnouncementMsg, will_Message, true, "" //set,payload_avalaible,payload_not avalaible ,is a child device, command topic
|
||||
);
|
||||
createDiscovery("sensor", //set Type
|
||||
subjectSYStoMQTT, "SYS: Uptime", (char*)getUniqueId("uptime", "").c_str(), //set state_topic,name,uniqueId
|
||||
"", "", "{{ value_json.uptime }}", //set availability_topic,device_class,value_template,
|
||||
"", "", "s", //set,payload_on,payload_off,unit_of_meas,
|
||||
0, //set off_delay
|
||||
"", "", true, "" //set,payload_avalaible,payload_not avalaible ,is a child device, command topic
|
||||
);
|
||||
|
||||
# if defined(ESP8266) || defined(ESP32)
|
||||
createDiscovery("sensor", //set Type
|
||||
subjectSYStoMQTT, "SYS: Free memory", (char*)getUniqueId("freemem", "").c_str(), //set state_topic,name,uniqueId
|
||||
"", "", "{{ value_json.freemem }}", //set availability_topic,device_class,value_template,
|
||||
"", "", "B", //set,payload_on,payload_off,unit_of_meas,
|
||||
0, //set off_delay
|
||||
"", "", true, "" //set,payload_avalaible,payload_not avalaible ,is a child device, command topic
|
||||
);
|
||||
createDiscovery("sensor", //set Type
|
||||
subjectSYStoMQTT, "SYS: IP", (char*)getUniqueId("ip", "").c_str(), //set state_topic,name,uniqueId
|
||||
"", "", "{{ value_json.ip }}", //set availability_topic,device_class,value_template,
|
||||
"", "", "", //set,payload_on,payload_off,unit_of_meas,
|
||||
0, //set off_delay
|
||||
"", "", true, "" //set,payload_avalaible,payload_not avalaible ,is a child device, command topic
|
||||
);
|
||||
# ifndef ESP32_ETHERNET
|
||||
createDiscovery("sensor", //set Type
|
||||
subjectSYStoMQTT, "SYS: Rssi", (char*)getUniqueId("rssi", "").c_str(), //set state_topic,name,uniqueId
|
||||
"", "", "{{ value_json.rssi }}", //set availability_topic,device_class,value_template,
|
||||
"", "", "dB", //set,payload_on,payload_off,unit_of_meas,
|
||||
0, //set off_delay
|
||||
"", "", true, "" //set,payload_avalaible,payload_not avalaible ,is a child device, command topic
|
||||
);
|
||||
# endif
|
||||
# endif
|
||||
# ifdef ESP32
|
||||
createDiscovery("sensor", //set Type
|
||||
subjectSYStoMQTT, "SYS: Low Power Mode", (char*)getUniqueId("lowpowermode", "").c_str(), //set state_topic,name,uniqueId
|
||||
"", "", "{{ value_json.lowpowermode }}", //set availability_topic,device_class,value_template,
|
||||
"", "", "", //set,payload_on,payload_off,unit_of_meas,
|
||||
0, //set off_delay
|
||||
"", "", true, "" //set,payload_avalaible,payload_not avalaible ,is a child device, command topic
|
||||
);
|
||||
# endif
|
||||
createDiscovery("switch", //set Type
|
||||
will_Topic, "restart OMG", (char*)getUniqueId("restart", "").c_str(), //set state_topic,name,uniqueId
|
||||
will_Topic, "SYS: Restart gateway", (char*)getUniqueId("restart", "").c_str(), //set state_topic,name,uniqueId
|
||||
will_Topic, "", "", //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_avalaible,payload_not avalaible ,is a child device, command topic
|
||||
);
|
||||
createDiscovery("switch", //set Type
|
||||
will_Topic, "erase OMG", (char*)getUniqueId("erase", "").c_str(), //set state_topic,name,uniqueId
|
||||
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
|
||||
@@ -476,18 +522,34 @@ void pubMqttDiscovery() {
|
||||
# endif
|
||||
|
||||
# ifdef ZgatewayBT
|
||||
// Sensor to display BT received value
|
||||
Log.trace(F("gatewayBTDiscovery" CR));
|
||||
char* gatewayBT[8] = {"sensor", "gatewayBT", "", "", jsonId, "", "", ""};
|
||||
//component type,name,availability topic,device class,value template,payload on, payload off, unit of measurement
|
||||
|
||||
Log.trace(F("CreateDiscoverySensor" CR));
|
||||
//trc(gatewayBT[1]);
|
||||
createDiscovery(gatewayBT[0],
|
||||
subjectBTtoMQTT, gatewayBT[1], (char*)getUniqueId(gatewayBT[1], gatewayBT[2]).c_str(),
|
||||
will_Topic, gatewayBT[3], gatewayBT[4],
|
||||
gatewayBT[5], gatewayBT[6], gatewayBT[7],
|
||||
0, "", "", true, "");
|
||||
createDiscovery("sensor", //set Type
|
||||
subjectSYStoMQTT, "BT: Interval between scans", (char*)getUniqueId("interval", "").c_str(), //set state_topic,name,uniqueId
|
||||
"", "", "{{ value_json.interval }}", //set availability_topic,device_class,value_template,
|
||||
"", "", "ms", //set,payload_on,payload_off,unit_of_meas,
|
||||
0, //set off_delay
|
||||
"", "", true, "" //set,payload_avalaible,payload_not avalaible ,is a child device, command topic
|
||||
);
|
||||
createDiscovery("sensor", //set Type
|
||||
subjectSYStoMQTT, "BT: Connnect every X scan(s)", (char*)getUniqueId("scanbcnct", "").c_str(), //set state_topic,name,uniqueId
|
||||
"", "", "{{ value_json.scanbcnct }}", //set availability_topic,device_class,value_template,
|
||||
"", "", "", //set,payload_on,payload_off,unit_of_meas,
|
||||
0, //set off_delay
|
||||
"", "", true, "" //set,payload_avalaible,payload_not avalaible ,is a child device, command topic
|
||||
);
|
||||
createDiscovery("switch", //set Type
|
||||
will_Topic, "BT: Force scan", (char*)getUniqueId("force_scan", "").c_str(), //set state_topic,name,uniqueId
|
||||
will_Topic, "", "", //set availability_topic,device_class,value_template,
|
||||
"{\"interval\":0}", "", "", //set,payload_on,payload_off,unit_of_meas,
|
||||
0, //set off_delay
|
||||
Gateway_AnnouncementMsg, will_Message, true, subjectMQTTtoBTset //set,payload_avalaible,payload_not avalaible ,is a child device, command topic
|
||||
);
|
||||
createDiscovery("switch", //set Type
|
||||
"", "BT: Publish only sensors", (char*)getUniqueId("only_sensors", "").c_str(), //set state_topic,name,uniqueId
|
||||
"", "", "", //set availability_topic,device_class,value_template,
|
||||
"{\"onlysensors\":true}", "{\"onlysensors\":false}", "", //set,payload_on,payload_off,unit_of_meas,
|
||||
0, //set off_delay
|
||||
Gateway_AnnouncementMsg, will_Message, true, subjectMQTTtoBTset //set,payload_avalaible,payload_not avalaible ,is a child device, command topic
|
||||
);
|
||||
# endif
|
||||
}
|
||||
|
||||
|
||||
+34
-84
@@ -48,10 +48,14 @@ ReceivedSignal receivedSignal[struct_size] = {{0, 0}, {0, 0}, {0, 0}, {0, 0}};
|
||||
unsigned long timer_sys_measures = 0;
|
||||
# define ARDUINOJSON_USE_LONG_LONG 1
|
||||
#endif
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
#include <ArduinoLog.h>
|
||||
#include <PubSubClient.h>
|
||||
|
||||
StaticJsonBuffer<JSON_MSG_BUFFER> modulesBuffer;
|
||||
JsonArray& modules = modulesBuffer.createArray();
|
||||
|
||||
// Modules config inclusion
|
||||
#if defined(ZgatewayRF) || defined(ZgatewayRF2) || defined(ZgatewayPilight)
|
||||
# include "config_RF.h"
|
||||
@@ -592,81 +596,110 @@ void setup() {
|
||||
|
||||
#ifdef ZsensorBME280
|
||||
setupZsensorBME280();
|
||||
modules.add(ZsensorBME280);
|
||||
#endif
|
||||
#ifdef ZsensorHTU21
|
||||
setupZsensorHTU21();
|
||||
modules.add(ZsensorHTU21);
|
||||
#endif
|
||||
#ifdef ZsensorAHTx0
|
||||
setupZsensorAHTx0();
|
||||
modules.add(ZsensorAHTx0);
|
||||
#endif
|
||||
#ifdef ZsensorBH1750
|
||||
setupZsensorBH1750();
|
||||
modules.add(ZsensorBH1750);
|
||||
#endif
|
||||
#ifdef ZsensorTSL2561
|
||||
setupZsensorTSL2561();
|
||||
modules.add(ZsensorTSL2561);
|
||||
#endif
|
||||
#ifdef Zgateway2G
|
||||
setup2G();
|
||||
modules.add(Zgateway2G);
|
||||
#endif
|
||||
#ifdef ZgatewayIR
|
||||
setupIR();
|
||||
modules.add(ZgatewayIR);
|
||||
#endif
|
||||
#ifdef ZgatewayLORA
|
||||
setupLORA();
|
||||
modules.add(ZgatewayLORA);
|
||||
#endif
|
||||
#ifdef ZgatewayRF
|
||||
setupRF();
|
||||
modules.add(ZgatewayRF);
|
||||
#endif
|
||||
#ifdef ZgatewayRF2
|
||||
setupRF2();
|
||||
modules.add(ZgatewayRF2);
|
||||
#endif
|
||||
#ifdef ZgatewayPilight
|
||||
setupPilight();
|
||||
modules.add(ZgatewayPilight);
|
||||
#endif
|
||||
#ifdef ZgatewayWeatherStation
|
||||
setupWeatherStation();
|
||||
modules.add(ZgatewayWeatherStation);
|
||||
#endif
|
||||
#ifdef ZgatewaySRFB
|
||||
setupSRFB();
|
||||
modules.add(ZgatewaySRFB);
|
||||
#endif
|
||||
#ifdef ZgatewayBT
|
||||
setupBT();
|
||||
modules.add(ZgatewayBT);
|
||||
#endif
|
||||
#ifdef ZgatewayRFM69
|
||||
setupRFM69();
|
||||
modules.add(ZgatewayRFM69);
|
||||
#endif
|
||||
#ifdef ZsensorINA226
|
||||
setupINA226();
|
||||
modules.add(ZsensorINA226);
|
||||
#endif
|
||||
#ifdef ZsensorHCSR501
|
||||
setupHCSR501();
|
||||
modules.add(ZsensorHCSR501);
|
||||
#endif
|
||||
#ifdef ZsensorHCSR04
|
||||
setupHCSR04();
|
||||
modules.add(ZsensorHCSR04);
|
||||
#endif
|
||||
#ifdef ZsensorGPIOInput
|
||||
setupGPIOInput();
|
||||
modules.add(ZsensorGPIOInput);
|
||||
#endif
|
||||
#ifdef ZsensorGPIOKeyCode
|
||||
setupGPIOKeyCode();
|
||||
modules.add(ZsensorGPIOKeyCode);
|
||||
#endif
|
||||
#ifdef ZactuatorFASTLED
|
||||
setupFASTLED();
|
||||
modules.add(ZactuatorFASTLED);
|
||||
#endif
|
||||
#ifdef ZactuatorPWM
|
||||
setupPWM();
|
||||
modules.add(ZactuatorPWM);
|
||||
#endif
|
||||
#ifdef ZsensorDS1820
|
||||
setupZsensorDS1820();
|
||||
modules.add(ZsensorDS1820);
|
||||
#endif
|
||||
#ifdef ZsensorADC
|
||||
setupADC();
|
||||
modules.add(ZsensorADC);
|
||||
#endif
|
||||
#ifdef ZsensorDHT
|
||||
setupDHT();
|
||||
modules.add(ZsensorDHT);
|
||||
#endif
|
||||
#ifdef ZgatewayRS232
|
||||
setupRS232();
|
||||
modules.add(ZgatewayRS232);
|
||||
#endif
|
||||
#ifdef ZmqttDiscovery
|
||||
modules.add(ZmqttDiscovery);
|
||||
#endif
|
||||
Log.trace(F("mqtt_max_packet_size: %d" CR), mqtt_max_packet_size);
|
||||
Log.notice(F("Setup OpenMQTTGateway end" CR));
|
||||
@@ -1337,94 +1370,14 @@ void stateMeasures() {
|
||||
SYSdata["mac"] = (char*)mac.c_str();
|
||||
SYSdata["wifiprt"] = (int)wifiProtocol;
|
||||
# endif
|
||||
# endif
|
||||
String modules = "";
|
||||
# ifdef ZgatewayRF
|
||||
modules = modules + ZgatewayRF;
|
||||
# endif
|
||||
# ifdef ZsensorBME280
|
||||
modules = modules + ZsensorBME280;
|
||||
# endif
|
||||
# ifdef ZsensorHTU21
|
||||
modules = modules + ZsensorHTU21;
|
||||
# endif
|
||||
# ifdef ZsensorAHTx0
|
||||
modules = modules + ZsensorAHTx0;
|
||||
# endif
|
||||
# ifdef ZsensorHCSR04
|
||||
modules = modules + ZsensorHCSR04;
|
||||
# endif
|
||||
# ifdef ZsensorBH1750
|
||||
modules = modules + ZsensorBH1750;
|
||||
# endif
|
||||
# ifdef ZsensorTSL2561
|
||||
modules = modules + ZsensorTSL2561;
|
||||
# endif
|
||||
# ifdef ZsensorDHT
|
||||
modules = modules + ZsensorDHT;
|
||||
# endif
|
||||
# ifdef ZsensorDS1820
|
||||
modules = modules + ZsensorDS1820;
|
||||
# endif
|
||||
# ifdef ZactuatorONOFF
|
||||
modules = modules + ZactuatorONOFF;
|
||||
# endif
|
||||
# ifdef Zgateway2G
|
||||
modules = modules + Zgateway2G;
|
||||
# endif
|
||||
# ifdef ZgatewayIR
|
||||
modules = modules + ZgatewayIR;
|
||||
# endif
|
||||
# ifdef ZgatewayLORA
|
||||
modules = modules + ZgatewayLORA;
|
||||
# endif
|
||||
# ifdef ZgatewayRF2
|
||||
modules = modules + ZgatewayRF2;
|
||||
# endif
|
||||
# ifdef ZgatewayWeatherStation
|
||||
modules = modules + ZgatewayWeatherStation;
|
||||
# endif
|
||||
# ifdef ZgatewayPilight
|
||||
modules = modules + ZgatewayPilight;
|
||||
# endif
|
||||
# ifdef ZgatewaySRFB
|
||||
modules = modules + ZgatewaySRFB;
|
||||
# endif
|
||||
# ifdef ZgatewayBT
|
||||
modules = modules + ZgatewayBT;
|
||||
# ifdef ESP32
|
||||
SYSdata["lowpowermode"] = (int)low_power_mode;
|
||||
# endif
|
||||
SYSdata["interval"] = BLEinterval;
|
||||
SYSdata["scanbcnct"] = BLEscanBeforeConnect;
|
||||
# endif
|
||||
# ifdef ZgatewayRFM69
|
||||
modules = modules + ZgatewayRFM69;
|
||||
# endif
|
||||
# ifdef ZsensorINA226
|
||||
modules = modules + ZsensorINA226;
|
||||
# endif
|
||||
# ifdef ZsensorHCSR501
|
||||
modules = modules + ZsensorHCSR501;
|
||||
# endif
|
||||
# ifdef ZsensorGPIOInput
|
||||
modules = modules + ZsensorGPIOInput;
|
||||
# endif
|
||||
# ifdef ZsensorGPIOKeyCode
|
||||
modules = modules + ZsensorGPIOKeyCode;
|
||||
# endif
|
||||
# ifdef ZsensorGPIOKeyCode
|
||||
modules = modules + ZsensorGPIOKeyCode;
|
||||
# endif
|
||||
# ifdef ZmqttDiscovery
|
||||
modules = modules + ZmqttDiscovery;
|
||||
# endif
|
||||
# ifdef ZactuatorFASTLED
|
||||
modules = modules + ZactuatorFASTLED;
|
||||
# endif
|
||||
# ifdef ZactuatorPWM
|
||||
modules = modules + ZactuatorPWM;
|
||||
# endif
|
||||
# ifdef ZboardM5STACK
|
||||
M5.Power.begin();
|
||||
SYSdata["m5-batt-level"] = (int8_t)M5.Power.getBatteryLevel();
|
||||
@@ -1444,10 +1397,7 @@ void stateMeasures() {
|
||||
SYSdata["m5-bat-chargecurrent"] = (float)M5.Axp.GetBatChargeCurrent();
|
||||
SYSdata["m5-aps-voltage"] = (float)M5.Axp.GetAPSVoltage();
|
||||
# endif
|
||||
# ifdef ZGatewayRS232
|
||||
modules = modules + ZGatewayRS232;
|
||||
# endif
|
||||
SYSdata["modules"] = modules;
|
||||
SYSdata.set("modules", modules);
|
||||
pub(subjectSYStoMQTT, SYSdata);
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in new issue
Block a user