mirror of
https://github.com/arendst/Tasmota.git
synced 2025-07-23 18:56:38 +00:00
Add rule support for IrReceive and RfReceive
5.14.0b * Add rule support for IrReceive and RfReceive (#2758)
This commit is contained in:
parent
ca08b77aad
commit
9f329d5fb0
@ -1,5 +1,6 @@
|
||||
/* 5.14.0b
|
||||
* Increase rule storage space to 3 rule sets of 512 characters using commands rule1, rule2 and rule3
|
||||
* Add two rule sets of 511 characters using commands rule1, rule2 and rule3
|
||||
* Add rule support for IrReceive and RfReceive (#2758)
|
||||
*
|
||||
* 5.14.0a
|
||||
* Add feature information to Status 4
|
||||
|
@ -889,7 +889,6 @@ void SettingsDelta()
|
||||
Settings.longitude = (int)((double)LONGITUDE * 1000000);
|
||||
}
|
||||
if (Settings.version < 0x050C000B) {
|
||||
// memset(&Settings.rules, 0x00, sizeof(Settings.rules));
|
||||
Settings.rules[0][0] = '\0';
|
||||
}
|
||||
if (Settings.version < 0x050C000D) {
|
||||
|
@ -188,7 +188,7 @@ enum LichtSubtypes {LST_NONE, LST_SINGLE, LST_COLDWARM, LST_RGB, LST_RGBW, LST_R
|
||||
enum LichtSchemes {LS_POWER, LS_WAKEUP, LS_CYCLEUP, LS_CYCLEDN, LS_RANDOM, LS_MAX};
|
||||
|
||||
enum XsnsFunctions {FUNC_INIT, FUNC_LOOP, FUNC_EVERY_50_MSECOND, FUNC_EVERY_SECOND, FUNC_PREP_BEFORE_TELEPERIOD, FUNC_JSON_APPEND, FUNC_WEB_APPEND, FUNC_SAVE_BEFORE_RESTART,
|
||||
FUNC_COMMAND, FUNC_MQTT_SUBSCRIBE, FUNC_MQTT_INIT, FUNC_MQTT_DATA, FUNC_SET_POWER, FUNC_SHOW_SENSOR};
|
||||
FUNC_COMMAND, FUNC_MQTT_SUBSCRIBE, FUNC_MQTT_INIT, FUNC_MQTT_DATA, FUNC_SET_POWER, FUNC_SHOW_SENSOR, FUNC_RULES_PROCESS};
|
||||
|
||||
const uint8_t kDefaultRfCode[9] PROGMEM = { 0x21, 0x16, 0x01, 0x0E, 0x03, 0x48, 0x2E, 0x1A, 0x00 };
|
||||
|
||||
|
@ -1177,11 +1177,9 @@ boolean SendKey(byte key, byte device, byte state)
|
||||
MqttPublishDirect(stopic, (key) ? Settings.flag.mqtt_switch_retain : Settings.flag.mqtt_button_retain);
|
||||
#endif // USE_DOMOTICZ
|
||||
result = true;
|
||||
#ifdef USE_RULES
|
||||
} else {
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"%s%d\":{\"State\":%d}}"), (key) ? "Switch" : "Button", device, state);
|
||||
result = RulesProcess();
|
||||
#endif // USE_RULES
|
||||
result = XdrvRulesProcess();
|
||||
}
|
||||
#ifdef USE_KNX
|
||||
KnxSendButtonPower(key, device, state);
|
||||
@ -1300,11 +1298,11 @@ void ExecuteCommand(char *cmnd)
|
||||
|
||||
void PublishStatus(uint8_t payload)
|
||||
{
|
||||
uint8_t option = 1;
|
||||
uint8_t option = STAT;
|
||||
char stemp[MAX_FRIENDLYNAMES * (sizeof(Settings.friendlyname[0]) +4)];
|
||||
|
||||
// Workaround MQTT - TCP/IP stack queueing when SUB_PREFIX = PUB_PREFIX
|
||||
if (!strcmp(Settings.mqtt_prefix[0],Settings.mqtt_prefix[1]) && (!payload)) option++;
|
||||
if (!strcmp(Settings.mqtt_prefix[0],Settings.mqtt_prefix[1]) && (!payload)) option++; // TELE
|
||||
|
||||
if ((!Settings.flag.mqtt_enabled) && (6 == payload)) payload = 99;
|
||||
if (!energy_flg && (9 == payload)) payload = 99;
|
||||
@ -2168,6 +2166,7 @@ void SerialInput()
|
||||
serial_in_buffer[serial_in_byte_counter] = 0; // serial data completed
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_JSON_SERIALRECEIVED "\":\"%s\"}"), serial_in_buffer);
|
||||
MqttPublishPrefixTopic_P(RESULT_OR_TELE, PSTR(D_JSON_SERIALRECEIVED));
|
||||
// XdrvRulesProcess();
|
||||
serial_in_byte_counter = 0;
|
||||
}
|
||||
}
|
||||
|
@ -1700,14 +1700,12 @@ void RtcSecond()
|
||||
snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_APPLICATION "(" D_UTC_TIME ") %s, (" D_DST_TIME ") %s, (" D_STD_TIME ") %s"),
|
||||
GetTime(0).c_str(), GetTime(2).c_str(), GetTime(3).c_str());
|
||||
AddLog(LOG_LEVEL_DEBUG);
|
||||
#ifdef USE_RULES
|
||||
if (local_time < 1451602800) { // 2016-01-01
|
||||
strncpy_P(mqtt_data, PSTR("{\"Time\":{\"Initialized\":1}}"), sizeof(mqtt_data));
|
||||
} else {
|
||||
strncpy_P(mqtt_data, PSTR("{\"Time\":{\"Set\":1}}"), sizeof(mqtt_data));
|
||||
}
|
||||
RulesProcess();
|
||||
#endif // USE_RULES
|
||||
XdrvRulesProcess();
|
||||
} else {
|
||||
ntp_sync_minute++; // Try again in next minute
|
||||
}
|
||||
@ -1788,7 +1786,7 @@ void AdcEvery50ms()
|
||||
adc_last_value = new_value;
|
||||
uint16_t value = adc_last_value / 10;
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"ANALOG\":{\"A0div10\":%d}}"), (value > 99) ? 100 : value);
|
||||
RulesProcess();
|
||||
XdrvRulesProcess();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -315,10 +315,8 @@ void MqttDisconnected(int state)
|
||||
snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_MQTT D_CONNECT_FAILED_TO " %s:%d, rc %d. " D_RETRY_IN " %d " D_UNIT_SECOND),
|
||||
Settings.mqtt_host, Settings.mqtt_port, state, mqtt_retry_counter);
|
||||
AddLog(LOG_LEVEL_INFO);
|
||||
#ifdef USE_RULES
|
||||
strncpy_P(mqtt_data, PSTR("{\"MQTT\":{\"Disconnected\":1}}"), sizeof(mqtt_data));
|
||||
RulesProcess();
|
||||
#endif // USE_RULES
|
||||
XdrvRulesProcess();
|
||||
}
|
||||
|
||||
void MqttConnected()
|
||||
@ -370,17 +368,13 @@ void MqttConnected()
|
||||
tele_period = Settings.tele_period -9;
|
||||
}
|
||||
status_update_timer = 2;
|
||||
#ifdef USE_RULES
|
||||
strncpy_P(mqtt_data, PSTR("{\"System\":{\"Boot\":1}}"), sizeof(mqtt_data));
|
||||
RulesProcess();
|
||||
#endif // USE_RULES
|
||||
XdrvRulesProcess();
|
||||
XdrvCall(FUNC_MQTT_INIT);
|
||||
}
|
||||
mqtt_initial_connection_state = 0;
|
||||
#ifdef USE_RULES
|
||||
strncpy_P(mqtt_data, PSTR("{\"MQTT\":{\"Connected\":1}}"), sizeof(mqtt_data));
|
||||
RulesProcess();
|
||||
#endif // USE_RULES
|
||||
XdrvRulesProcess();
|
||||
}
|
||||
|
||||
#ifdef USE_MQTT_TLS
|
||||
|
@ -110,6 +110,7 @@ void IrReceiveCheck()
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_JSON_IRRECEIVED "\":{\"" D_JSON_IR_PROTOCOL "\":\"%s\",\"" D_JSON_IR_BITS "\":%d,\"" D_JSON_IR_DATA "\":\"%lX\"}}"),
|
||||
GetTextIndexed(sirtype, sizeof(sirtype), iridx, kIrRemoteProtocols), results.bits, (uint32_t)results.value);
|
||||
MqttPublishPrefixTopic_P(RESULT_OR_TELE, PSTR(D_JSON_IRRECEIVED));
|
||||
XdrvRulesProcess();
|
||||
#ifdef USE_DOMOTICZ
|
||||
unsigned long value = results.value | (iridx << 28); // [Protocol:4, Data:28]
|
||||
DomoticzSensor(DZ_COUNT, value); // Send data as Domoticz Counter value
|
||||
|
@ -97,6 +97,7 @@ void SonoffBridgeReceived()
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_JSON_RFRECEIVED "\":{\"" D_JSON_SYNC "\":%d,\"" D_JSON_LOW "\":%d,\"" D_JSON_HIGH "\":%d,\"" D_JSON_DATA "\":\"%06X\",\"" D_CMND_RFKEY "\":%s}}"),
|
||||
sync_time, low_time, high_time, received_id, rfkey);
|
||||
MqttPublishPrefixTopic_P(RESULT_OR_TELE, PSTR(D_JSON_RFRECEIVED));
|
||||
XdrvRulesProcess();
|
||||
#ifdef USE_DOMOTICZ
|
||||
DomoticzSensor(DZ_COUNT, received_id); // Send rid as Domoticz Counter value
|
||||
#endif // USE_DOMOTICZ
|
||||
|
@ -61,6 +61,7 @@ void SerialBridgeInput()
|
||||
serial_bridge_buffer[serial_bridge_in_byte_counter] = 0; // serial data completed
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_JSON_SSERIALRECEIVED "\":\"%s\"}"), serial_bridge_buffer);
|
||||
MqttPublishPrefixTopic_P(RESULT_OR_TELE, PSTR(D_JSON_SSERIALRECEIVED));
|
||||
// XdrvRulesProcess();
|
||||
serial_bridge_in_byte_counter = 0;
|
||||
}
|
||||
}
|
||||
|
@ -287,7 +287,7 @@ void TimerEverySecond()
|
||||
#ifdef USE_RULES
|
||||
if (3 == xtimer.power) { // Blink becomes Rule disregarding device and allowing use of Backlog commands
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"Clock\":{\"Timer\":%d}}"), i +1);
|
||||
RulesProcess();
|
||||
XdrvRulesProcess();
|
||||
} else
|
||||
#endif // USE_RULES
|
||||
if (devices_present) { ExecuteCommandPower(xtimer.device +1, xtimer.power); }
|
||||
|
@ -80,8 +80,6 @@
|
||||
enum RulesCommands { CMND_RULE, CMND_RULETIMER, CMND_EVENT, CMND_VAR, CMND_MEM };
|
||||
const char kRulesCommands[] PROGMEM = D_CMND_RULE "|" D_CMND_RULETIMER "|" D_CMND_EVENT "|" D_CMND_VAR "|" D_CMND_MEM ;
|
||||
|
||||
char rules[MAX_RULE_SIZE];
|
||||
|
||||
String rules_event_value;
|
||||
unsigned long rules_timer[MAX_RULE_TIMERS] = { 0 };
|
||||
uint8_t rules_quota = 0;
|
||||
@ -436,20 +434,16 @@ boolean RulesCommand()
|
||||
switch (XdrvMailbox.payload) {
|
||||
case 0: // Off
|
||||
case 1: // On
|
||||
// Settings.flag.rules_enabled = XdrvMailbox.payload;
|
||||
bitWrite(Settings.rule_enabled, index -1, XdrvMailbox.payload);
|
||||
break;
|
||||
case 2: // Toggle
|
||||
// Settings.flag.rules_enabled ^= 1;
|
||||
bitWrite(Settings.rule_enabled, index -1, bitRead(Settings.rule_enabled, index -1) ^1);
|
||||
break;
|
||||
case 4: // Off
|
||||
case 5: // On
|
||||
// Settings.flag.rules_once = XdrvMailbox.payload &1;
|
||||
bitWrite(Settings.rule_once, index -1, XdrvMailbox.payload &1);
|
||||
break;
|
||||
case 6: // Toggle
|
||||
// Settings.flag.rules_once ^= 1;
|
||||
bitWrite(Settings.rule_once, index -1, bitRead(Settings.rule_once, index -1) ^1);
|
||||
break;
|
||||
}
|
||||
@ -526,6 +520,9 @@ boolean Xdrv10(byte function)
|
||||
case FUNC_COMMAND:
|
||||
result = RulesCommand();
|
||||
break;
|
||||
case FUNC_RULES_PROCESS:
|
||||
result = RulesProcess();
|
||||
break;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
@ -175,6 +175,11 @@ boolean XdrvMqttData(char *topicBuf, uint16_t stopicBuf, char *dataBuf, uint16_t
|
||||
return XdrvCall(FUNC_MQTT_DATA);
|
||||
}
|
||||
|
||||
boolean XdrvRulesProcess()
|
||||
{
|
||||
return XdrvCall(FUNC_RULES_PROCESS);
|
||||
}
|
||||
|
||||
/*********************************************************************************************\
|
||||
* Function call to all xdrv
|
||||
*
|
||||
@ -188,6 +193,7 @@ boolean XdrvMqttData(char *topicBuf, uint16_t stopicBuf, char *dataBuf, uint16_t
|
||||
* FUNC_SHOW_SENSOR
|
||||
* FUNC_EVERY_SECOND
|
||||
* FUNC_EVERY_50_MSECOND
|
||||
* FUNC_RULES_PROCESS
|
||||
\*********************************************************************************************/
|
||||
|
||||
boolean XdrvCall(byte Function)
|
||||
|
Loading…
x
Reference in New Issue
Block a user