From 7b68935ae3953ebb542297131f37d92e36f8b196 Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Tue, 3 Nov 2020 16:05:57 +0100 Subject: [PATCH] Add index to Button and Switch action topics --- tasmota/support_button.ino | 4 +++- tasmota/support_switch.ino | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/tasmota/support_button.ino b/tasmota/support_button.ino index 4f7004aaf..ef894fcf1 100644 --- a/tasmota/support_button.ino +++ b/tasmota/support_button.ino @@ -375,7 +375,9 @@ void MqttButtonTopic(uint32_t button_id, uint32_t action, uint32_t hold) { 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)); - MqttPublishPrefixTopicRulesProcess_P(RESULT_OR_STAT, PSTR(D_JSON_BUTTON)); + char scommand[10]; + snprintf_P(scommand, sizeof(scommand), PSTR("BUTTON%d"), button_id); + MqttPublishPrefixTopicRulesProcess_P(RESULT_OR_STAT, scommand); } } diff --git a/tasmota/support_switch.ino b/tasmota/support_switch.ino index e5ab1ce77..6315f512f 100644 --- a/tasmota/support_switch.ino +++ b/tasmota/support_switch.ino @@ -427,7 +427,9 @@ void SwitchHandler(uint32_t mode) { GetTextIndexed(mqtt_state_str, sizeof(mqtt_state_str), mqtt_action, kSwitchPressStates); } Response_P(PSTR("{\"%s\":{\"Action\":\"%s\"}}"), GetSwitchText(i).c_str(), mqtt_state); - MqttPublishPrefixTopicRulesProcess_P(RESULT_OR_STAT, PSTR(D_JSON_SWITCH)); + char scommand[10]; + snprintf_P(scommand, sizeof(scommand), PSTR("SWITCH%d"), i +1); + MqttPublishPrefixTopicRulesProcess_P(RESULT_OR_STAT, scommand); } mqtt_action = POWER_NONE; }