mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-06 15:59:52 +03:00
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:
18
src/mqtt.cpp
18
src/mqtt.cpp
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user