mirror of https://github.com/arendst/Tasmota.git
Add option for new Hass discovery feature
This commit is contained in:
parent
8628c54ba0
commit
89b58f62af
|
@ -68,7 +68,7 @@ typedef union { // Restricted by MISRA-C Rule 18.4 bu
|
|||
uint32_t time_append_timezone : 1; // bit 2 (v6.2.1.2)
|
||||
uint32_t gui_hostname_ip : 1; // bit 3 (v6.2.1.20)
|
||||
uint32_t tuya_apply_o20 : 1; // bit 4 (v6.3.0.4)
|
||||
uint32_t spare05 : 1;
|
||||
uint32_t hass_short_discovery_msg : 1; // bit 5 (vTBD)
|
||||
uint32_t spare06 : 1;
|
||||
uint32_t spare07 : 1;
|
||||
uint32_t spare08 : 1;
|
||||
|
|
|
@ -22,6 +22,47 @@
|
|||
#define XDRV_12 12
|
||||
|
||||
const char HASS_DISCOVER_RELAY[] PROGMEM =
|
||||
"{\"name\":\"%s\"," // dualr2 1
|
||||
"\"command_topic\":\"%s\"," // cmnd/dualr2/POWER2
|
||||
"\"state_topic\":\"%s\"," // stat/dualr2/RESULT (implies "\"optimistic\":\"false\",")
|
||||
"\"value_template\":\"{{value_json.%s}}\"," // POWER2
|
||||
"\"payload_off\":\"%s\"," // OFF
|
||||
"\"payload_on\":\"%s\"," // ON
|
||||
// "\"optimistic\":\"false\"," // false is Hass default when state_topic is set
|
||||
"\"availability_topic\":\"%s\"," // tele/dualr2/LWT
|
||||
"\"payload_available\":\"" D_ONLINE "\"," // Online
|
||||
"\"payload_not_available\":\"" D_OFFLINE "\""; // Offline
|
||||
|
||||
const char HASS_DISCOVER_BUTTON[] PROGMEM =
|
||||
"{\"name\":\"%s\"," // dualr2 1 BTN
|
||||
"\"state_topic\":\"%s\"," // cmnd/dualr2/POWER (implies "\"optimistic\":\"false\",")
|
||||
// "\"value_template\":\"{{value_json.%s}}\"," // POWER2
|
||||
"\"payload_on\":\"%s\"," // TOGGLE
|
||||
// "\"optimistic\":\"false\"," // false is Hass default when state_topic is set
|
||||
"\"availability_topic\":\"%s\"," // tele/dualr2/LWT
|
||||
"\"payload_available\":\"" D_ONLINE "\"," // Online
|
||||
"\"payload_not_available\":\"" D_OFFLINE "\"," // Offline
|
||||
"\"force_update\":true";
|
||||
|
||||
const char HASS_DISCOVER_LIGHT_DIMMER[] PROGMEM =
|
||||
"%s,\"brightness_command_topic\":\"%s\"," // cmnd/led2/Dimmer
|
||||
"\"brightness_state_topic\":\"%s\"," // stat/led2/RESULT
|
||||
"\"brightness_scale\":100," // 100%
|
||||
"\"on_command_type\":\"brightness\"," // power on (first), power on (last), no power on (brightness)
|
||||
"\"brightness_value_template\":\"{{value_json." D_CMND_DIMMER "}}\"";
|
||||
|
||||
const char HASS_DISCOVER_LIGHT_COLOR[] PROGMEM =
|
||||
"%s,\"rgb_command_topic\":\"%s2\"," // cmnd/led2/Color2
|
||||
"\"rgb_state_topic\":\"%s\"," // stat/led2/RESULT
|
||||
"\"rgb_value_template\":\"{{value_json." D_CMND_COLOR "}}\"";
|
||||
// "\"rgb_value_template\":\"{{value_json." D_CMND_COLOR " | join(',')}}\"";
|
||||
|
||||
const char HASS_DISCOVER_LIGHT_CT[] PROGMEM =
|
||||
"%s,\"color_temp_command_topic\":\"%s\"," // cmnd/led2/CT
|
||||
"\"color_temp_state_topic\":\"%s\"," // stat/led2/RESULT
|
||||
"\"color_temp_value_template\":\"{{value_json." D_CMND_COLORTEMPERATURE "}}\"";
|
||||
|
||||
const char HASS_DISCOVER_RELAY_SHORT[] PROGMEM =
|
||||
"{\"name\":\"%s\"," // dualr2 1
|
||||
"\"cmd_t\":\"%s\"," // cmnd/dualr2/POWER2
|
||||
"\"stat_t\":\"%s\"," // stat/dualr2/RESULT (implies "\"optimistic\":\"false\",")
|
||||
|
@ -33,7 +74,7 @@ const char HASS_DISCOVER_RELAY[] PROGMEM =
|
|||
"\"pl_avail\":\"" D_ONLINE "\"," // Online
|
||||
"\"pl_not_avail\":\"" D_OFFLINE "\""; // Offline
|
||||
|
||||
const char HASS_DISCOVER_BUTTON[] PROGMEM =
|
||||
const char HASS_DISCOVER_BUTTON_SHORT[] PROGMEM =
|
||||
"{\"name\":\"%s\"," // dualr2 1 BTN
|
||||
"\"stat_t\":\"%s\"," // cmnd/dualr2/POWER (implies "\"optimistic\":\"false\",")
|
||||
// "\"value_template\":\"{{value_json.%s}}\"," // POWER2
|
||||
|
@ -44,20 +85,20 @@ const char HASS_DISCOVER_BUTTON[] PROGMEM =
|
|||
"\"pl_not_avail\":\"" D_OFFLINE "\"," // Offline
|
||||
"\"frc_upd\":true";
|
||||
|
||||
const char HASS_DISCOVER_LIGHT_DIMMER[] PROGMEM =
|
||||
const char HASS_DISCOVER_LIGHT_DIMMER_SHORT[] PROGMEM =
|
||||
"%s,\"bri_cmd_t\":\"%s\"," // cmnd/led2/Dimmer
|
||||
"\"bri_stat_t\":\"%s\"," // stat/led2/RESULT
|
||||
"\"bri_scl\":100," // 100%
|
||||
"\"on_cmd_type\":\"brightness\"," // power on (first), power on (last), no power on (brightness)
|
||||
"\"bri_val_tpl\":\"{{value_json." D_CMND_DIMMER "}}\"";
|
||||
|
||||
const char HASS_DISCOVER_LIGHT_COLOR[] PROGMEM =
|
||||
const char HASS_DISCOVER_LIGHT_COLOR_SHORT[] PROGMEM =
|
||||
"%s,\"rgb_cmd_t\":\"%s2\"," // cmnd/led2/Color2
|
||||
"\"rgb_stat_t\":\"%s\"," // stat/led2/RESULT
|
||||
"\"rgb_val_tpl\":\"{{value_json." D_CMND_COLOR "}}\"";
|
||||
// "\"rgb_val_tpl\":\"{{value_json." D_CMND_COLOR " | join(',')}}\"";
|
||||
|
||||
const char HASS_DISCOVER_LIGHT_CT[] PROGMEM =
|
||||
const char HASS_DISCOVER_LIGHT_CT_SHORT[] PROGMEM =
|
||||
"%s,\"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 "}}\"";
|
||||
|
@ -105,19 +146,22 @@ void HAssDiscoverRelay(void)
|
|||
GetTopic_P(command_topic, CMND, mqtt_topic, value_template);
|
||||
GetTopic_P(state_topic, STAT, mqtt_topic, S_RSLT_RESULT);
|
||||
GetTopic_P(availability_topic, TELE, mqtt_topic, S_LWT);
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), HASS_DISCOVER_RELAY, name, command_topic, state_topic, value_template, Settings.state_text[0], Settings.state_text[1], availability_topic);
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), Settings.flag3.hass_short_discovery_msg?HASS_DISCOVER_RELAY_SHORT:HASS_DISCOVER_RELAY,
|
||||
name, command_topic, state_topic, value_template, Settings.state_text[0], Settings.state_text[1], availability_topic);
|
||||
|
||||
if (is_light) {
|
||||
char brightness_command_topic[TOPSZ];
|
||||
|
||||
GetTopic_P(brightness_command_topic, CMND, mqtt_topic, D_CMND_DIMMER);
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), HASS_DISCOVER_LIGHT_DIMMER, mqtt_data, brightness_command_topic, state_topic);
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), Settings.flag3.hass_short_discovery_msg?HASS_DISCOVER_LIGHT_DIMMER_SHORT:HASS_DISCOVER_LIGHT_DIMMER,
|
||||
mqtt_data, brightness_command_topic, state_topic);
|
||||
|
||||
if (light_subtype >= LST_RGB) {
|
||||
char rgb_command_topic[TOPSZ];
|
||||
|
||||
GetTopic_P(rgb_command_topic, CMND, mqtt_topic, D_CMND_COLOR);
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), HASS_DISCOVER_LIGHT_COLOR, mqtt_data, rgb_command_topic, state_topic);
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), Settings.flag3.hass_short_discovery_msg?HASS_DISCOVER_LIGHT_COLOR_SHORT:HASS_DISCOVER_LIGHT_COLOR,
|
||||
mqtt_data, rgb_command_topic, state_topic);
|
||||
/*
|
||||
char effect_command_topic[TOPSZ];
|
||||
|
||||
|
@ -129,7 +173,8 @@ void HAssDiscoverRelay(void)
|
|||
char color_temp_command_topic[TOPSZ];
|
||||
|
||||
GetTopic_P(color_temp_command_topic, CMND, mqtt_topic, D_CMND_COLORTEMPERATURE);
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), HASS_DISCOVER_LIGHT_CT, mqtt_data, color_temp_command_topic, state_topic);
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), Settings.flag3.hass_short_discovery_msg?HASS_DISCOVER_LIGHT_CT_SHORT:HASS_DISCOVER_LIGHT_CT,
|
||||
mqtt_data, color_temp_command_topic, state_topic);
|
||||
}
|
||||
}
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s}"), mqtt_data);
|
||||
|
@ -179,7 +224,8 @@ void HAssDiscoverButton(void)
|
|||
GetPowerDevice(value_template, button_index+1, sizeof(value_template), Settings.flag.device_index_enable);
|
||||
GetTopic_P(state_topic, CMND, key_topic, value_template); // State of button is sent as CMND TOGGLE
|
||||
GetTopic_P(availability_topic, TELE, mqtt_topic, S_LWT);
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), HASS_DISCOVER_BUTTON, name, state_topic, Settings.state_text[2], availability_topic);
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), Settings.flag3.hass_short_discovery_msg?HASS_DISCOVER_BUTTON_SHORT:HASS_DISCOVER_BUTTON,
|
||||
name, state_topic, Settings.state_text[2], availability_topic);
|
||||
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s}"), mqtt_data);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue