HA binary sensor bool format payload

@proddy : since bool-format goes from websettings to mqtt it needs a change. but i'm not familiar enough with HA: raw or strings? HA configs seems to have a lot of trips.
This commit is contained in:
MichaelDvP
2021-03-09 19:13:20 +01:00
committed by GitHub
parent 18a1406d41
commit 4dd4c37cba

View File

@@ -862,11 +862,19 @@ void Mqtt::publish_mqtt_ha_sensor(uint8_t type, // EMSdevice
snprintf_P(topic, sizeof(topic), PSTR("homeassistant/binary_sensor/%s/%s/config"), mqtt_base_.c_str(), uniq.c_str()); // topic
// how to render boolean
EMSESP::webSettingsService.read([&](WebSettings & settings) {
char result[10];
doc[F("payload_on")] = Helpers::render_boolean(result, true);
doc[F("payload_off")] = Helpers::render_boolean(result, false);
});
if (bool_format_ == BOOL_FORMAT_ONOFF) {
doc[F("payload_on")] = FJSON("on");
doc[F("payload_off")] = FJSON("off");
} else if (bool_format_ == BOOL_FORMAT_ONOFF_CAP) {
doc[F("payload_on")] = FJSON("ON");
doc[F("payload_off")] = FJSON("OFF");
} else if (bool_format_ == BOOL_FORMAT_TRUEFALSE) {
doc[F("payload_on")] = true;
doc[F("payload_off")] = false;
} else {
doc[F("payload_on")] = 1;
doc[F("payload_off")] = 0;
}
} else {
// normal HA sensor, not a boolean one
snprintf_P(topic, sizeof(topic), PSTR("homeassistant/sensor/%s/%s/config"), mqtt_base_.c_str(), uniq.c_str()); // topic