diff --git a/lib/libesp32/Berry/default/embedded/Tasmota.be b/lib/libesp32/Berry/default/embedded/Tasmota.be index 9266c135c..b0cffc511 100644 --- a/lib/libesp32/Berry/default/embedded/Tasmota.be +++ b/lib/libesp32/Berry/default/embedded/Tasmota.be @@ -15,6 +15,7 @@ class Timer end end +tasmota = nil class Tasmota # add `chars_in_string(s:string,c:string) -> int`` diff --git a/tasmota/xdrv_10_rules.ino b/tasmota/xdrv_10_rules.ino index d2f323760..a4d454040 100644 --- a/tasmota/xdrv_10_rules.ino +++ b/tasmota/xdrv_10_rules.ino @@ -801,6 +801,11 @@ bool RuleSetProcess(uint8_t rule_set, String &event_saved) bool RulesProcessEvent(const char *json_event) { +#ifdef USE_BERRY + // events are passed to Berry before Rules engine + callBerryRule(json_event); +#endif + if (Rules.busy) { return false; } Rules.busy = true; @@ -858,7 +863,11 @@ void RulesInit(void) void RulesEvery50ms(void) { +#ifdef USE_BERRY + if (!Rules.busy) { // Emitting Rules events is always enabled with Berry +#else if (Settings->rule_enabled && !Rules.busy) { // Any rule enabled +#endif char json_event[120]; if (-1 == Rules.new_power) { Rules.new_power = TasmotaGlobal.power; } diff --git a/tasmota/xdrv_52_9_berry.ino b/tasmota/xdrv_52_9_berry.ino index 213645f1f..6095a7750 100644 --- a/tasmota/xdrv_52_9_berry.ino +++ b/tasmota/xdrv_52_9_berry.ino @@ -93,12 +93,13 @@ extern "C" { \*********************************************************************************************/ // // call a function (if exists) of type void -> void -bool callBerryRule(void) { +// If event == nullptr, then take XdrvMailbox.data +bool callBerryRule(const char *event) { if (berry.rules_busy) { return false; } berry.rules_busy = true; char * json_event = XdrvMailbox.data; bool serviced = false; - serviced = callBerryEventDispatcher(PSTR("rule"), nullptr, 0, XdrvMailbox.data); + serviced = callBerryEventDispatcher(PSTR("rule"), nullptr, 0, event ? event : XdrvMailbox.data); berry.rules_busy = false; return serviced; // TODO event not handled } @@ -732,7 +733,7 @@ bool Xdrv52(uint8_t function) // Berry wide commands and events case FUNC_RULES_PROCESS: - result = callBerryRule(); + result = callBerryRule(nullptr); break; case FUNC_MQTT_DATA: result = callBerryEventDispatcher(PSTR("mqtt_data"), XdrvMailbox.topic, 0, XdrvMailbox.data, XdrvMailbox.data_len); diff --git a/tasmota/xdrv_interface.ino b/tasmota/xdrv_interface.ino index e3c637231..0444ad11d 100644 --- a/tasmota/xdrv_interface.ino +++ b/tasmota/xdrv_interface.ino @@ -1083,8 +1083,8 @@ bool XdrvRulesProcess(bool teleperiod, const char* event) { char* data_save = XdrvMailbox.data; XdrvMailbox.data = (char*)event; bool rule_handled = XdrvCallDriver(10, (teleperiod) ? FUNC_TELEPERIOD_RULES_PROCESS : FUNC_RULES_PROCESS); -#ifdef USE_BERRY - // events are passed to both Rules engine AND Berry engine +#if defined(USE_BERRY) && !defined(USE_RULES) + // events are sent to Berry in Rules driver, or here if USE_RULES is not defined (only on a subset) bool berry_handled = XdrvCallDriver(52, FUNC_RULES_PROCESS); rule_handled |= berry_handled; #endif