Add index to Button and Switch action topics

This commit is contained in:
Theo Arends 2020-11-03 16:05:57 +01:00
parent 9f191d9214
commit 7b68935ae3
2 changed files with 6 additions and 2 deletions

View File

@ -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);
}
}

View File

@ -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;
}