From 3c6471d5de75fe149f9126911731623571043d78 Mon Sep 17 00:00:00 2001 From: Erik Date: Thu, 15 Jul 2021 16:07:30 +0200 Subject: [PATCH 1/4] Improve RGBW light integration with HomeAssistant for so19 1 --- tasmota/xdrv_12_home_assistant.ino | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tasmota/xdrv_12_home_assistant.ino b/tasmota/xdrv_12_home_assistant.ino index 323c1b2c5..c2face57e 100644 --- a/tasmota/xdrv_12_home_assistant.ino +++ b/tasmota/xdrv_12_home_assistant.ino @@ -94,10 +94,10 @@ const char HASS_DISCOVER_LIGHT_COLOR[] PROGMEM = "\"rgb_val_tpl\":\"{{value_json." D_CMND_COLOR ".split(',')[0:3]|join(',')}}\""; const char HASS_DISCOVER_LIGHT_WHITE[] PROGMEM = - ",\"whit_val_cmd_t\":\"%s\"," // cmnd/led2/White - "\"whit_val_stat_t\":\"%s\"," // stat/led2/RESULT - "\"whit_val_scl\":100," - "\"whit_val_tpl\":\"{{value_json." D_CMND_WHITE "}}\""; + ",\"whit_cmd_t\":\"%s\"," // cmnd/led2/White + "\"clrm_stat_t\":\"%s\"," // stat/led2/RESULT + "\"whit_scl\":100," + "\"clrm_val_tpl\":\"{%%if value_json.White%%}white{%%else%%}rgb{%%endif %%}\""; const char HASS_DISCOVER_LIGHT_CT[] PROGMEM = ",\"clr_temp_cmd_t\":\"%s\"," // cmnd/led2/CT From 02de85efa71bd252df71aea6129aa13206926d58 Mon Sep 17 00:00:00 2001 From: Erik Date: Thu, 15 Jul 2021 16:16:51 +0200 Subject: [PATCH 2/4] Only enable white mode for RGBW lights --- tasmota/xdrv_12_home_assistant.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tasmota/xdrv_12_home_assistant.ino b/tasmota/xdrv_12_home_assistant.ino index c2face57e..5db6fa9aa 100644 --- a/tasmota/xdrv_12_home_assistant.ino +++ b/tasmota/xdrv_12_home_assistant.ino @@ -535,7 +535,7 @@ void HAssAnnounceRelayLight(void) TryResponseAppend_P(HASS_DISCOVER_LIGHT_CT, color_temp_command_topic, state_topic); ct_light = false; } - if ((!ind_light && wt_light) || (LST_RGBW <= Light.subtype && + if ((!ind_light && wt_light) || (LST_RGBW == Light.subtype && !PwmMulti && LightControl)) { char *white_temp_command_topic = stemp1; From c3d757ca951d8f9ca21d5ae326f553ce4057cd98 Mon Sep 17 00:00:00 2001 From: Erik Date: Thu, 15 Jul 2021 17:51:40 +0200 Subject: [PATCH 3/4] Use hs color instead of rgb color --- tasmota/xdrv_12_home_assistant.ino | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/tasmota/xdrv_12_home_assistant.ino b/tasmota/xdrv_12_home_assistant.ino index 5db6fa9aa..c9ca04906 100644 --- a/tasmota/xdrv_12_home_assistant.ino +++ b/tasmota/xdrv_12_home_assistant.ino @@ -88,16 +88,16 @@ const char HASS_DISCOVER_BASE_LIGHT[] PROGMEM = "\"on_cmd_type\":\"%s\"," // power on (first), power on (last), no power on (brightness) "\"bri_val_tpl\":\"{{value_json.%s}}\""; -const char HASS_DISCOVER_LIGHT_COLOR[] PROGMEM = - ",\"rgb_cmd_t\":\"%s2\"," // cmnd/led2/Color2 - "\"rgb_stat_t\":\"%s\"," // stat/led2/RESULT - "\"rgb_val_tpl\":\"{{value_json." D_CMND_COLOR ".split(',')[0:3]|join(',')}}\""; +const char HASS_DISCOVER_LIGHT_HS_COLOR[] PROGMEM = + ",\"hs_cmd_t\":\"%s\"," // cmnd/led2/HSBColor + "\"hs_stat_t\":\"%s\"," // stat/led2/RESULT + "\"hs_val_tpl\":\"{{value_json." D_CMND_HSBCOLOR ".split(',')[0:2]|join(',')}}\""; const char HASS_DISCOVER_LIGHT_WHITE[] PROGMEM = ",\"whit_cmd_t\":\"%s\"," // cmnd/led2/White "\"clrm_stat_t\":\"%s\"," // stat/led2/RESULT "\"whit_scl\":100," - "\"clrm_val_tpl\":\"{%%if value_json.White%%}white{%%else%%}rgb{%%endif %%}\""; + "\"clrm_val_tpl\":\"{%%if value_json.White%%}white{%%else%%}hs{%%endif %%}\""; const char HASS_DISCOVER_LIGHT_CT[] PROGMEM = ",\"clr_temp_cmd_t\":\"%s\"," // cmnd/led2/CT @@ -393,7 +393,6 @@ void HAssAnnounceRelayLight(void) bool is_topic_light = false; // Switch HAss domain between Lights and Relays bool ind_light = false; // Controls Separated Lights when SetOption37 is >= 128 bool ct_light = false; // Controls a CT Light when SetOption37 is >= 128 - bool wt_light = false; // Controls a White Light when SetOption37 is >= 128 bool err_flag = false; // When true it blocks the creation of entities if the order of the Relays is not correct to avoid issue with Lights bool TuyaMod = false; // Controls Tuya MCU modules bool PwmMod = false; // Controls PWM_DIMMER module @@ -514,16 +513,15 @@ void HAssAnnounceRelayLight(void) if ((ind_light && !PwmMulti) || LightControl) { if (Light.subtype >= LST_RGB) { - char *rgb_command_topic = stemp1; + char *clr_command_topic = stemp1; - GetTopic_P(rgb_command_topic, CMND, TasmotaGlobal.mqtt_topic, D_CMND_COLOR); - TryResponseAppend_P(HASS_DISCOVER_LIGHT_COLOR, rgb_command_topic, state_topic); + GetTopic_P(clr_command_topic, CMND, TasmotaGlobal.mqtt_topic, D_CMND_HSBCOLOR); + TryResponseAppend_P(HASS_DISCOVER_LIGHT_HS_COLOR, clr_command_topic, state_topic); char *effect_command_topic = stemp1; GetTopic_P(effect_command_topic, CMND, TasmotaGlobal.mqtt_topic, D_CMND_SCHEME); TryResponseAppend_P(HASS_DISCOVER_LIGHT_SCHEME, effect_command_topic, state_topic); } - if (LST_RGBW <= Light.subtype) { wt_light = true; } if (LST_RGBCW == Light.subtype) { ct_light = true; } } @@ -535,13 +533,11 @@ void HAssAnnounceRelayLight(void) TryResponseAppend_P(HASS_DISCOVER_LIGHT_CT, color_temp_command_topic, state_topic); ct_light = false; } - if ((!ind_light && wt_light) || (LST_RGBW == Light.subtype && - !PwmMulti && LightControl)) { + if (LST_RGBW == Light.subtype && !PwmMulti && LightControl) { char *white_temp_command_topic = stemp1; GetTopic_P(white_temp_command_topic, CMND, TasmotaGlobal.mqtt_topic, D_CMND_WHITE); TryResponseAppend_P(HASS_DISCOVER_LIGHT_WHITE, white_temp_command_topic, state_topic); - wt_light = false; } ind_light = false; max_lights--; From 978f2e3d5d67efbd04864def99191274ac252098 Mon Sep 17 00:00:00 2001 From: Erik Date: Thu, 15 Jul 2021 18:16:59 +0200 Subject: [PATCH 4/4] Use explicit color mode for RGBWW lights --- tasmota/xdrv_12_home_assistant.ino | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tasmota/xdrv_12_home_assistant.ino b/tasmota/xdrv_12_home_assistant.ino index c9ca04906..7568b8e2f 100644 --- a/tasmota/xdrv_12_home_assistant.ino +++ b/tasmota/xdrv_12_home_assistant.ino @@ -102,7 +102,9 @@ const char HASS_DISCOVER_LIGHT_WHITE[] PROGMEM = const char HASS_DISCOVER_LIGHT_CT[] PROGMEM = ",\"clr_temp_cmd_t\":\"%s\"," // cmnd/led2/CT "\"clr_temp_stat_t\":\"%s\"," // stat/led2/RESULT - "\"clr_temp_val_tpl\":\"{{value_json." D_CMND_COLORTEMPERATURE "}}\""; + "\"clr_temp_val_tpl\":\"{{value_json." D_CMND_COLORTEMPERATURE "}}\"," + "\"clrm_stat_t\":\"%s\"," // stat/led2/RESULT + "\"clrm_val_tpl\":\"{%%if value_json.White%%}color_temp{%%else%%}hs{%%endif %%}\""; const char HASS_DISCOVER_LIGHT_SCHEME[] PROGMEM = ",\"fx_cmd_t\":\"%s\"," // cmnd/led2/Scheme @@ -530,7 +532,7 @@ void HAssAnnounceRelayLight(void) char *color_temp_command_topic = stemp1; GetTopic_P(color_temp_command_topic, CMND, TasmotaGlobal.mqtt_topic, D_CMND_COLORTEMPERATURE); - TryResponseAppend_P(HASS_DISCOVER_LIGHT_CT, color_temp_command_topic, state_topic); + TryResponseAppend_P(HASS_DISCOVER_LIGHT_CT, color_temp_command_topic, state_topic, state_topic); ct_light = false; } if (LST_RGBW == Light.subtype && !PwmMulti && LightControl) {