[DISC] Removal of openHAB specific MQTT discovery patch (#2153)
Removal of openHAB specific MQTT discovery patch "ohdisc", as it is no longer required with openHAB 4.3 and later, and with openHAB before 4.3 MQTT discovery never was fully implemented anyway.
This commit is contained in:
1 parent
d837dfd32a
commit
4bf43f5695
7 files changed
-59
No files matched your search
@@ -76,13 +76,6 @@ Or use another upload method from the Upload section that requires credentials b
|
|||||||
|
|
||||||
You should see the gateway connected to your broker by checking with an MQTT client like MQTT Explorer.
|
You should see the gateway connected to your broker by checking with an MQTT client like MQTT Explorer.
|
||||||
|
|
||||||
To make the auto discovery compatible with OpenHAB you have to send the following command with a retain flag.
|
|
||||||
|
|
||||||
`mosquitto_pub -t "home/OpenMQTTGateway/commands/MQTTtoSYS/config" -m '{"ohdisc":true}'`
|
|
||||||
|
|
||||||
You can also activate OpenHAB auto discovery by adding the gateway as a Thing, Model, and switching the button to ON. The name of the channel to add is "SYS: OpenHAB discovery".
|
|
||||||
Once activated restart OpenMQTTGateway.
|
|
||||||
|
|
||||||
## Adding the things
|
## Adding the things
|
||||||
1. From the Administration click on "Things" under "Settings", you should see a number in the INBOX button
|
1. From the Administration click on "Things" under "Settings", you should see a number in the INBOX button
|
||||||
|
|
||||||
|
|||||||
@@ -35,18 +35,6 @@ If you want the settings to be kept upon gateway restart, you can save the state
|
|||||||
Auto discovery is enabled by default on release binaries and platformio.
|
Auto discovery is enabled by default on release binaries and platformio.
|
||||||
:::
|
:::
|
||||||
|
|
||||||
## AutoDiscovery compatible with OpenHAB (default: false)
|
|
||||||
OpenHAB does not support the key `is_defined` in the json template, to remove it at runtime and make the auto discovery compatible you can use the following command with a retain flag.
|
|
||||||
|
|
||||||
`mosquitto_pub -t "home/OpenMQTTGateway/commands/MQTTtoSYS/config" -m '{"ohdisc":true}'`
|
|
||||||
|
|
||||||
If you want the settings to be kept upon gateway restart, you can save the state by adding `"save":true` (ESP32 only).
|
|
||||||
`mosquitto_pub -t "home/OpenMQTTGateway/commands/MQTTtoSYS/config" -m '{"ohdisc":true, "save":true}'`
|
|
||||||
|
|
||||||
::: tip
|
|
||||||
This command can also be used with other controllers that does not support the is_defined key.
|
|
||||||
:::
|
|
||||||
|
|
||||||
## Activate Offline mode
|
## Activate Offline mode
|
||||||
|
|
||||||
`mosquitto_pub -t "home/OpenMQTTGateway/commands/MQTTtoSYS/config" -m '{"offline":true,"save":true}'`
|
`mosquitto_pub -t "home/OpenMQTTGateway/commands/MQTTtoSYS/config" -m '{"offline":true,"save":true}'`
|
||||||
|
|||||||
@@ -670,7 +670,6 @@ struct SYSConfig_s {
|
|||||||
bool blufi; // if true the gateway will be accesible with blufi
|
bool blufi; // if true the gateway will be accesible with blufi
|
||||||
bool offline;
|
bool offline;
|
||||||
bool discovery; // HA discovery convention
|
bool discovery; // HA discovery convention
|
||||||
bool ohdiscovery; // OH discovery specificities
|
|
||||||
#ifdef LED_ADDRESSABLE
|
#ifdef LED_ADDRESSABLE
|
||||||
int rgbbrightness; // brightness of the RGB LED
|
int rgbbrightness; // brightness of the RGB LED
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -136,11 +136,7 @@ void launchRTL_433Discovery(bool overrideDiscovery) {
|
|||||||
idWoKey.remove(idWoKey.length() - (strlen(parameters[i][0]) + 1));
|
idWoKey.remove(idWoKey.length() - (strlen(parameters[i][0]) + 1));
|
||||||
DISCOVERY_TRACE_LOG(F("idWoKey %s" CR), idWoKey.c_str());
|
DISCOVERY_TRACE_LOG(F("idWoKey %s" CR), idWoKey.c_str());
|
||||||
String value_template = "";
|
String value_template = "";
|
||||||
if (SYSConfig.ohdiscovery) {
|
|
||||||
value_template = "{{ value_json." + String(parameters[i][0]) + " }}";
|
|
||||||
} else {
|
|
||||||
value_template = "{{ value_json." + String(parameters[i][0]) + " | is_defined }}";
|
value_template = "{{ value_json." + String(parameters[i][0]) + " | is_defined }}";
|
||||||
}
|
|
||||||
String topic = subjectRTL_433toMQTT;
|
String topic = subjectRTL_433toMQTT;
|
||||||
# if valueAsATopic
|
# if valueAsATopic
|
||||||
// Remove the key from the unique id to extract the device id
|
// Remove the key from the unique id to extract the device id
|
||||||
@@ -158,11 +154,7 @@ void launchRTL_433Discovery(bool overrideDiscovery) {
|
|||||||
# endif
|
# endif
|
||||||
if (strcmp(parameters[i][0], "battery_ok") == 0) {
|
if (strcmp(parameters[i][0], "battery_ok") == 0) {
|
||||||
if (strcmp(pdevice->modelName, "Govee-Water") == 0 || strcmp(pdevice->modelName, "Govee-Contact") == 0 || strcmp(pdevice->modelName, "Archos-TBH") == 0 || strcmp(pdevice->modelName, "FineOffset-WH31L") == 0 || strcmp(pdevice->modelName, "Fineoffset-WH45") == 0 || strcmp(pdevice->modelName, "Fineoffset-WN34") == 0 || strcmp(pdevice->modelName, "Fineoffset-WS80") == 0 || strcmp(pdevice->modelName, "Fineoffset-WH0290") == 0 || strcmp(pdevice->modelName, "Fineoffset-WH51") == 0 || strcmp(pdevice->modelName, "Kedsum-TH") == 0 || strcmp(pdevice->modelName, "AVE") == 0 || strcmp(pdevice->modelName, "TPMS") == 0) {
|
if (strcmp(pdevice->modelName, "Govee-Water") == 0 || strcmp(pdevice->modelName, "Govee-Contact") == 0 || strcmp(pdevice->modelName, "Archos-TBH") == 0 || strcmp(pdevice->modelName, "FineOffset-WH31L") == 0 || strcmp(pdevice->modelName, "Fineoffset-WH45") == 0 || strcmp(pdevice->modelName, "Fineoffset-WN34") == 0 || strcmp(pdevice->modelName, "Fineoffset-WS80") == 0 || strcmp(pdevice->modelName, "Fineoffset-WH0290") == 0 || strcmp(pdevice->modelName, "Fineoffset-WH51") == 0 || strcmp(pdevice->modelName, "Kedsum-TH") == 0 || strcmp(pdevice->modelName, "AVE") == 0 || strcmp(pdevice->modelName, "TPMS") == 0) {
|
||||||
if (SYSConfig.ohdiscovery) {
|
|
||||||
value_template = "{{ (value_json." + String(parameters[i][0]) + " * 100) | round(0)}}";
|
|
||||||
} else {
|
|
||||||
value_template = "{{ (float(value_json." + String(parameters[i][0]) + ") * 100) | round(0) | is_defined }}";
|
value_template = "{{ (float(value_json." + String(parameters[i][0]) + ") * 100) | round(0) | is_defined }}";
|
||||||
}
|
|
||||||
createDiscovery("sensor", //set Type
|
createDiscovery("sensor", //set Type
|
||||||
(char*)topic.c_str(), parameters[i][1], pdevice->uniqueId, //set state_topic,name,uniqueId
|
(char*)topic.c_str(), parameters[i][1], pdevice->uniqueId, //set state_topic,name,uniqueId
|
||||||
"", parameters[i][3], (char*)value_template.c_str(), //set availability_topic,device_class,value_template,
|
"", parameters[i][3], (char*)value_template.c_str(), //set availability_topic,device_class,value_template,
|
||||||
|
|||||||
@@ -303,9 +303,6 @@ void createDiscovery(const char* sensor_type,
|
|||||||
if (retainCmd)
|
if (retainCmd)
|
||||||
sensor["retain"] = retainCmd; // Retain command
|
sensor["retain"] = retainCmd; // Retain command
|
||||||
if (value_template && value_template[0]) {
|
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 && strcmp(state_class, "blind") == 0) {
|
if (strcmp(sensor_type, "cover") == 0 && strcmp(state_class, "blind") == 0) {
|
||||||
sensor["tilt_status_tpl"] = value_template; // tilt_status_template for blind
|
sensor["tilt_status_tpl"] = value_template; // tilt_status_template for blind
|
||||||
} else if (strcmp(sensor_type, "cover") == 0 && strcmp(state_class, "curtain") == 0) {
|
} else if (strcmp(sensor_type, "cover") == 0 && strcmp(state_class, "curtain") == 0) {
|
||||||
@@ -314,7 +311,6 @@ void createDiscovery(const char* sensor_type,
|
|||||||
sensor["val_tpl"] = value_template; //HA Auto discovery
|
sensor["val_tpl"] = value_template; //HA Auto discovery
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if (payload_on && payload_on[0]) {
|
if (payload_on && payload_on[0]) {
|
||||||
if (strcmp(sensor_type, "button") == 0) {
|
if (strcmp(sensor_type, "button") == 0) {
|
||||||
sensor["pl_prs"] = payload_on; // payload_press for a button press
|
sensor["pl_prs"] = payload_on; // payload_press for a button press
|
||||||
@@ -591,16 +587,6 @@ void pubMqttDiscovery() {
|
|||||||
stateClassNone, //State Class
|
stateClassNone, //State Class
|
||||||
"false", "true" //state_off, state_on
|
"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 LED_ADDRESSABLE
|
# ifdef LED_ADDRESSABLE
|
||||||
createDiscovery("number", //set Type
|
createDiscovery("number", //set Type
|
||||||
subjectSYStoMQTT, "SYS: LED Brightness", (char*)getUniqueId("rgbb", "").c_str(), //set state_topic,name,uniqueId
|
subjectSYStoMQTT, "SYS: LED Brightness", (char*)getUniqueId("rgbb", "").c_str(), //set state_topic,name,uniqueId
|
||||||
@@ -1342,7 +1328,6 @@ void pubMqttDiscovery() {
|
|||||||
{"switch", "force_scan"}, // Now a button
|
{"switch", "force_scan"}, // Now a button
|
||||||
{"sensor", "interval"}, // Now a number
|
{"sensor", "interval"}, // Now a number
|
||||||
{"sensor", "scanbcnct"}, // Now a number
|
{"sensor", "scanbcnct"}, // Now a number
|
||||||
{"switch", "ohdiscovery"}, // Now a new key
|
|
||||||
{"switch", "discovery"}}; // Now a new key
|
{"switch", "discovery"}}; // Now a new key
|
||||||
|
|
||||||
for (int i = 0; i < EntitiesCount; i++) {
|
for (int i = 0; i < EntitiesCount; i++) {
|
||||||
|
|||||||
@@ -140,11 +140,6 @@ char discovery_prefix[parameters_size + 1] = discovery_Prefix;
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*-------------- Auto discovery macros-----------------*/
|
/*-------------- Auto discovery macros-----------------*/
|
||||||
// Set the line below to true so as to have autodiscovery working with OpenHAB
|
|
||||||
#ifndef OpenHABDiscovery
|
|
||||||
# define OpenHABDiscovery false
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Home assistant autodiscovery value key definition
|
// Home assistant autodiscovery value key definition
|
||||||
#define jsonBatt "{{ value_json.batt | is_defined }}"
|
#define jsonBatt "{{ value_json.batt | is_defined }}"
|
||||||
#define jsonLux "{{ value_json.lux | is_defined }}"
|
#define jsonLux "{{ value_json.lux | is_defined }}"
|
||||||
|
|||||||
@@ -805,7 +805,6 @@ void SYSConfig_init() {
|
|||||||
#endif
|
#endif
|
||||||
#ifdef ZmqttDiscovery
|
#ifdef ZmqttDiscovery
|
||||||
SYSConfig.discovery = DEFAULT_DISCOVERY;
|
SYSConfig.discovery = DEFAULT_DISCOVERY;
|
||||||
SYSConfig.ohdiscovery = OpenHABDiscovery;
|
|
||||||
#endif
|
#endif
|
||||||
#ifdef LED_ADDRESSABLE
|
#ifdef LED_ADDRESSABLE
|
||||||
SYSConfig.rgbbrightness = DEFAULT_ADJ_BRIGHTNESS;
|
SYSConfig.rgbbrightness = DEFAULT_ADJ_BRIGHTNESS;
|
||||||
@@ -822,7 +821,6 @@ void SYSConfig_fromJson(JsonObject& SYSdata) {
|
|||||||
#endif
|
#endif
|
||||||
#ifdef ZmqttDiscovery
|
#ifdef ZmqttDiscovery
|
||||||
Config_update(SYSdata, "disc", SYSConfig.discovery);
|
Config_update(SYSdata, "disc", SYSConfig.discovery);
|
||||||
Config_update(SYSdata, "ohdisc", SYSConfig.ohdiscovery);
|
|
||||||
#endif
|
#endif
|
||||||
#ifdef LED_ADDRESSABLE
|
#ifdef LED_ADDRESSABLE
|
||||||
Config_update(SYSdata, "rgbb", SYSConfig.rgbbrightness);
|
Config_update(SYSdata, "rgbb", SYSConfig.rgbbrightness);
|
||||||
@@ -843,7 +841,6 @@ void SYSConfig_save() {
|
|||||||
# endif
|
# endif
|
||||||
# ifdef ZmqttDiscovery
|
# ifdef ZmqttDiscovery
|
||||||
SYSdata["disc"] = SYSConfig.discovery;
|
SYSdata["disc"] = SYSConfig.discovery;
|
||||||
SYSdata["ohdisc"] = SYSConfig.ohdiscovery;
|
|
||||||
# endif
|
# endif
|
||||||
# ifdef LED_ADDRESSABLE
|
# ifdef LED_ADDRESSABLE
|
||||||
SYSdata["rgbb"] = SYSConfig.rgbbrightness;
|
SYSdata["rgbb"] = SYSConfig.rgbbrightness;
|
||||||
@@ -2782,7 +2779,6 @@ String stateMeasures() {
|
|||||||
SYSdata["serial"] = SYSConfig.serial;
|
SYSdata["serial"] = SYSConfig.serial;
|
||||||
#ifdef ZmqttDiscovery
|
#ifdef ZmqttDiscovery
|
||||||
SYSdata["disc"] = SYSConfig.discovery;
|
SYSdata["disc"] = SYSConfig.discovery;
|
||||||
SYSdata["ohdisc"] = SYSConfig.ohdiscovery;
|
|
||||||
#endif
|
#endif
|
||||||
SYSdata["env"] = ENV_NAME;
|
SYSdata["env"] = ENV_NAME;
|
||||||
uint32_t freeMem;
|
uint32_t freeMem;
|
||||||
@@ -3370,13 +3366,6 @@ void XtoSYS(const char* topicOri, JsonObject& SYSdata) { // json object decoding
|
|||||||
Log.warning(F("RGB brightness value invalid - ignoring command" CR));
|
Log.warning(F("RGB brightness value invalid - ignoring command" CR));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
#ifdef ZmqttDiscovery
|
|
||||||
if (SYSdata.containsKey("ohdisc") && SYSdata["ohdisc"].is<bool>()) {
|
|
||||||
SYSConfig.ohdiscovery = SYSdata["ohdisc"];
|
|
||||||
Log.notice(F("OpenHAB discovery: %T" CR), SYSConfig.ohdiscovery);
|
|
||||||
publishState = true;
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
if (SYSdata.containsKey("wifi_ssid") && SYSdata["wifi_ssid"].is<const char*>() && SYSdata.containsKey("wifi_pass") && SYSdata["wifi_pass"].is<const char*>()) {
|
if (SYSdata.containsKey("wifi_ssid") && SYSdata["wifi_ssid"].is<const char*>() && SYSdata.containsKey("wifi_pass") && SYSdata["wifi_pass"].is<const char*>()) {
|
||||||
#ifdef ESP32
|
#ifdef ESP32
|
||||||
|
|||||||
Reference in new issue
Block a user