arendst / Tasmota

Alternative firmware for ESP8266 and ESP32 based devices with easy configuration using webUI, OTA updates, automation using timers or rules, expandability and entirely local control over MQTT, HTTP, Serial or KNX. Full documentation at
https://tasmota.github.io/docs
GNU General Public License v3.0
22.2k stars 4.81k forks source link

How to separate switch and actor for using rules? #3675

Closed renne closed 6 years ago

renne commented 6 years ago

Make sure these boxes are checked [x] before submitting your issue - Thank you!

Hi,

I'm trying to link Switch1 (RCWL-0516 motion detector on GPIO0, SwitchMode1 1) with POWER1 via rules. If I use SwitchTopic1 0 or SwitchTopic1 1 the light is always powered off when the RCWL-0516 goes low after 2 seconds. If SwitchTopic1 xxx is used I can't get a rule to trigger.

How do I have to configure the H801 to link Switch1 with Power1 via rules without internal connections interfering?

Frogmore42 commented 6 years ago

I have not tried rules yet, but you probably want switch mode 4, so it activates on motion. You need switch topic to be something other than 0 or 1, since they will control the relay either directly or indirectly, respectively.

I would suggest NOT using GPIO 0 for the RCWL-0516, since it might trigger bootloader mode on power up and you probably want a physical button on GPIO to enable bootloader mode manually. You can also define the pin that the rcwl is using as Switch2 and define another unused pin as Relay2 and then you rule should work. If it also switches Relay2 it won't matter as nothing is connected to it.

ascillato2 commented 6 years ago

Please, read the wiki at rules examples: https://github.com/arendst/Sonoff-Tasmota/wiki/Rules#15-rule-to-enable-a-pir-sensor-only-at-night

renne commented 6 years ago

@Frogmore42 Switchmode1 4 with SwitchTopic1 0or SwitchTopic1 1 toggles the light every time someone moves. If I use SwitchTopic MOTION rules don't trigger. The RCWL-0516 doesn't have adjustable delay. It switches on for 2 seconds when movement is detected. So I need something like the 10. Simple Staircase Timer without switching off by the button (= RCWL-0516).

The H801 has only GPIO0, GPIO2 and GPIO3 on solder-pads. As GPIO2 and GPIO3 are used for I2C only GPIO0 is available for the RCWL-0516. If I want to flash the H801 I have to pull out the cable and connect a USB-UART adapter.

Using Switch1 with SwitchTopic1 0 and Switchmode1 1 on GPIO0, dummy Relay 1 on GPIO16 and the rule {"Rule1":"ON","Once":"OFF","StopOnError":"OFF","Free":413,"Rules":"on switch1#state=1 do backlog power2 on; ruletimer1 300 endon on rules#timer=1 do power2 off endon"} works but is quite complicated and costs a GPIO.

@ascillato2 15. Rule to enable a PIR Sensor only at night does not work as the light is switched off by Switch1 with SwitchTopic1 0or SwitchTopic1 1. SwitchTopic MOTION doesn't trigger rules (e.g. event cmnd/motion/power1 = on).

Is there any way to trigger a rule by a MQTT message (e.g. SwitchTopic motion)?

Frogmore42 commented 6 years ago

I would try this: 'rule1 on button1#state do backlog power1 on; ruletimer1 600 endon on rules#timer=1 do power1 off endon

Configure the GPIO as a button not a switch. You can use GPIO 2 as button. But it might work okay with GPIO 0 too.

benzino77 commented 6 years ago

Please, look at the example: 9. Simple Thermostat Example

When you define rule: on switch1#state do... the switch1 will be "disconnected" from relay1 and will be controlled by rule. If you want to power on the light (for lets say X minutes) when the pir detects a move you could try with the switchmode1 3 or switchmode1 4 - switch (pir in your setup) as a pushbutton.

renne commented 6 years ago

@Frogmore42 After resetting the configuration of the H801 completely the rule rule1 on button1#state do backlog power1 on; ruletimer1 600 endon on rules#timer=1 do power1 off endon works. The button usage functionalities of Button1 cause the H801 to reset after some time. Changing GPIO0 and the rule to Button2 doesn't work. What is the difference in configuration between Button1 and Button2?

@benzino77 Switch1 works with SwitchMode1 4 after configuration reset, too.

SibMan54 commented 5 years ago

I have a Wemos D1 module and 4 relays are connected to it on pins GPIO04, GPIO05, GPIO12, GPIO13 The RCWL-0516 sensor is connected to GPIO14 On my idea in the absence of the movement during certain time the 2nd relay has to be switched off. But the problem is that switch 5...8 -> on/off relay 1

SibMan54 commented 5 years ago

Whether it is possible to remove somehow a binding of switch 5...8 from relay 1 Following rule: rule1 on switch5#state do ruletimer1 1800 endon on rules#timer=1 do power2 off endon on time#minute=120 do power2 off endon

And I want so: rule1 on power2#state=1 do rule2 1 endon on power2#state=0 do rule2 0 endon rule2 on switch5#state do ruletimer1 1800 endon on rules#timer=1 do power2 off endon on time#minute=120 do power2 off endon

benzino77 commented 5 years ago

What is your switchtopic[12345]?

SibMan54 commented 5 years ago

12:22:10 CMD: SwitchTopic 12:22:10 MQT: stat/sonoff/SWITCHTOPIC = {"SwitchTopic":"0"}

13:01:58 CMD: SwitchMode5 13:01:58 MQT: stat/sonoff/SWITCHMODE = {"SwitchMode5":3}

benzino77 commented 5 years ago

I think you have to have a rule for each: switch5 to switch8 even if the rules for some switches will be empty: on switch7#state do delay endon on switch5#state do all_other_tasks endon on rules#timer=1 do some_other_tasks endon

I can't remember who (@ascillato ?) had mentioned about such situation in one of the issues... but I'm not sure.