diff --git a/tasmota/i18n.h b/tasmota/i18n.h index cf0505eb7..4a2a03281 100644 --- a/tasmota/i18n.h +++ b/tasmota/i18n.h @@ -732,6 +732,8 @@ const char S_JSON_SENSOR_INDEX_SVALUE[] PROGMEM = "{\"" D_CMND_SENSO const char S_JSON_DRIVER_INDEX_NVALUE[] PROGMEM = "{\"" D_CMND_DRIVER "%d\":%d}"; const char S_JSON_DRIVER_INDEX_SVALUE[] PROGMEM = "{\"" D_CMND_DRIVER "%d\":\"%s\"}"; +const char S_JSON_SVALUE_ACTION_SVALUE[] PROGMEM = "{\"%s\":{\"Action\":\"%s\"}}"; + const char JSON_SNS_TEMP[] PROGMEM = ",\"%s\":{\"" D_JSON_TEMPERATURE "\":%s}"; const char JSON_SNS_ILLUMINANCE[] PROGMEM = ",\"%s\":{\"" D_JSON_ILLUMINANCE "\":%d}"; diff --git a/tasmota/support_button.ino b/tasmota/support_button.ino index ef894fcf1..39fdc407c 100644 --- a/tasmota/support_button.ino +++ b/tasmota/support_button.ino @@ -373,10 +373,10 @@ void MqttButtonTopic(uint32_t button_id, uint32_t action, uint32_t hold) { SendKey(KEY_BUTTON, button_id, (hold) ? 3 : action +9); if (!Settings.flag.hass_discovery) { // SetOption19 - Control Home Assistant automatic discovery (See SetOption59) - char mqttstate[7]; - Response_P(PSTR("{\"" D_JSON_BUTTON "%d\":{\"Action\":\"%s\"}}"), button_id, (hold) ? SettingsText(SET_STATE_TXT4) : GetTextIndexed(mqttstate, sizeof(mqttstate), action, kMultiPress)); char scommand[10]; - snprintf_P(scommand, sizeof(scommand), PSTR("BUTTON%d"), button_id); + snprintf_P(scommand, sizeof(scommand), PSTR(D_JSON_BUTTON "%d"), button_id); + char mqttstate[7]; + Response_P(S_JSON_SVALUE_ACTION_SVALUE, scommand, (hold) ? SettingsText(SET_STATE_TXT4) : GetTextIndexed(mqttstate, sizeof(mqttstate), action, kMultiPress)); MqttPublishPrefixTopicRulesProcess_P(RESULT_OR_STAT, scommand); } } diff --git a/tasmota/support_switch.ino b/tasmota/support_switch.ino index 6315f512f..313b45408 100644 --- a/tasmota/support_switch.ino +++ b/tasmota/support_switch.ino @@ -426,9 +426,9 @@ void SwitchHandler(uint32_t mode) { } else { GetTextIndexed(mqtt_state_str, sizeof(mqtt_state_str), mqtt_action, kSwitchPressStates); } - Response_P(PSTR("{\"%s\":{\"Action\":\"%s\"}}"), GetSwitchText(i).c_str(), mqtt_state); + Response_P(S_JSON_SVALUE_ACTION_SVALUE, GetSwitchText(i).c_str(), mqtt_state); char scommand[10]; - snprintf_P(scommand, sizeof(scommand), PSTR("SWITCH%d"), i +1); + snprintf_P(scommand, sizeof(scommand), PSTR(D_JSON_SWITCH "%d"), i +1); MqttPublishPrefixTopicRulesProcess_P(RESULT_OR_STAT, scommand); } mqtt_action = POWER_NONE; diff --git a/tasmota/xdrv_02_mqtt.ino b/tasmota/xdrv_02_mqtt.ino index b976dd843..857857d5f 100644 --- a/tasmota/xdrv_02_mqtt.ino +++ b/tasmota/xdrv_02_mqtt.ino @@ -352,13 +352,11 @@ void MqttPublishPrefixTopic_P(uint32_t prefix, const char* subtopic, bool retain * prefix 6 = tele using subtopic or RESULT */ char romram[64]; - char stopic[TOPSZ]; - snprintf_P(romram, sizeof(romram), ((prefix > 3) && !Settings.flag.mqtt_response) ? S_RSLT_RESULT : subtopic); // SetOption4 - Switch between MQTT RESULT or COMMAND - for (uint32_t i = 0; i < strlen(romram); i++) { - romram[i] = toupper(romram[i]); - } + UpperCase(romram, romram); + prefix &= 3; + char stopic[TOPSZ]; GetTopic_P(stopic, prefix, TasmotaGlobal.mqtt_topic, romram); MqttPublish(stopic, retained);