Skip to content

Commit

Permalink
fix for MQTT format #205
Browse files Browse the repository at this point in the history
  • Loading branch information
fashberg committed Aug 26, 2023
1 parent ec1bd95 commit b53a414
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 19 deletions.
1 change: 1 addition & 0 deletions Changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

* Support for static IP-Addresses - thanks to @N-b-dy
* Support for current IP-Address sensor for Home Assistant - thanks to @Henry-Sir
* Fix for new Home Assistant Autodiscovery format (fixes [#205](https://github.com/fashberg/WThermostatBeca/issues/205))

## Version 1.22-fas

Expand Down
34 changes: 15 additions & 19 deletions WThermostat/WBecaDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ const static char HTTP_CONFIG_SCHTAB_FOOT[] PROGMEM = R"=====(
// LWT = Last Will & Testament
const static char MQTT_HASS_AUTODISCOVERY_CLIMATE[] PROGMEM = R"=====(
{
"name":"%s",
"name":null,
"unique_id": "%s",
"dev":{"ids":["%s"],"name":"%s","mdl":"%s","sw":"%s","mf":"WThermostatBeca"},
"dev":{"ids":["%s"],"name":"%s","mdl":"%s","sw":"%s","mf":"WThermostatBeca","cu":"http://%s/config/"},
"~": "%s",
"avty_t":"~/tele/LWT",
"pl_avail":"Online",
Expand All @@ -63,9 +63,9 @@ const static char MQTT_HASS_AUTODISCOVERY_CLIMATE[] PROGMEM = R"=====(
)=====";
const static char MQTT_HASS_AUTODISCOVERY_AIRCO[] PROGMEM = R"=====(
{
"name":"%s",
"name":null,
"unique_id": "%s",
"dev":{"ids":["%s"],"name":"%s","mdl":"%s","sw":"%s","mf":"WThermostatBeca"},
"dev":{"ids":["%s"],"name":"%s","mdl":"%s","sw":"%s","mf":"WThermostatBeca","cu":"http://%s/config/"},
"~": "%s",
"avty_t":"~/tele/LWT",
"pl_avail":"Online",
Expand Down Expand Up @@ -95,7 +95,7 @@ const static char MQTT_HASS_AUTODISCOVERY_AIRCO[] PROGMEM = R"=====(
)=====";
const static char MQTT_HASS_AUTODISCOVERY_SENSOR[] PROGMEM = R"=====(
{
"name":"%s Temperature",
"name":"Temperature",
"unique_id":"%s",
"device_class":"temperature",
"dev":{"ids":["%s"]},
Expand All @@ -107,7 +107,7 @@ const static char MQTT_HASS_AUTODISCOVERY_SENSOR[] PROGMEM = R"=====(
)=====";
const static char MQTT_HASS_AUTODISCOVERY_SENSORFLOOR[] PROGMEM = R"=====(
{
"name":"%s Temperature Floor",
"name":"Temperature Floor",
"unique_id":"%s",
"device_class":"temperature",
"dev":{"ids":["%s"]},
Expand All @@ -119,7 +119,7 @@ const static char MQTT_HASS_AUTODISCOVERY_SENSORFLOOR[] PROGMEM = R"====
)=====";
const static char MQTT_HASS_AUTODISCOVERY_SENSORRSSI[] PROGMEM = R"=====(
{
"name":"%s WiFi RSSI",
"name":"WiFi RSSI",
"unique_id":"%s",
"device_class":"signal_strength",
"dev":{"ids":["%s"]},
Expand All @@ -131,7 +131,7 @@ const static char MQTT_HASS_AUTODISCOVERY_SENSORRSSI[] PROGMEM = R"=====
)=====";
const static char MQTT_HASS_AUTODISCOVERY_SENSORIP[] PROGMEM = R"=====(
{
"name":"%s IP",
"name":"IP",
"unique_id":"%s",
"dev":{"ids":["%s"]},
"~":"%s",
Expand Down Expand Up @@ -1332,29 +1332,29 @@ class WBecaDevice: public WDevice {
if (!removeDiscovery){
if (getThermostatModel() == MODEL_BHT_002_GBLW ){
response->printf_P(MQTT_HASS_AUTODISCOVERY_CLIMATE,
network->getIdx(),
unique_id.c_str(),
network->getMacAddress().c_str(),
network->getIdx(),
network->getApplicationName().c_str(),
network->getFirmwareVersion().c_str(),
network->getDeviceIp().toString().c_str(),
network->getMqttTopic(),
str_temp
);
} else if (getThermostatModel() == MODEL_BAC_002_ALW ){
response->printf_P(MQTT_HASS_AUTODISCOVERY_AIRCO,
network->getIdx(),
unique_id.c_str(),
network->getMacAddress().c_str(),
network->getIdx(),
network->getApplicationName().c_str(),
network->getFirmwareVersion().c_str(),
network->getDeviceIp().toString().c_str(),
network->getMqttTopic(),
str_temp
);
}
}
if (!network->publishMqtt(topic.c_str(), response, true)) return false;
network->publishMqtt(topic.c_str(), response, true);
response->flush();

unique_id = (String)network->getIdx();
Expand All @@ -1364,13 +1364,12 @@ class WBecaDevice: public WDevice {
topic.concat(F("/config"));
if (!removeDiscovery){
response->printf_P(MQTT_HASS_AUTODISCOVERY_SENSOR,
network->getIdx(),
unique_id.c_str(),
network->getMacAddress().c_str(),
network->getMqttTopic()
);
}
if (!network->publishMqtt(topic.c_str(), response, true)) return false;
network->publishMqtt(topic.c_str(), response, true);
response->flush();

if (this->floorSensor->getBoolean()){
Expand All @@ -1381,13 +1380,12 @@ class WBecaDevice: public WDevice {
topic.concat(F("/config"));
if (!removeDiscovery){
response->printf_P(MQTT_HASS_AUTODISCOVERY_SENSORFLOOR,
network->getIdx(),
unique_id.c_str(),
network->getMacAddress().c_str(),
network->getMqttTopic()
);
}
if (!network->publishMqtt(topic.c_str(), response, true)) return false;
network->publishMqtt(topic.c_str(), response, true);
response->flush();
}

Expand All @@ -1398,13 +1396,12 @@ class WBecaDevice: public WDevice {
topic.concat(F("/config"));
if (!removeDiscovery){
response->printf_P(MQTT_HASS_AUTODISCOVERY_SENSORRSSI,
network->getIdx(),
unique_id.c_str(),
network->getMacAddress().c_str(),
network->getMqttTopic()
);
}
if (!network->publishMqtt(topic.c_str(), response, true)) return false;
network->publishMqtt(topic.c_str(), response, true);
response->flush();

unique_id = (String)network->getIdx();
Expand All @@ -1414,13 +1411,12 @@ class WBecaDevice: public WDevice {
topic.concat(F("/config"));
if (!removeDiscovery){
response->printf_P(MQTT_HASS_AUTODISCOVERY_SENSORIP,
network->getIdx(),
unique_id.c_str(),
network->getMacAddress().c_str(),
network->getMqttTopic()
);
}
if (!network->publishMqtt(topic.c_str(), response, true)) return false;
network->publishMqtt(topic.c_str(), response, true);
response->flush();
return true;
}
Expand Down

0 comments on commit b53a414

Please sign in to comment.