Add more rule triggers

This commit is contained in:
Theo Arends 2021-04-07 15:07:05 +02:00
parent 4c1011d0aa
commit 2f5c20a42f
24 changed files with 81 additions and 95 deletions

View File

@ -1295,7 +1295,7 @@ void DumpConvertTable(void) {
jsflg = true;
if ((ResponseAppend_P(PSTR("\"%d\":\"%d\""), i, data) > (MAX_LOGSZ - TOPSZ)) || (i == nitems(kGpioConvert) -1)) {
ResponseJsonEndEnd();
MqttPublishPrefixTopic_P(RESULT_OR_STAT, XdrvMailbox.command);
MqttPublishPrefixTopicRulesProcess_P(RESULT_OR_STAT, XdrvMailbox.command);
jsflg = false;
lines++;
}
@ -1310,7 +1310,7 @@ void DumpConvertTable(void) {
jsflg = true;
if ((ResponseAppend_P(PSTR("\"%d\":\"%d\""), i, data) > (MAX_LOGSZ - TOPSZ)) || (i == nitems(kAdcNiceList) -1)) {
ResponseJsonEndEnd();
MqttPublishPrefixTopic_P(RESULT_OR_STAT, XdrvMailbox.command);
MqttPublishPrefixTopicRulesProcess_P(RESULT_OR_STAT, XdrvMailbox.command);
jsflg = false;
lines++;
}

View File

@ -130,7 +130,7 @@ void ResponseCmndAll(uint32_t text_index, uint32_t count) {
if ((SET_MQTT_GRP_TOPIC == text_index) && (1 == i)) { real_index = SET_MQTT_GRP_TOPIC2 -1; }
if ((ResponseAppend_P(PSTR("%c\"%s%d\":\"%s\""), (jsflg)?',':'{', XdrvMailbox.command, i +1, EscapeJSONString(SettingsText(real_index +i)).c_str()) > (MAX_LOGSZ - TOPSZ)) || (i == count -1)) {
ResponseJsonEnd();
MqttPublishPrefixTopic_P(RESULT_OR_STAT, XdrvMailbox.command);
MqttPublishPrefixTopicRulesProcess_P(RESULT_OR_STAT, XdrvMailbox.command);
ResponseClear();
jsflg = false;
} else {
@ -399,6 +399,12 @@ void CmndPower(void)
}
}
void CmndStatusResponse(uint32_t index) {
char cmnd_status[10]; // STATUS11
snprintf_P(cmnd_status, sizeof(cmnd_status), PSTR(D_CMND_STATUS "%d"), index);
MqttPublishPrefixTopicRulesProcess_P(STAT, cmnd_status);
}
void CmndStatus(void)
{
int32_t payload = XdrvMailbox.payload;
@ -442,7 +448,7 @@ void CmndStatus(void)
Settings.flag.mqtt_power_retain, // CMND_POWERRETAIN
Settings.flag5.mqtt_info_retain, // CMND_INFORETAIN
Settings.flag5.mqtt_state_retain); // CMND_STATERETAIN
MqttPublishPrefixTopic_P(STAT, PSTR(D_CMND_STATUS));
MqttPublishPrefixTopicRulesProcess_P(STAT, PSTR(D_CMND_STATUS));
}
if ((0 == payload) || (1 == payload)) {
@ -460,7 +466,7 @@ void CmndStatus(void)
, GetSettingsAddress()
#endif
);
MqttPublishPrefixTopic_P(STAT, PSTR(D_CMND_STATUS "1"));
CmndStatusResponse(1);
}
if ((0 == payload) || (2 == payload)) {
@ -478,7 +484,7 @@ void CmndStatus(void)
, ESP.getSdkVersion(),
ESP.getCpuFreqMHz(), GetDeviceHardware().c_str(),
GetStatistics().c_str());
MqttPublishPrefixTopic_P(STAT, PSTR(D_CMND_STATUS "2"));
CmndStatusResponse(2);
}
if ((0 == payload) || (3 == payload)) {
@ -489,7 +495,7 @@ void CmndStatus(void)
SettingsText(SET_SYSLOG_HOST), Settings.syslog_port, EscapeJSONString(SettingsText(SET_STASSID1)).c_str(), EscapeJSONString(SettingsText(SET_STASSID2)).c_str(), Settings.tele_period,
Settings.flag2.data, Settings.flag.data, ToHex_P((unsigned char*)Settings.param, PARAM8_SIZE, stemp2, sizeof(stemp2)),
Settings.flag3.data, Settings.flag4.data, Settings.flag5.data);
MqttPublishPrefixTopic_P(STAT, PSTR(D_CMND_STATUS "3"));
CmndStatusResponse(3);
}
if ((0 == payload) || (4 == payload)) {
@ -516,7 +522,7 @@ void CmndStatus(void)
ResponseAppend_P(PSTR(",\"Sensors\":"));
XsnsSensorState();
ResponseJsonEndEnd();
MqttPublishPrefixTopic_P(STAT, PSTR(D_CMND_STATUS "4"));
CmndStatusResponse(4);
}
if ((0 == payload) || (5 == payload)) {
@ -526,7 +532,7 @@ void CmndStatus(void)
NetworkHostname(), (uint32_t)NetworkAddress(),
Settings.ipv4_address[1], Settings.ipv4_address[2], Settings.ipv4_address[3],
NetworkMacAddress().c_str(), Settings.webserver, Settings.sta_config, WifiGetOutputPower().c_str());
MqttPublishPrefixTopic_P(STAT, PSTR(D_CMND_STATUS "5"));
CmndStatusResponse(5);
}
if (((0 == payload) || (6 == payload)) && Settings.flag.mqtt_enabled) { // SetOption3 - Enable MQTT
@ -534,7 +540,7 @@ void CmndStatus(void)
D_CMND_MQTTCLIENT "\":\"%s\",\"" D_CMND_MQTTUSER "\":\"%s\",\"" D_JSON_MQTT_COUNT "\":%d,\"MAX_PACKET_SIZE\":%d,\"KEEPALIVE\":%d,\"SOCKET_TIMEOUT\":%d}}"),
SettingsText(SET_MQTT_HOST), Settings.mqtt_port, EscapeJSONString(SettingsText(SET_MQTT_CLIENT)).c_str(),
TasmotaGlobal.mqtt_client, EscapeJSONString(SettingsText(SET_MQTT_USER)).c_str(), MqttConnectCount(), MQTT_MAX_PACKET_SIZE, Settings.mqtt_keepalive, Settings.mqtt_socket_timeout);
MqttPublishPrefixTopic_P(STAT, PSTR(D_CMND_STATUS "6"));
CmndStatusResponse(6);
}
if ((0 == payload) || (7 == payload)) {
@ -554,7 +560,7 @@ void CmndStatus(void)
GetDateAndTime(DT_UTC).c_str(), GetDateAndTime(DT_LOCALNOTZ).c_str(), GetDateAndTime(DT_DST).c_str(),
GetDateAndTime(DT_STD).c_str(), stemp);
#endif // USE_TIMERS and USE_SUNRISE
MqttPublishPrefixTopic_P(STAT, PSTR(D_CMND_STATUS "7"));
CmndStatusResponse(7);
}
#if defined(USE_ENERGY_SENSOR) && defined(USE_ENERGY_MARGIN_DETECTION)
@ -564,7 +570,7 @@ void CmndStatus(void)
D_CMND_VOLTAGELOW "\":%d,\"" D_CMND_VOLTAGEHIGH "\":%d,\"" D_CMND_CURRENTLOW "\":%d,\"" D_CMND_CURRENTHIGH "\":%d}}"),
Settings.energy_power_delta[0], Settings.energy_power_delta[1], Settings.energy_power_delta[2], Settings.energy_min_power, Settings.energy_max_power,
Settings.energy_min_voltage, Settings.energy_max_voltage, Settings.energy_min_current, Settings.energy_max_current);
MqttPublishPrefixTopic_P(STAT, PSTR(D_CMND_STATUS "9"));
CmndStatusResponse(9);
}
}
#endif // USE_ENERGY_MARGIN_DETECTION
@ -573,18 +579,14 @@ void CmndStatus(void)
Response_P(PSTR("{\"" D_CMND_STATUS D_STATUS10_SENSOR "\":"));
MqttShowSensor();
ResponseJsonEnd();
if (8 == payload) {
MqttPublishPrefixTopic_P(STAT, PSTR(D_CMND_STATUS "8"));
} else {
MqttPublishPrefixTopic_P(STAT, PSTR(D_CMND_STATUS "10"));
}
CmndStatusResponse((8 == payload) ? 8 : 10);
}
if ((0 == payload) || (11 == payload)) {
Response_P(PSTR("{\"" D_CMND_STATUS D_STATUS11_STATUS "\":"));
MqttShowState();
ResponseJsonEnd();
MqttPublishPrefixTopic_P(STAT, PSTR(D_CMND_STATUS "11"));
CmndStatusResponse(11);
}
if (CrashFlag()) {
@ -592,7 +594,7 @@ void CmndStatus(void)
Response_P(PSTR("{\"" D_CMND_STATUS D_STATUS12_STATUS "\":"));
CrashDump();
ResponseJsonEnd();
MqttPublishPrefixTopic_P(STAT, PSTR(D_CMND_STATUS "12"));
CmndStatusResponse(12);
}
}
@ -613,7 +615,7 @@ void CmndStatus(void)
Settings.shutter_mode);
}
ResponseJsonEndEnd();
MqttPublishPrefixTopic_P(STAT, PSTR(D_CMND_STATUS "13"));
CmndStatusResponse(13);
}
}
#endif
@ -622,10 +624,6 @@ void CmndStatus(void)
if (bitRead(Settings.rule_enabled, 0)) { Run_Scripter(">U", 2, TasmotaGlobal.mqtt_data); }
#endif
if (payload) {
XdrvRulesProcess(0); // Allow rule processing on single Status command only
}
ResponseClear();
}
@ -1192,7 +1190,7 @@ void CmndModules(void)
uint32_t j = i ? midx +1 : 0;
if ((ResponseAppend_P(PSTR("\"%d\":\"%s\""), j, AnyModuleName(midx).c_str()) > (MAX_LOGSZ - TOPSZ)) || (i == sizeof(kModuleNiceList))) {
ResponseJsonEndEnd();
MqttPublishPrefixTopic_P(RESULT_OR_STAT, XdrvMailbox.command);
MqttPublishPrefixTopicRulesProcess_P(RESULT_OR_STAT, XdrvMailbox.command);
jsflg = false;
lines++;
}
@ -1260,7 +1258,7 @@ void CmndGpio(void)
char stemp1[TOPSZ];
if ((ResponseAppend_P(PSTR("\"" D_CMND_GPIO "%d\":{\"%d\":\"%s%s\"}"), i, sensor_type, GetTextIndexed(stemp1, sizeof(stemp1), sensor_name_idx, sensor_names), sindex) > (MAX_LOGSZ - TOPSZ))) {
ResponseJsonEnd();
MqttPublishPrefixTopic_P(RESULT_OR_STAT, XdrvMailbox.command);
MqttPublishPrefixTopicRulesProcess_P(RESULT_OR_STAT, XdrvMailbox.command);
ResponseClear();
jsflg2 = true;
jsflg = false;
@ -1298,7 +1296,7 @@ void ShowGpios(const uint16_t *NiceList, uint32_t size, uint32_t offset, uint32_
char stemp1[TOPSZ];
if ((ResponseAppend_P(PSTR("\"%d\":\"%s\""), ridx, GetTextIndexed(stemp1, sizeof(stemp1), midx, kSensorNames)) > (MAX_LOGSZ - TOPSZ)) || (i == size -1)) {
ResponseJsonEndEnd();
MqttPublishPrefixTopic_P(RESULT_OR_STAT, XdrvMailbox.command);
MqttPublishPrefixTopicRulesProcess_P(RESULT_OR_STAT, XdrvMailbox.command);
jsflg = false;
lines++;
}

View File

@ -1188,7 +1188,7 @@ void Every250mSeconds(void)
}
ResponseAppend_P(PSTR("\"}"));
// TasmotaGlobal.restart_flag = 2; // Restart anyway to keep memory clean webserver
MqttPublishPrefixTopic_P(STAT, PSTR(D_CMND_UPGRADE));
MqttPublishPrefixTopicRulesProcess_P(STAT, PSTR(D_CMND_UPGRADE));
#ifdef USE_COUNTER
CounterInterruptDisable(false);
#endif // USE_COUNTER

View File

@ -2893,13 +2893,12 @@ int WebSend(char *buffer)
}
}
TasmotaGlobal.mqtt_data[j] = '\0';
MqttPublishPrefixTopic_P(RESULT_OR_STAT, PSTR(D_CMND_WEBSEND));
#ifdef USE_SCRIPT
extern uint8_t tasm_cmd_activ;
extern uint8_t tasm_cmd_activ;
// recursive call must be possible in this case
tasm_cmd_activ=0;
XdrvRulesProcess(0);
tasm_cmd_activ = 0;
#endif // USE_SCRIPT
MqttPublishPrefixTopicRulesProcess_P(RESULT_OR_STAT, PSTR(D_CMND_WEBSEND));
#endif // USE_WEBSEND_RESPONSE
}
status = 0; // No error - Done

View File

@ -487,7 +487,7 @@ void MqttPublishPowerBlinkState(uint32_t device) {
Response_P(PSTR("{\"%s\":\"" D_JSON_BLINK " %s\"}"),
GetPowerDevice(scommand, device, sizeof(scommand), Settings.flag.device_index_enable), GetStateText(bitRead(TasmotaGlobal.blink_mask, device -1))); // SetOption26 - Switch between POWER or POWER1
MqttPublishPrefixTopic_P(RESULT_OR_STAT, S_RSLT_POWER);
MqttPublishPrefixTopicRulesProcess_P(RESULT_OR_STAT, S_RSLT_POWER);
}
/*********************************************************************************************/
@ -553,7 +553,7 @@ void MqttConnected(void) {
char stopic2[TOPSZ];
Response_P(PSTR("{\"" D_CMND_MODULE "\":\"%s\",\"" D_JSON_VERSION "\":\"%s%s\",\"" D_JSON_FALLBACKTOPIC "\":\"%s\",\"" D_CMND_GROUPTOPIC "\":\"%s\"}"),
ModuleName().c_str(), TasmotaGlobal.version, TasmotaGlobal.image_name, GetFallbackTopic_P(stopic, ""), GetGroupTopic_P(stopic2, "", SET_MQTT_GRP_TOPIC));
MqttPublishPrefixTopic_P(TELE, PSTR(D_RSLT_INFO "1"), Settings.flag5.mqtt_info_retain);
MqttPublishPrefixTopicRulesProcess_P(TELE, PSTR(D_RSLT_INFO "1"), Settings.flag5.mqtt_info_retain);
#ifdef USE_WEBSERVER
if (Settings.webserver) {
#if LWIP_IPV6
@ -563,7 +563,7 @@ void MqttConnected(void) {
Response_P(PSTR("{\"" D_JSON_WEBSERVER_MODE "\":\"%s\",\"" D_CMND_HOSTNAME "\":\"%s\",\"" D_CMND_IPADDRESS "\":\"%s\"}"),
(2 == Settings.webserver) ? PSTR(D_ADMIN) : PSTR(D_USER), NetworkHostname(), NetworkAddress().toString().c_str(), Settings.flag5.mqtt_info_retain);
#endif // LWIP_IPV6 = 1
MqttPublishPrefixTopic_P(TELE, PSTR(D_RSLT_INFO "2"), Settings.flag5.mqtt_info_retain);
MqttPublishPrefixTopicRulesProcess_P(TELE, PSTR(D_RSLT_INFO "2"), Settings.flag5.mqtt_info_retain);
}
#endif // USE_WEBSERVER
Response_P(PSTR("{\"" D_JSON_RESTARTREASON "\":"));
@ -573,7 +573,7 @@ void MqttConnected(void) {
ResponseAppend_P(PSTR("\"%s\""), GetResetReason().c_str());
}
ResponseJsonEnd();
MqttPublishPrefixTopic_P(TELE, PSTR(D_RSLT_INFO "3"), Settings.flag5.mqtt_info_retain);
MqttPublishPrefixTopicRulesProcess_P(TELE, PSTR(D_RSLT_INFO "3"), Settings.flag5.mqtt_info_retain);
}
MqttPublishAllPowerState();

View File

@ -428,7 +428,7 @@ void EnergyMarginCheck(void)
Energy.mplh_counter--;
if (!Energy.mplh_counter) {
ResponseTime_P(PSTR(",\"" D_JSON_MAXPOWERREACHED "\":%d}"), energy_power_u);
MqttPublishPrefixTopic_P(STAT, S_RSLT_WARNING);
MqttPublishPrefixTopicRulesProcess_P(STAT, S_RSLT_WARNING);
EnergyMqttShow();
SetAllPower(POWER_ALL_OFF, SRC_MAXPOWER);
if (!Energy.mplr_counter) {
@ -451,11 +451,11 @@ void EnergyMarginCheck(void)
Energy.mplr_counter--;
if (Energy.mplr_counter) {
ResponseTime_P(PSTR(",\"" D_JSON_POWERMONITOR "\":\"%s\"}"), GetStateText(1));
MqttPublishPrefixTopic_P(RESULT_OR_STAT, PSTR(D_JSON_POWERMONITOR));
MqttPublishPrefixTopicRulesProcess_P(RESULT_OR_STAT, PSTR(D_JSON_POWERMONITOR));
RestorePower(true, SRC_MAXPOWER);
} else {
ResponseTime_P(PSTR(",\"" D_JSON_MAXPOWERREACHEDRETRY "\":\"%s\"}"), GetStateText(0));
MqttPublishPrefixTopic_P(STAT, S_RSLT_WARNING);
MqttPublishPrefixTopicRulesProcess_P(STAT, S_RSLT_WARNING);
EnergyMqttShow();
SetAllPower(POWER_ALL_OFF, SRC_MAXPOWER);
}
@ -470,13 +470,13 @@ void EnergyMarginCheck(void)
if (!Energy.max_energy_state && (RtcTime.hour == Settings.energy_max_energy_start)) {
Energy.max_energy_state = 1;
ResponseTime_P(PSTR(",\"" D_JSON_ENERGYMONITOR "\":\"%s\"}"), GetStateText(1));
MqttPublishPrefixTopic_P(RESULT_OR_STAT, PSTR(D_JSON_ENERGYMONITOR));
MqttPublishPrefixTopicRulesProcess_P(RESULT_OR_STAT, PSTR(D_JSON_ENERGYMONITOR));
RestorePower(true, SRC_MAXENERGY);
}
else if ((1 == Energy.max_energy_state ) && (energy_daily_u >= Settings.energy_max_energy)) {
Energy.max_energy_state = 2;
ResponseTime_P(PSTR(",\"" D_JSON_MAXENERGYREACHED "\":%3_f}"), &Energy.daily);
MqttPublishPrefixTopic_P(STAT, S_RSLT_WARNING);
MqttPublishPrefixTopicRulesProcess_P(STAT, S_RSLT_WARNING);
EnergyMqttShow();
SetAllPower(POWER_ALL_OFF, SRC_MAXENERGY);
}

View File

@ -3093,7 +3093,7 @@ void CmndUndocA(void)
LightGetColor(scolor, true); // force hex whatever Option 17
scolor[6] = '\0'; // RGB only
Response_P(PSTR("%s,%d,%d,%d,%d,%d"), scolor, Settings.light_fade, Settings.light_correction, Settings.light_scheme, Settings.light_speed, Settings.light_width);
MqttPublishPrefixTopic_P(STAT, XdrvMailbox.topic);
MqttPublishPrefixTopicRulesProcess_P(STAT, XdrvMailbox.topic);
ResponseClear();
}

View File

@ -182,7 +182,7 @@ void SonoffBridgeLearnFailed(void)
{
SnfBridge.learn_active = 0;
Response_P(S_JSON_COMMAND_INDEX_SVALUE, D_CMND_RFKEY, SnfBridge.learn_key, D_JSON_LEARN_FAILED);
MqttPublishPrefixTopic_P(RESULT_OR_STAT, PSTR(D_CMND_RFKEY));
MqttPublishPrefixTopicRulesProcess_P(RESULT_OR_STAT, PSTR(D_CMND_RFKEY));
}
void SonoffBridgeReceived(void)
@ -208,7 +208,7 @@ void SonoffBridgeReceived(void)
Settings.rf_code[SnfBridge.learn_key][i] = TasmotaGlobal.serial_in_buffer[i +1];
}
Response_P(S_JSON_COMMAND_INDEX_SVALUE, D_CMND_RFKEY, SnfBridge.learn_key, D_JSON_LEARNED);
MqttPublishPrefixTopic_P(RESULT_OR_STAT, PSTR(D_CMND_RFKEY));
MqttPublishPrefixTopicRulesProcess_P(RESULT_OR_STAT, PSTR(D_CMND_RFKEY));
} else {
SonoffBridgeLearnFailed();
}

View File

@ -462,7 +462,7 @@ void CmndTimers(void)
}
ResponseCmndStateText(Settings.flag3.timers_enable); // CMND_TIMERS
MqttPublishPrefixTopic_P(RESULT_OR_STAT, XdrvMailbox.command);
MqttPublishPrefixTopicRulesProcess_P(RESULT_OR_STAT, XdrvMailbox.command);
uint32_t jsflg = 0;
uint32_t lines = 1;
@ -476,7 +476,7 @@ void CmndTimers(void)
PrepShowTimer(i +1);
if (jsflg > 3) {
ResponseJsonEndEnd();
MqttPublishPrefixTopic_P(RESULT_OR_STAT, PSTR(D_CMND_TIMERS));
MqttPublishPrefixTopicRulesProcess_P(RESULT_OR_STAT, PSTR(D_CMND_TIMERS));
jsflg = 0;
}
}

View File

@ -2067,7 +2067,7 @@ void CmndRule(void)
XdrvMailbox.index = i;
XdrvMailbox.data[0] = data; // Only 0 or "
CmndRule();
MqttPublishPrefixTopic_P(RESULT_OR_STAT, XdrvMailbox.command);
MqttPublishPrefixTopicRulesProcess_P(RESULT_OR_STAT, XdrvMailbox.command);
}
ResponseClear(); // Disable further processing
return;

View File

@ -1198,7 +1198,7 @@ void TuyaSerialInput(void)
snprintf_P(scommand, sizeof(scommand), PSTR("DpType%uId%u"), dpDataType, dpId);
if (dpDataType != 3 && dpDataType != 5) { Response_P(PSTR("%u"), DataVal); }
else { Response_P(PSTR("%s"), DataStr); }
MqttPublishPrefixTopic_P(STAT, scommand);
MqttPublishPrefixTopicRulesProcess_P(STAT, scommand);
}
}

View File

@ -889,11 +889,10 @@ void HueLightsCommand(uint8_t device, uint32_t device_id, String &response) {
LightSetBri(device, bri);
}
if (LST_COLDWARM <= local_light_subtype) {
MqttPublishPrefixTopic_P(RESULT_OR_STAT, PSTR(D_CMND_COLOR));
MqttPublishPrefixTopicRulesProcess_P(RESULT_OR_STAT, PSTR(D_CMND_COLOR));
} else {
MqttPublishPrefixTopic_P(RESULT_OR_STAT, PSTR(D_CMND_DIMMER));
MqttPublishPrefixTopicRulesProcess_P(RESULT_OR_STAT, PSTR(D_CMND_DIMMER));
}
XdrvRulesProcess(0);
}
change = false;
}

View File

@ -785,8 +785,7 @@ int32_t Z_ReceiveSimpleDesc(int32_t res, const SBuffer &buf) {
ResponseAppend_P(PSTR("\"0x%04X\""), buf.get16(numOutIndex + i*2));
}
ResponseAppend_P(PSTR("]}}"));
MqttPublishPrefixTopic_P(RESULT_OR_TELE, PSTR(D_JSON_ZIGBEEZCL_RECEIVED));
XdrvRulesProcess(0);
MqttPublishPrefixTopicRulesProcess_P(RESULT_OR_TELE, PSTR(D_JSON_ZIGBEEZCL_RECEIVED));
}
// If tuya protocol, change the model information

View File

@ -129,10 +129,10 @@ void DeepSleepPrepare(void)
// stat/tasmota/DEEPSLEEP = {"DeepSleep":{"Time":"2019-11-12T21:33:45","Epoch":1573590825}}
Response_P(PSTR("{\"" D_PRFX_DEEPSLEEP "\":{\"" D_JSON_TIME "\":\"%s\",\"Epoch\":%d}}"), (char*)dt.c_str(), RtcSettings.nextwakeup);
MqttPublishPrefixTopic_P(RESULT_OR_STAT, PSTR(D_PRFX_DEEPSLEEP));
MqttPublishPrefixTopicRulesProcess_P(RESULT_OR_STAT, PSTR(D_PRFX_DEEPSLEEP));
// Response_P(S_LWT_OFFLINE);
// MqttPublishPrefixTopic_P(TELE, PSTR(D_LWT), true); // Offline or remove previous retained topic
// MqttPublishPrefixTopicRulesProcess_P(TELE, PSTR(D_LWT), true); // Offline or remove previous retained topic
}
void DeepSleepStart(void)

View File

@ -620,7 +620,7 @@ void PWMDimmerHandleButton(uint32_t button_index, bool pressed)
// If we need to publish an MQTT trigger, do it.
if (mqtt_trigger) {
char topic[TOPSZ];
sprintf_P(TasmotaGlobal.mqtt_data, PSTR("Trigger%u"), mqtt_trigger);
Response_P(PSTR("Trigger%u"), mqtt_trigger);
#ifdef USE_DEVICE_GROUPS
if (Settings.flag4.device_groups_enabled) {
snprintf_P(topic, sizeof(topic), PSTR("cmnd/%s/EVENT"), device_groups[power_button_index].group_name);
@ -628,7 +628,7 @@ void PWMDimmerHandleButton(uint32_t button_index, bool pressed)
}
else
#endif // USE_DEVICE_GROUPS
MqttPublishPrefixTopic_P(CMND, PSTR("EVENT"));
MqttPublishPrefixTopicRulesProcess_P(CMND, PSTR("EVENT"));
}
// If we need to send a device group update, do it.

View File

@ -904,9 +904,7 @@ miel_hvac_publish_settings(struct miel_hvac_softc *sc)
ResponseAppend_P(PSTR("}"));
MqttPublishPrefixTopic_P(TELE, PSTR("HVACSettings"));
XdrvRulesProcess(0);
MqttPublishPrefixTopicRulesProcess_P(TELE, PSTR("HVACSettings"));
}
static void
@ -947,8 +945,7 @@ miel_hvac_data_response(struct miel_hvac_softc *sc,
Response_P(PSTR("{\"Bytes\":\"%s\"}"),
ToHex_P((uint8_t *)d, sizeof(*d), hex, sizeof(hex)));
MqttPublishPrefixTopic_P(TELE, PSTR("HVACData"));
XdrvRulesProcess(0);
MqttPublishPrefixTopicRulesProcess_P(TELE, PSTR("HVACData"));
}
static void

View File

@ -394,7 +394,7 @@ void PIDRun(void) {
char str_buf[FLOATSZ];
dtostrfd(power, 3, str_buf);
snprintf_P(TasmotaGlobal.mqtt_data, sizeof(TasmotaGlobal.mqtt_data), PSTR("{\"%s\":\"%s\"}"), "power", str_buf);
MqttPublishPrefixTopic_P(TELE, "PID", false);
MqttPublishPrefixTopicRulesProcess_P(TELE, "PID");
#endif // PID_DONT_USE_PID_TOPIC
#if defined PID_SHUTTER

View File

@ -1265,7 +1265,7 @@ void postAdvertismentDetails(){
// we got the data, give before MQTT call.
localmutex.give();
// no retain - this is present devices, not historic
MqttPublishPrefixTopic_P(TELE, PSTR("BLE"), 0);
MqttPublishPrefixTopicRulesProcess_P(TELE, PSTR("BLE"), 0);
} else {
}
}
@ -2305,8 +2305,8 @@ static void BLEEverySecond(bool restart){
// 2 seconds to go, post to BLE topic on MQTT our reason
if (BLERestartTasmota == 2){
if (!BLERestartTasmotaReason) BLERestartTasmotaReason = BLE_RESTART_TEAMOTA_REASON_UNKNOWN;
snprintf_P(TasmotaGlobal.mqtt_data, sizeof(TasmotaGlobal.mqtt_data), PSTR("{\"reboot\":\"%s\"}"), BLERestartTasmotaReason);
MqttPublishPrefixTopic_P(TELE, PSTR("BLE"), Settings.flag.mqtt_sensor_retain);
Response_P(PSTR("{\"reboot\":\"%s\"}"), BLERestartTasmotaReason);
MqttPublishPrefixTopicRulesProcess_P(TELE, PSTR("BLE"), Settings.flag.mqtt_sensor_retain);
AddLog(LOG_LEVEL_ERROR,PSTR("BLE: Failure! Restarting Tasmota in %d seconds because %s"), BLERestartTasmota, BLERestartTasmotaReason);
}
@ -2318,8 +2318,8 @@ static void BLEEverySecond(bool restart){
}
if (BLERestartBLEReason){ // just use the ptr as the trigger to send MQTT
snprintf_P(TasmotaGlobal.mqtt_data, sizeof(TasmotaGlobal.mqtt_data), PSTR("{\"blerestart\":\"%s\"}"), BLERestartBLEReason);
MqttPublishPrefixTopic_P(TELE, PSTR("BLE"), Settings.flag.mqtt_sensor_retain);
Response_P(PSTR("{\"blerestart\":\"%s\"}"), BLERestartBLEReason);
MqttPublishPrefixTopicRulesProcess_P(TELE, PSTR("BLE"), Settings.flag.mqtt_sensor_retain);
AddLog(LOG_LEVEL_ERROR,PSTR("BLE: Failure! Restarting BLE Stack because %s"), BLERestartBLEReason);
BLERestartBLEReason = nullptr;
}
@ -3154,11 +3154,7 @@ static void BLEPostMQTTSeenDevices(int type) {
do {
remains = getSeenDevicesToJson(dest, maxlen);
// no retain - this is present devices, not historic
if (type == 1){
MqttPublishPrefixTopic_P(TELE, PSTR("BLE"), 0);
} else {
MqttPublishPrefixTopic_P(STAT, PSTR("BLE"), 0);
}
MqttPublishPrefixTopicRulesProcess_P((1== type) ? TELE : STAT, PSTR("BLE"));
} while (remains);
// }
}
@ -3173,8 +3169,8 @@ static void BLEPostMQTT(bool onlycompleted) {
#endif
if (prepOperation && !onlycompleted){
std::string out = BLETriggerResponse(prepOperation);
snprintf_P(TasmotaGlobal.mqtt_data, sizeof(TasmotaGlobal.mqtt_data), PSTR("%s"), out.c_str());
MqttPublishPrefixTopic_P(TELE, PSTR("BLE"), Settings.flag.mqtt_sensor_retain);
Response_P(PSTR("%s"), out.c_str());
MqttPublishPrefixTopicRulesProcess_P(TELE, PSTR("BLE"), Settings.flag.mqtt_sensor_retain);
#ifdef BLE_ESP32_DEBUG
if (BLEDebugMode > 0) AddLog(LOG_LEVEL_INFO,PSTR("BLE: prep sent %s"), out.c_str());
#endif
@ -3193,8 +3189,8 @@ static void BLEPostMQTT(bool onlycompleted) {
} else {
std::string out = BLETriggerResponse(toSend);
localmutex.give();
snprintf_P(TasmotaGlobal.mqtt_data, sizeof(TasmotaGlobal.mqtt_data), PSTR("%s"), out.c_str());
MqttPublishPrefixTopic_P(TELE, PSTR("BLE"), Settings.flag.mqtt_sensor_retain);
Response_P(PSTR("%s"), out.c_str());
MqttPublishPrefixTopicRulesProcess_P(TELE, PSTR("BLE"), Settings.flag.mqtt_sensor_retain);
#ifdef BLE_ESP32_DEBUG
if (BLEDebugMode > 0) AddLog(LOG_LEVEL_INFO,PSTR("BLE: queued %d sent %s"), i, out.c_str());
#endif
@ -3215,8 +3211,8 @@ static void BLEPostMQTT(bool onlycompleted) {
} else {
std::string out = BLETriggerResponse(toSend);
localmutex.give();
snprintf_P(TasmotaGlobal.mqtt_data, sizeof(TasmotaGlobal.mqtt_data), PSTR("%s"), out.c_str());
MqttPublishPrefixTopic_P(TELE, PSTR("BLE"), Settings.flag.mqtt_sensor_retain);
Response_P(PSTR("%s"), out.c_str());
MqttPublishPrefixTopicRulesProcess_P(TELE, PSTR("BLE"), Settings.flag.mqtt_sensor_retain);
#ifdef BLE_ESP32_DEBUG
if (BLEDebugMode > 0) AddLog(LOG_LEVEL_INFO,PSTR("BLE: curr %d sent %s"), i, out.c_str());
#endif
@ -3238,8 +3234,8 @@ static void BLEPostMQTT(bool onlycompleted) {
if (BLEDebugMode > 0) AddLog(LOG_LEVEL_DEBUG,PSTR("BLE: mqttOperation removed opid %d"), toSend->opid);
#endif
std::string out = BLETriggerResponse(toSend);
snprintf_P(TasmotaGlobal.mqtt_data, sizeof(TasmotaGlobal.mqtt_data), PSTR("%s"), out.c_str());
MqttPublishPrefixTopic_P(TELE, PSTR("BLE"), Settings.flag.mqtt_sensor_retain);
Response_P(PSTR("%s"), out.c_str());
MqttPublishPrefixTopicRulesProcess_P(TELE, PSTR("BLE"), Settings.flag.mqtt_sensor_retain);
// we alreayd removed this from the queues, so now delete
delete toSend;
//break;
@ -3248,8 +3244,8 @@ static void BLEPostMQTT(bool onlycompleted) {
} while (1);
}
} else {
snprintf_P(TasmotaGlobal.mqtt_data, sizeof(TasmotaGlobal.mqtt_data), PSTR("{\"BLEOperation\":{}}"));
MqttPublishPrefixTopic_P(TELE, PSTR("BLE"), Settings.flag.mqtt_sensor_retain);
Response_P(PSTR("{\"BLEOperation\":{}}"));
MqttPublishPrefixTopicRulesProcess_P(TELE, PSTR("BLE"), Settings.flag.mqtt_sensor_retain);
}
}
@ -3363,7 +3359,7 @@ static void BLEShowStats(){
uint32_t deviceCount = seenDevices.size();
ResponseTime_P(PSTR(""));
ResponseAppend_P(PSTR(",\"BLE\":{\"scans\":%u,\"adverts\":%u,\"devices\":%u,\"resets\":%u}}"), BLEScanCount, totalCount, deviceCount, BLEResets);
MqttPublishPrefixTopic_P(TELE, PSTR("BLE"), 0);
MqttPublishPrefixTopicRulesProcess_P(TELE, PSTR("BLE"), 0);
}
@ -3378,7 +3374,7 @@ static void BLEShowStats(){
ResponseAppend_P(PSTR("{\"%s\":\"%s\"}"), tmp, aliases[i]->name);
}
ResponseAppend_P(PSTR("]}"));
MqttPublishPrefixTopic_P(TELE, PSTR("BLE"), Settings.flag.mqtt_sensor_retain);
MqttPublishPrefixTopicRulesProcess_P(TELE, PSTR("BLE"), Settings.flag.mqtt_sensor_retain);
}*/
void BLEAliasListResp(){

View File

@ -169,7 +169,7 @@ void ADPSCallback(uint8_t phase)
ResponseJsonEnd();
// Publish adding ADCO serial number into the topic
MqttPublishPrefixTopic_P(RESULT_OR_TELE, serialNumber, false);
MqttPublishPrefixTopicRulesProcess_P(RESULT_OR_TELE, serialNumber, false);
AddLog(LOG_LEVEL_INFO, PSTR("ADPS on phase %d"), phase);
}

View File

@ -1784,7 +1784,7 @@ void APDS9960_loop(void) {
enableGestureSensor();
APDS9960_overload = false;
Response_P(PSTR("{\"Gesture\":\"On\"}"));
MqttPublishPrefixTopic_P(RESULT_OR_TELE, TasmotaGlobal.mqtt_data); // only after the long break we report, that we are online again
MqttPublishPrefixTopicRulesProcess_P(RESULT_OR_TELE, TasmotaGlobal.mqtt_data); // only after the long break we report, that we are online again
gesture_mode = 1;
}
@ -1796,7 +1796,7 @@ void APDS9960_loop(void) {
disableGestureSensor();
recovery_loop_counter = APDS9960_LONG_RECOVERY; // long pause after overload/long press - number of stateloops
Response_P(PSTR("{\"Gesture\":\"Off\"}"));
MqttPublishPrefixTopic_P(RESULT_OR_TELE, TasmotaGlobal.mqtt_data);
MqttPublishPrefixTopicRulesProcess_P(RESULT_OR_TELE, TasmotaGlobal.mqtt_data);
gesture_mode = 0;
}
}

View File

@ -354,7 +354,7 @@ void MCP230xx_CheckForInterrupt(void) {
if (int_tele) {
ResponseTime_P(PSTR(",\"MCP230XX_INT\":{\"D%i\":%i,\"MS\":%lu}}"),
intp+(mcp230xx_port*8), ((mcp230xx_intcap >> intp) & 0x01),millis_since_last_int);
MqttPublishPrefixTopic_P(RESULT_OR_STAT, PSTR("MCP230XX_INT"));
MqttPublishPrefixTopicRulesProcess_P(RESULT_OR_STAT, PSTR("MCP230XX_INT"));
if (Settings.flag3.hass_tele_on_power) { // SetOption59 - Send tele/%topic%/SENSOR in addition to stat/%topic%/RESULT
MqttPublishSensor();
}

View File

@ -362,7 +362,7 @@ void Mpr121Show(struct mpr121 *pS, uint8_t function)
if ((FUNC_EVERY_50_MSECOND == function)
&& (BITC(i, j) != BITP(i, j))) {
Response_P(PSTR("{\"MPR121%c\":{\"Button%i\":%i}}"), pS->id[i], j, BITC(i, j));
MqttPublishPrefixTopic_P(RESULT_OR_STAT, TasmotaGlobal.mqtt_data);
MqttPublishPrefixTopicRulesProcess_P(RESULT_OR_STAT, PSTR("MPR121"));
}
// Add buttons to web string
#ifdef USE_WEBSERVER

View File

@ -148,7 +148,7 @@ void HxCalibrationStateTextJson(uint8_t msg_id)
Hx.calibrate_msg = msg_id;
Response_P(S_JSON_SENSOR_INDEX_SVALUE, XSNS_34, GetTextIndexed(cal_text, sizeof(cal_text), Hx.calibrate_msg, kHxCalibrationStates));
if (msg_id < 3) { MqttPublishPrefixTopic_P(RESULT_OR_STAT, PSTR("Sensor34")); }
if (msg_id < 3) { MqttPublishPrefixTopicRulesProcess_P(RESULT_OR_STAT, PSTR("Sensor34")); }
}
void SetWeightDelta()

View File

@ -2701,11 +2701,9 @@ void MI32ShowSomeSensors(){
cnt++;
}
ResponseAppend_P(PSTR("}"));
MqttPublishPrefixTopic_P(TELE, PSTR(D_RSLT_SENSOR), Settings.flag.mqtt_sensor_retain);
MqttPublishPrefixTopicRulesProcess_P(TELE, PSTR(D_RSLT_SENSOR), Settings.flag.mqtt_sensor_retain);
//AddLog(LOG_LEVEL_DEBUG,PSTR("M32: %s: show some %d %s"),D_CMND_MI32, MI32.mqttCurrentSlot, TasmotaGlobal.mqtt_data);
XdrvRulesProcess(1); // Allow rule based HA messages
#ifdef USE_HOME_ASSISTANT
if(hass_mode==2){
MI32.option.noSummary = _noSummarySave;
@ -3093,7 +3091,7 @@ void MI32ShowTriggeredSensors(){
}
AddLog(LOG_LEVEL_DEBUG,PSTR("M32: %s: triggered %d %s"),D_CMND_MI32, sensor, TasmotaGlobal.mqtt_data);
XdrvRulesProcess(1); // Allow rule based HA messages
XdrvRulesProcess(0);
} else { // else don't and clear
ResponseClear();