diff --git a/src/httpserver/http_fns.c b/src/httpserver/http_fns.c index c0d2b9305..d6fc6a189 100644 --- a/src/httpserver/http_fns.c +++ b/src/httpserver/http_fns.c @@ -1595,52 +1595,54 @@ void doHomeAssistantDiscovery(const char* topic, http_request_t* request) { // try to pair toggles with dimmers. This is needed only for TuyaMCU, // where custom channel types are used. This is NOT used for simple // CW/RGB/RGBCW/etc lights. - while (true) { - // find first dimmer - dimmer = -1; - for (i = 0; i < CHANNEL_MAX; i++) { - type = g_cfg.pins.channelTypes[i]; - if (BIT_CHECK(flagsChannelPublished, i)) { - continue; - } - if (type == ChType_Dimmer) { - brightness_scale = 100; - dimmer = i; - break; - } - if (type == ChType_Dimmer1000) { - brightness_scale = 1000; - dimmer = i; - break; - } - if (type == ChType_Dimmer256) { - brightness_scale = 256; - dimmer = i; - break; + if (CFG_HasFlag(OBK_FLAG_DISCOVERY_DONT_MERGE_LIGHTS) == false) { + while (true) { + // find first dimmer + dimmer = -1; + for (i = 0; i < CHANNEL_MAX; i++) { + type = g_cfg.pins.channelTypes[i]; + if (BIT_CHECK(flagsChannelPublished, i)) { + continue; + } + if (type == ChType_Dimmer) { + brightness_scale = 100; + dimmer = i; + break; + } + if (type == ChType_Dimmer1000) { + brightness_scale = 1000; + dimmer = i; + break; + } + if (type == ChType_Dimmer256) { + brightness_scale = 256; + dimmer = i; + break; + } } - } - // find first togle - toggle = -1; - for (i = 0; i < CHANNEL_MAX; i++) { - type = g_cfg.pins.channelTypes[i]; - if (BIT_CHECK(flagsChannelPublished, i)) { - continue; + // find first togle + toggle = -1; + for (i = 0; i < CHANNEL_MAX; i++) { + type = g_cfg.pins.channelTypes[i]; + if (BIT_CHECK(flagsChannelPublished, i)) { + continue; + } + if (type == ChType_Toggle) { + toggle = i; + break; + } } - if (type == ChType_Toggle) { - toggle = i; + // if nothing found, stop + if (toggle == -1 || dimmer == -1) { break; } - } - // if nothing found, stop - if (toggle == -1 || dimmer == -1) { - break; - } - BIT_SET(flagsChannelPublished, toggle); - BIT_SET(flagsChannelPublished, dimmer); - dev_info = hass_init_light_singleColor_onChannels(toggle, dimmer, brightness_scale); - MQTT_QueuePublish(topic, dev_info->channel, hass_build_discovery_json(dev_info), OBK_PUBLISH_FLAG_RETAIN); - hass_free_device_info(dev_info); + BIT_SET(flagsChannelPublished, toggle); + BIT_SET(flagsChannelPublished, dimmer); + dev_info = hass_init_light_singleColor_onChannels(toggle, dimmer, brightness_scale); + MQTT_QueuePublish(topic, dev_info->channel, hass_build_discovery_json(dev_info), OBK_PUBLISH_FLAG_RETAIN); + hass_free_device_info(dev_info); + } } #endif //if (relayCount > 0) { @@ -2547,7 +2549,7 @@ const char* g_obk_flagNames[] = { "[DoorSensor] Invert state", "[TuyaMCU] Use queue", "[HTTP] Disable authentication in safe mode (not recommended)", - "error", + "[MQTT Discovery] Don't merge toggles and dimmers into lights", "error", }; int http_fn_cfg_generic(http_request_t* request) { diff --git a/src/new_pins.h b/src/new_pins.h index 5cb410bdb..668e05d8b 100644 --- a/src/new_pins.h +++ b/src/new_pins.h @@ -1035,8 +1035,9 @@ typedef struct pinsState_s { #define OBK_FLAG_DOORSENSOR_INVERT_STATE 42 #define OBK_FLAG_TUYAMCU_USE_QUEUE 43 #define OBK_FLAG_HTTP_DISABLE_AUTH_IN_SAFE_MODE 44 +#define OBK_FLAG_DISCOVERY_DONT_MERGE_LIGHTS 45 -#define OBK_TOTAL_FLAGS 45 +#define OBK_TOTAL_FLAGS 46 #define LOGGER_FLAG_MQTT_DEDUPER 1 #define LOGGER_FLAG_POWER_SAVE 2