Skip to content

Commit ed2b848

Browse files
authored
Merge pull request arendst#4478 from emontnemery/hass_fix_light
Small improvements to Hass MQTT discovery
2 parents f0bd53b + 573011b commit ed2b848

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

sonoff/xdrv_12_home_assistant.ino

+14-14
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,7 @@ const char HASS_DISCOVER_LIGHT_DIMMER[] PROGMEM =
5454
const char HASS_DISCOVER_LIGHT_COLOR[] PROGMEM =
5555
"%s,\"rgb_command_topic\":\"%s2\"," // cmnd/led2/Color2
5656
"\"rgb_state_topic\":\"%s\"," // stat/led2/RESULT
57-
"\"rgb_value_template\":\"{{value_json." D_CMND_COLOR "}}\"";
58-
// "\"rgb_value_template\":\"{{value_json." D_CMND_COLOR " | join(',')}}\"";
57+
"\"rgb_value_template\":\"{{value_json." D_CMND_COLOR ".split(',')[0:3]|join(',')}}\"";
5958

6059
const char HASS_DISCOVER_LIGHT_CT[] PROGMEM =
6160
"%s,\"color_temp_command_topic\":\"%s\"," // cmnd/led2/CT
@@ -115,19 +114,17 @@ const char HASS_DISCOVER_LIGHT_COLOR_SHORT[] PROGMEM =
115114
"%s,\"rgb_cmd_t\":\"%s2\"," // cmnd/led2/Color2
116115
"\"rgb_stat_t\":\"%s\"," // stat/led2/RESULT
117116
"\"rgb_val_tpl\":\"{{value_json." D_CMND_COLOR ".split(',')[0:3]|join(',')}}\"";
118-
// "\"rgb_val_tpl\":\"{{value_json." D_CMND_COLOR " | join(',')}}\"";
119117

120118
const char HASS_DISCOVER_LIGHT_CT_SHORT[] PROGMEM =
121119
"%s,\"clr_temp_cmd_t\":\"%s\"," // cmnd/led2/CT
122120
"\"clr_temp_stat_t\":\"%s\"," // stat/led2/RESULT
123121
"\"clr_temp_val_tpl\":\"{{value_json." D_CMND_COLORTEMPERATURE "}}\"";
124-
/*
125-
const char HASS_DISCOVER_LIGHT_SCHEME[] PROGMEM =
126-
"%s,\"effect_command_topic\":\"%s\"," // cmnd/led2/Scheme
127-
"\"effect_state_topic\":\"%s\"," // stat/led2/RESULT
128-
"\"effect_value_template\":\"{{value_json." D_CMND_SCHEME "}}\","
129-
"\"effect_list\":[\"0\",\"1\",\"2\",\"3\",\"4\"]"; // string list with reference to scheme parameter. Currently only supports numbers 0 to 11 as it make the mqtt string too long
130-
*/
122+
123+
const char HASS_DISCOVER_LIGHT_SCHEME_SHORT[] PROGMEM =
124+
"%s,\"fx_cmd_t\":\"%s\"," // cmnd/led2/Scheme
125+
"\"fx_stat_t\":\"%s\"," // stat/led2/RESULT
126+
"\"fx_val_tpl\":\"{{value_json." D_CMND_SCHEME "}}\","
127+
"\"fx_list\":[\"0\",\"1\",\"2\",\"3\",\"4\"]"; // string list with reference to scheme parameter.
131128

132129
const char HASS_DISCOVER_SENSOR_SHORT[] PROGMEM =
133130
"{\"name\":\"%s\"," // dualr2 1 BTN
@@ -239,12 +236,15 @@ void HAssAnnounceRelayLight(void)
239236
Shorten(&rgb_command_topic, prefix);
240237
snprintf_P(mqtt_data, sizeof(mqtt_data), Settings.flag3.hass_short_discovery_msg?HASS_DISCOVER_LIGHT_COLOR_SHORT:HASS_DISCOVER_LIGHT_COLOR,
241238
mqtt_data, rgb_command_topic, state_topic);
242-
/*
243-
char effect_command_topic[TOPSZ];
244239

240+
char _effect_command_topic[TOPSZ];
241+
char *effect_command_topic = _effect_command_topic;
245242
GetTopic_P(effect_command_topic, CMND, mqtt_topic, D_CMND_SCHEME);
246-
snprintf_P(mqtt_data, sizeof(mqtt_data), HASS_DISCOVER_LIGHT_SCHEME, mqtt_data, effect_command_topic, state_topic);
247-
*/
243+
if (Settings.flag3.hass_short_discovery_msg) {
244+
Shorten(&effect_command_topic, prefix);
245+
snprintf_P(mqtt_data, sizeof(mqtt_data), HASS_DISCOVER_LIGHT_SCHEME_SHORT, mqtt_data, effect_command_topic, state_topic);
246+
}
247+
248248
}
249249
if ((LST_COLDWARM == light_subtype) || (LST_RGBWC == light_subtype)) {
250250
char _color_temp_command_topic[TOPSZ];

0 commit comments

Comments
 (0)