mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2026-01-29 10:09:11 +03:00
HA integration - add devices as HA devices - HomeAssistant Discovery #288
This commit is contained in:
@@ -85,8 +85,24 @@ Boiler::Boiler(uint8_t device_type, int8_t device_id, uint8_t product_id, const
|
||||
// create the config topics for Home Assistant MQTT Discovery
|
||||
// for each of the main elements
|
||||
void Boiler::register_mqtt_ha_config() {
|
||||
Mqtt::register_mqtt_ha_binary_sensor(F("Boiler DHW"), "tapwater_active");
|
||||
Mqtt::register_mqtt_ha_binary_sensor(F("Boiler Heating"), "heating_active");
|
||||
// Create the Master device
|
||||
StaticJsonDocument<EMSESP_MAX_JSON_SIZE_MEDIUM> doc;
|
||||
doc["name"] = F("EMS-ESP");
|
||||
doc["uniq_id"] = F("boiler");
|
||||
doc["ic"] = F("mdi:home-thermometer-outline");
|
||||
doc["stat_t"] = F("ems-esp/boiler_data");
|
||||
doc["val_tpl"] = F("{{value_json.serviceCode}}");
|
||||
JsonObject dev = doc.createNestedObject("dev");
|
||||
dev["name"] = F("EMS-ESP Boiler");
|
||||
dev["sw"] = EMSESP_APP_VERSION;
|
||||
dev["mf"] = this->brand_to_string();
|
||||
dev["mdl"] = this->name();
|
||||
JsonArray ids = dev.createNestedArray("ids");
|
||||
ids.add("ems-esp-boiler");
|
||||
Mqtt::publish_retain(F("homeassistant/sensor/ems-esp/boiler/config"), doc.as<JsonObject>(), true); // publish the config payload with retain flag
|
||||
|
||||
Mqtt::register_mqtt_ha_binary_sensor(F("Boiler DHW"), this->device_type(), "tapwater_active");
|
||||
Mqtt::register_mqtt_ha_binary_sensor(F("Boiler Heating"), this->device_type(), "heating_active");
|
||||
|
||||
Mqtt::register_mqtt_ha_sensor(F("Service Code"), this->device_type(), "serviceCode", "", "");
|
||||
Mqtt::register_mqtt_ha_sensor(F("Service Code number"), this->device_type(), "serviceCodeNumber", "", "");
|
||||
|
||||
@@ -139,6 +139,22 @@ void Mixing::publish_values() {
|
||||
|
||||
// publish config topic for HA MQTT Discovery
|
||||
void Mixing::register_mqtt_ha_config() {
|
||||
// Create the Master device
|
||||
StaticJsonDocument<EMSESP_MAX_JSON_SIZE_MEDIUM> doc;
|
||||
doc["name"] = F("EMS-ESP");
|
||||
doc["uniq_id"] = F("mixing");
|
||||
doc["ic"] = F("mdi:home-thermometer-outline");
|
||||
doc["stat_t"] = F("ems-esp/mixing_data");
|
||||
doc["val_tpl"] = F("{{value_json.pumpStatus}}");
|
||||
JsonObject dev = doc.createNestedObject("dev");
|
||||
dev["name"] = F("EMS-ESP Mixing");
|
||||
dev["sw"] = EMSESP_APP_VERSION;
|
||||
dev["mf"] = this->brand_to_string();
|
||||
dev["mdl"] = this->name();
|
||||
JsonArray ids = dev.createNestedArray("ids");
|
||||
ids.add("ems-esp-mixing");
|
||||
Mqtt::publish_retain(F("homeassistant/sensor/ems-esp/mixing/config"), doc.as<JsonObject>(), true); // publish the config payload with retain flag
|
||||
|
||||
if (this->type() == Type::HC) {
|
||||
Mqtt::register_mqtt_ha_sensor(F("Current flow temperature"), this->device_type(), "flowTemp", "°C", "");
|
||||
Mqtt::register_mqtt_ha_sensor(F("Setpoint flow temperature"), this->device_type(), "flowSetTemp", "°C", "");
|
||||
|
||||
@@ -127,6 +127,22 @@ void Solar::publish_values() {
|
||||
|
||||
// publish config topic for HA MQTT Discovery
|
||||
void Solar::register_mqtt_ha_config() {
|
||||
// Create the Master device
|
||||
StaticJsonDocument<EMSESP_MAX_JSON_SIZE_MEDIUM> doc;
|
||||
doc["name"] = F("EMS-ESP");
|
||||
doc["uniq_id"] = F("solar");
|
||||
doc["ic"] = F("mdi:home-thermometer-outline");
|
||||
doc["stat_t"] = F("ems-esp/solar_data");
|
||||
doc["val_tpl"] = F("{{value_json.solarPump}}");
|
||||
JsonObject dev = doc.createNestedObject("dev");
|
||||
dev["name"] = F("EMS-ESP Solar");
|
||||
dev["sw"] = EMSESP_APP_VERSION;
|
||||
dev["mf"] = this->brand_to_string();
|
||||
dev["mdl"] = this->name();
|
||||
JsonArray ids = dev.createNestedArray("ids");
|
||||
ids.add("ems-esp-solar");
|
||||
Mqtt::publish_retain(F("homeassistant/sensor/ems-esp/solar/config"), doc.as<JsonObject>(), true); // publish the config payload with retain flag
|
||||
|
||||
Mqtt::register_mqtt_ha_sensor(F("Collector temperature (TS1)"), this->device_type(), "collectorTemp", "°C", "");
|
||||
Mqtt::register_mqtt_ha_sensor(F("Bottom temperature (TS2)"), this->device_type(), "tankBottomTemp", "°C", "");
|
||||
Mqtt::register_mqtt_ha_sensor(F("Bottom temperature (TS5)"), this->device_type(), "tankBottomTemp2", "°C", "");
|
||||
|
||||
@@ -412,7 +412,7 @@ bool Thermostat::export_values(uint8_t mqtt_format, JsonObject & rootThermostat)
|
||||
dataThermostat["summermode"] = "auto";
|
||||
} else {
|
||||
char s[7];
|
||||
rootThermostat["summermode"] = Helpers::render_boolean(s, (hc->summer_setmode == 0));
|
||||
rootThermostat["summermode"] = Helpers::render_boolean(s, (hc->summer_setmode == 0));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -599,10 +599,14 @@ void Thermostat::register_mqtt_ha_config(uint8_t hc_num) {
|
||||
}
|
||||
|
||||
JsonObject dev = doc.createNestedObject(F("dev"));
|
||||
JsonArray ids = dev.createNestedArray(F("ids"));
|
||||
ids.add(F("ems-esp"));
|
||||
dev["name"] = F("EMS-ESP Thermostat");
|
||||
dev["sw"] = EMSESP_APP_VERSION;
|
||||
dev["mf"] = this->brand_to_string();
|
||||
dev["mdl"] = this->name();
|
||||
JsonArray ids = dev.createNestedArray(F("ids"));
|
||||
ids.add(F("ems-esp-thermostat"));
|
||||
|
||||
std::string topic(100, '\0'); // e.g homeassistant/climate/hc1/thermostat/config
|
||||
std::string topic(100, '\0');
|
||||
snprintf_P(&topic[0], topic.capacity() + 1, PSTR("homeassistant/climate/ems-esp/thermostat_hc%d/config"), hc_num);
|
||||
// Mqtt::publish(topic); // empty payload, this remove any previous config sent to HA
|
||||
Mqtt::publish_retain(topic, doc.as<JsonObject>(), true); // publish the config payload with retain flag
|
||||
@@ -926,7 +930,7 @@ void Thermostat::show_values(uuid::console::Shell & shell) {
|
||||
print_value(shell, 4, F("Summer mode"), F("auto"));
|
||||
} else {
|
||||
char s[7];
|
||||
print_value(shell, 4, F("Summer mode"), Helpers::render_boolean(s, (hc->summer_setmode == 0)));
|
||||
print_value(shell, 4, F("Summer mode"), Helpers::render_boolean(s, (hc->summer_setmode == 0)));
|
||||
}
|
||||
}
|
||||
if (Helpers::hasValue(hc->targetflowtemp)) {
|
||||
@@ -1646,21 +1650,21 @@ bool Thermostat::set_mode_n(const uint8_t mode, const uint8_t hc_num) {
|
||||
}
|
||||
|
||||
bool Thermostat::set_summermode(const char * value, const int8_t id) {
|
||||
uint8_t hc_num = (id == -1) ? AUTO_HEATING_CIRCUIT : id;
|
||||
std::shared_ptr<Thermostat::HeatingCircuit> hc = heating_circuit(hc_num);
|
||||
std::string v(10, '\0');
|
||||
uint8_t hc_num = (id == -1) ? AUTO_HEATING_CIRCUIT : id;
|
||||
std::shared_ptr<Thermostat::HeatingCircuit> hc = heating_circuit(hc_num);
|
||||
std::string v(10, '\0');
|
||||
if (!Helpers::value2string(value, v)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
uint8_t set = 0xFF; // some dummy value
|
||||
if (v == "on" || v == "1" || v == "true") {
|
||||
if (v == "on" || v == "1" || v == "true") {
|
||||
LOG_INFO(F("Setting summer mode to always on for heating circuit %d"), hc->hc_num());
|
||||
set = 0;
|
||||
} else if (v == "auto" || v == "2") {
|
||||
LOG_INFO(F("Setting summer mode to auto for heating circuit %d"), hc->hc_num());
|
||||
set = 1;
|
||||
} else if (v == "off" || v == "0" || v == "false") {
|
||||
} else if (v == "off" || v == "0" || v == "false") {
|
||||
LOG_INFO(F("Setting summer mode to always off for heating circuit %d"), hc->hc_num());
|
||||
set = 2;
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user