Workaround for better Domoticz MQTT intergration? #904

This commit is contained in:
proddy
2023-02-11 23:26:15 +01:00
parent ba96d587ab
commit 12b4bd3795
19 changed files with 87 additions and 39 deletions

View File

@@ -169,6 +169,10 @@
#define EMSESP_DEFAULT_DISCOVERY_PREFIX "homeassistant"
#endif
#ifndef EMSESP_DEFAULT_DISCOVERY_TYPE
#define EMSESP_DEFAULT_DISCOVERY_TYPE 0 // HA
#endif
#ifndef EMSESP_DEFAULT_PUBLISH_SINGLE
#define EMSESP_DEFAULT_PUBLISH_SINGLE false
#endif

View File

@@ -42,6 +42,7 @@ uint8_t Mqtt::entity_format_;
bool Mqtt::ha_enabled_;
uint8_t Mqtt::nested_format_;
std::string Mqtt::discovery_prefix_;
uint8_t Mqtt::discovery_type_;
bool Mqtt::send_response_;
bool Mqtt::publish_single_;
bool Mqtt::publish_single2cmd_;
@@ -1024,7 +1025,6 @@ void Mqtt::publish_ha_sensor_config(uint8_t type, // EMSdev
}
// build a config topic that will be prefix onto a HA type (e.g. number, switch)
// e.g. homeassistant/number/ems-esp/thermostat_hc1_manualtemp
char config_topic[70];
snprintf(config_topic, sizeof(config_topic), "%s/%s_%s/config", mqtt_basename_.c_str(), device_name, entity_with_tag);
@@ -1041,9 +1041,15 @@ void Mqtt::publish_ha_sensor_config(uint8_t type, // EMSdev
case DeviceValueType::SHORT:
case DeviceValueType::USHORT:
case DeviceValueType::ULONG:
// number - https://www.home-assistant.io/integrations/number.mqtt
// https://developers.home-assistant.io/docs/core/entity/number
snprintf(topic, sizeof(topic), "number/%s", config_topic);
if (discovery_type() == 0) {
// Home Assistant
// number - https://www.home-assistant.io/integrations/number.mqtt
snprintf(topic, sizeof(topic), "number/%s", config_topic);
} else {
// Domoticz
// Does not support number, use sensor
snprintf(topic, sizeof(topic), "sensor/%s", config_topic);
}
break;
case DeviceValueType::BOOL:
// switch - https://www.home-assistant.io/integrations/switch.mqtt

View File

@@ -185,6 +185,10 @@ class Mqtt {
return entity_format_;
}
static uint8_t discovery_type() {
return discovery_type_;
}
static void nested_format(uint8_t nested_format) {
nested_format_ = nested_format;
}
@@ -326,6 +330,7 @@ class Mqtt {
static uint8_t nested_format_;
static uint8_t entity_format_;
static std::string discovery_prefix_;
static uint8_t discovery_type_;
static bool publish_single_;
static bool publish_single2cmd_;
static bool send_response_;

View File

@@ -1244,6 +1244,7 @@ bool System::command_info(const char * value, const int8_t id, JsonObject & outp
node["entity format"] = settings.entity_format;
node["base"] = settings.base;
node["discovery prefix"] = settings.discovery_prefix;
node["discovery type"] = settings.discovery_type;
node["nested format"] = settings.nested_format;
node["ha enabled"] = settings.ha_enabled;
node["mqtt qos"] = settings.mqtt_qos;