diff --git a/code/espurna/homeassistant.ino b/code/espurna/homeassistant.ino index a212fa52..a3892bce 100644 --- a/code/espurna/homeassistant.ino +++ b/code/espurna/homeassistant.ino @@ -38,10 +38,9 @@ void _haSendMagnitude(unsigned char i, JsonObject& config) { config.set("platform", "mqtt"); config["state_topic"] = mqttTopic(magnitudeTopicIndex(i).c_str(), false); config["unit_of_measurement"] = magnitudeUnits(type); - } -void _haSendMagnitudes() { +void _haSendMagnitudes(const JsonObject& deviceConfig) { for (unsigned char i=0; i printer, bool wrapJson = false) } #endif +} +void _haGetDeviceConfig(JsonObject& config) { + String identifier = getIdentifier(); + + config.createNestedArray("identifiers").add(identifier); + config["name"] = getSetting("desc", getSetting("hostname")); + config["manufacturer"] = String(MANUFACTURER); + config["model"] = String(DEVICE); + config["sw_version"] = String(APP_NAME) + " " + String(APP_VERSION) + " (" + getCoreVersion() + ")"; } void _haSend() { @@ -254,12 +268,18 @@ void _haSend() { DEBUG_MSG_P(PSTR("[HA] Sending autodiscovery MQTT message\n")); + // Get common device config + DynamicJsonBuffer jsonBuffer; + JsonObject& deviceConfig = jsonBuffer.createObject(); + _haGetDeviceConfig(deviceConfig); + // Send messages - _haSendSwitches(); + _haSendSwitches(deviceConfig); #if SENSOR_SUPPORT - _haSendMagnitudes(); + _haSendMagnitudes(deviceConfig); #endif - + + jsonBuffer.clear(); _haSendFlag = false; }