mirror of https://github.com/arendst/Tasmota.git
Refactor Sensor MQTT data adding rule support
This commit is contained in:
parent
b2e6a2fe75
commit
48e15216be
|
@ -851,7 +851,14 @@ void PerformEverySecond(void)
|
|||
tele_period = 0;
|
||||
|
||||
MqttPublishTeleState();
|
||||
MqttPublishSensor();
|
||||
|
||||
mqtt_data[0] = '\0';
|
||||
if (MqttShowSensor()) {
|
||||
MqttPublishPrefixTopic_P(TELE, PSTR(D_RSLT_SENSOR), Settings.flag.mqtt_sensor_retain); // CMND_SENSORRETAIN
|
||||
#if defined(USE_RULES) || defined(USE_SCRIPT)
|
||||
RulesTeleperiod(); // Allow rule based HA messages
|
||||
#endif // USE_RULES
|
||||
}
|
||||
|
||||
XdrvCall(FUNC_AFTER_TELEPERIOD);
|
||||
}
|
||||
|
|
|
@ -432,9 +432,7 @@ void MqttPublishPrefixTopic_P(uint32_t prefix, const char* subtopic)
|
|||
void MqttPublishTeleSensor(void)
|
||||
{
|
||||
MqttPublishPrefixTopic_P(TELE, PSTR(D_RSLT_SENSOR), Settings.flag.mqtt_sensor_retain); // CMND_SENSORRETAIN
|
||||
#if defined(USE_RULES) || defined(USE_SCRIPT)
|
||||
RulesTeleperiod(); // Allow rule based HA messages
|
||||
#endif // USE_RULES
|
||||
XdrvRulesProcess();
|
||||
}
|
||||
|
||||
void MqttPublishPowerState(uint32_t device)
|
||||
|
|
|
@ -425,7 +425,7 @@ void EnergyMqttShow(void)
|
|||
EnergyShow(true);
|
||||
tele_period = tele_period_save;
|
||||
ResponseJsonEnd();
|
||||
MqttPublishPrefixTopic_P(TELE, PSTR(D_RSLT_SENSOR), Settings.flag.mqtt_sensor_retain); // CMND_SENSORRETAIN
|
||||
MqttPublishTeleSensor();
|
||||
Energy.power_delta = false;
|
||||
}
|
||||
#endif // USE_ENERGY_MARGIN_DETECTION
|
||||
|
|
|
@ -181,7 +181,7 @@ void PCA9685_OutputTelemetry(bool telemetry) {
|
|||
}
|
||||
ResponseAppend_P(PSTR("\"END\":1}}"));
|
||||
if (telemetry) {
|
||||
MqttPublishPrefixTopic_P(TELE, PSTR(D_RSLT_SENSOR), Settings.flag.mqtt_sensor_retain); // CMND_SENSORRETAIN
|
||||
MqttPublishTeleSensor();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -126,7 +126,7 @@ void ILI9488_InitDriver()
|
|||
#ifdef USE_TOUCH_BUTTONS
|
||||
void ILI9488_MQTT(uint8_t count,const char *cp) {
|
||||
ResponseTime_P(PSTR(",\"RA8876\":{\"%s%d\":\"%d\"}}"), cp,count+1,(buttons[count]->vpower&0x80)>>7);
|
||||
MqttPublishPrefixTopic_P(TELE, PSTR(D_RSLT_SENSOR), Settings.flag.mqtt_sensor_retain); // CMND_SENSORRETAIN
|
||||
MqttPublishTeleSensor();
|
||||
}
|
||||
|
||||
void ILI9488_RDW_BUTT(uint32_t count,uint32_t pwr) {
|
||||
|
|
|
@ -111,7 +111,7 @@ void RA8876_InitDriver()
|
|||
#ifdef USE_TOUCH_BUTTONS
|
||||
void RA8876_MQTT(uint8_t count,const char *cp) {
|
||||
ResponseTime_P(PSTR(",\"RA8876\":{\"%s%d\":\"%d\"}}"), cp,count+1,(buttons[count]->vpower&0x80)>>7);
|
||||
MqttPublishPrefixTopic_P(TELE, PSTR(D_RSLT_SENSOR), Settings.flag.mqtt_sensor_retain); // CMND_SENSORRETAIN
|
||||
MqttPublishTeleSensor();
|
||||
}
|
||||
|
||||
void RA8876_RDW_BUTT(uint32_t count,uint32_t pwr) {
|
||||
|
|
|
@ -742,7 +742,7 @@ void MCP230xx_OutputTelemetry(void) {
|
|||
}
|
||||
}
|
||||
ResponseAppend_P(PSTR("\"END\":1}}"));
|
||||
MqttPublishPrefixTopic_P(TELE, PSTR(D_RSLT_SENSOR), Settings.flag.mqtt_sensor_retain); // CMND_SENSORRETAIN
|
||||
MqttPublishTeleSensor();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -757,7 +757,7 @@ void MCP230xx_Interrupt_Counter_Report(void) {
|
|||
}
|
||||
}
|
||||
ResponseAppend_P(PSTR("\"END\":1}}"));
|
||||
MqttPublishPrefixTopic_P(TELE, PSTR(D_RSLT_SENSOR), Settings.flag.mqtt_sensor_retain); // CMND_SENSORRETAIN
|
||||
MqttPublishTeleSensor();
|
||||
mcp230xx_int_sec_counter = 0;
|
||||
}
|
||||
|
||||
|
@ -772,7 +772,7 @@ void MCP230xx_Interrupt_Retain_Report(void) {
|
|||
}
|
||||
}
|
||||
ResponseAppend_P(PSTR("\"Value\":%u}}"),retainresult);
|
||||
MqttPublishPrefixTopic_P(TELE, PSTR(D_RSLT_SENSOR), Settings.flag.mqtt_sensor_retain); // CMND_SENSORRETAIN
|
||||
MqttPublishTeleSensor();
|
||||
}
|
||||
|
||||
/*********************************************************************************************\
|
||||
|
|
|
@ -360,7 +360,7 @@ void HxEvery100mSecond(void)
|
|||
ResponseAppendTime();
|
||||
HxShow(true);
|
||||
ResponseJsonEnd();
|
||||
MqttPublishPrefixTopic_P(TELE, PSTR(D_RSLT_SENSOR), Settings.flag.mqtt_sensor_retain); // CMND_SENSORRETAIN
|
||||
MqttPublishTeleSensor();
|
||||
Hx.weight_changed = false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -500,7 +500,7 @@ void PN532_ScanForTag(void)
|
|||
ResponseTime_P(PSTR(",\"PN532\":{\"UID\":\"%s\"}}"), uids);
|
||||
#endif // USE_PN532_DATA_FUNCTION
|
||||
|
||||
MqttPublishPrefixTopic_P(TELE, PSTR(D_RSLT_SENSOR), Settings.flag.mqtt_sensor_retain); // CMND_SENSORRETAIN
|
||||
MqttPublishTeleSensor();
|
||||
|
||||
#ifdef USE_PN532_CAUSE_EVENTS
|
||||
|
||||
|
|
|
@ -254,7 +254,7 @@ void SPS30_Show(bool json) {
|
|||
void CmdClean(void) {
|
||||
sps30_cmd(SPS_CMD_CLEAN);
|
||||
ResponseTime_P(PSTR(",\"SPS30\":{\"CFAN\":\"true\"}}"));
|
||||
MqttPublishPrefixTopic_P(TELE, PSTR(D_RSLT_SENSOR), Settings.flag.mqtt_sensor_retain); // CMND_SENSORRETAIN
|
||||
MqttPublishTeleSensor();
|
||||
}
|
||||
|
||||
bool SPS30_cmd(void) {
|
||||
|
|
|
@ -107,7 +107,7 @@ void RDM6300_ScanForTag() {
|
|||
rdm_uid_str[9]=0;
|
||||
|
||||
ResponseTime_P(PSTR(",\"RDM6300\":{\"UID\":\"%s\"}}"), rdm_uid_str);
|
||||
MqttPublishPrefixTopic_P(TELE, PSTR(D_RSLT_SENSOR), Settings.flag.mqtt_sensor_retain); // CMND_SENSORRETAIN
|
||||
MqttPublishTeleSensor();
|
||||
/*
|
||||
char command[24];
|
||||
sprintf(command,"event RDM6300=%s",rdm_uid_str);
|
||||
|
|
|
@ -548,7 +548,7 @@ void ibeacon_mqtt(const char *mac,const char *rssi) {
|
|||
s_rssi[4]=0;
|
||||
int16_t n_rssi=atoi(s_rssi);
|
||||
ResponseTime_P(PSTR(",\"" D_CMND_IBEACON "_%s\":{\"RSSI\":%d}}"),s_mac,n_rssi);
|
||||
MqttPublishPrefixTopic_P(TELE, PSTR(D_RSLT_SENSOR), Settings.flag.mqtt_sensor_retain); // CMND_SENSORRETAIN
|
||||
MqttPublishTeleSensor();
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1621,7 +1621,7 @@ void SML_Immediate_MQTT(const char *mp,uint8_t index,uint8_t mindex) {
|
|||
// immediate mqtt
|
||||
dtostrfd(meter_vars[index],dp&0xf,tpowstr);
|
||||
ResponseTime_P(PSTR(",\"%s\":{\"%s\":%s}}"),meter_desc_p[mindex].prefix,jname,tpowstr);
|
||||
MqttPublishPrefixTopic_P(TELE, PSTR(D_RSLT_SENSOR), Settings.flag.mqtt_sensor_retain); // CMND_SENSORRETAIN
|
||||
MqttPublishTeleSensor();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue