From a67efa0ab2c36e4c94de31c13e93d6ccbfc382aa Mon Sep 17 00:00:00 2001 From: Adrian Scillato <35405447+ascillato@users.noreply.github.com> Date: Wed, 26 Sep 2018 23:02:55 -0300 Subject: [PATCH] Added new triggers for rules on boot time To make it possible to trigger a rule at boot time with the state of the switches or relays (in order to take decisions), 2 new trigger types has been added: * SWITCH1#BOOT to be used like: ON SWITCH1#BOOT DO ... %value% ENDON ON SWITCH1#BOOT=0 DO .... ENDON ON SWITCH1#BOOT=1 DO .... ENDON and * POWER1#BOOT to be used like: ON POWER1#BOOT DO ... %value% ENDON ON POWER1#BOOT=0 DO .... ENDON ON POWER1#BOOT=1 DO .... ENDON --- sonoff/xdrv_10_rules.ino | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/sonoff/xdrv_10_rules.ino b/sonoff/xdrv_10_rules.ino index 060bf085f..b13dfc771 100644 --- a/sonoff/xdrv_10_rules.ino +++ b/sonoff/xdrv_10_rules.ino @@ -376,6 +376,25 @@ void RulesEvery50ms() RulesProcessEvent(json_event); } } + } else { + // Boot time POWER OUTPUTS (Relays) Status + for (byte i = 0; i < devices_present; i++) { + uint8_t new_state = (rules_new_power >> i) &1; + snprintf_P(json_event, sizeof(json_event), PSTR("{\"Power%d\":{\"Boot\":%d}}"), i +1, new_state); + RulesProcessEvent(json_event); + } + // Boot time SWITCHES Status + for (byte i = 0; i < MAX_SWITCHES; i++) { +#ifdef USE_TM1638 + if ((pin[GPIO_SWT1 +i] < 99) || ((pin[GPIO_TM16CLK] < 99) && (pin[GPIO_TM16DIO] < 99) && (pin[GPIO_TM16STB] < 99))) { +#else + if (pin[GPIO_SWT1 +i] < 99) { +#endif // USE_TM1638 + boolean swm = ((FOLLOW_INV == Settings.switchmode[i]) || (PUSHBUTTON_INV == Settings.switchmode[i]) || (PUSHBUTTONHOLD_INV == Settings.switchmode[i])); + snprintf_P(json_event, sizeof(json_event), PSTR("{\"" D_JSON_SWITCH "%d\":{\"Boot\":%d}}"), i +1, (swm ^ lastwallswitch[i])); + RulesProcessEvent(json_event); + } + } } rules_old_power = rules_new_power; }