Page 1 of 1

ESPEasy R120 Rules - [need help]

Posted: 06 Aug 2017, 19:05
by cracky
Hello, guys!

I need some help, I got 1 ESP8266-01 with EspEasy R120 and I need to configure some rules with multiple "if-then" condition.

I have the following:
1 x ESP8266-01
2 x relays
1 x touch button

What I need:

- when I press once the touch button, turn relay 1 ON
- when I press second time, turn relay 2 ON
and the third time -> turn off both

What I got now with the rules bellow..
When I press touch button, first relay start on, then relay 2, and after that are both off -> and the cycle repeats until I press again the touch button.
configure.PNG

Code: Select all

on Touch#Switch do
if [Touch#Switch]=1.00
gpio,1,1
event checkBec1
endif
endon

on checkBec1 do
if [Touch#Switch]=1.00
if [bec1#Switch]=1.00
gpio,2,1
event checkBec2
endif
endon

on checkBec2 do
if [Touch#Switch]=1.00
if [bec2#switch]=1.00
gpio,1,0
gpio,2,0
endif
endon

Help please, I have 0 experience with this coding type.
Thank you in advance!

Re: ESPEasy R120 Rules - [need help]

Posted: 10 Aug 2017, 18:20
by cracky
Anyone?:)

Re: ESPEasy R120 Rules - [need help]

Posted: 10 Aug 2017, 20:12
by grovkillen
Have you studied the wiki? Since the syntax is not correct I believe you haven't. Please read it and then come here if you still need help.

The (rules) tutorial section as well as the guide for Sonoff Touch will give you the answers.

Re: ESPEasy R120 Rules - [need help]

Posted: 22 Aug 2017, 09:13
by Yann1420@live.co.uk
Do not misunderstand me, this team has done a great job.
But what I am missing for example is simple things like is the basic syntax rules, e.g. case-sensitive, indentation, line-continuation, keywords.

Re: ESPEasy R120 Rules - [need help]

Posted: 22 Aug 2017, 09:43
by grovkillen
Regarding line indent, case-sensitive are no problem, but yes - it is not stated in the wiki. Regarding the rule asked for here:

Code: Select all

 on touch#switch do
    if [count#state]>1
      TaskValueSet,4,1,0
    else
      TaskValueSet,4,1,[count#state]+1
    endif
 endon
 
   on count#state=0 do
    gpio,1,0
    gpio,2,0
  endon
 
  on count#state=1 do
    gpio,1,1
  endon

  on count#state=2 do
    gpio,2,1
  endon
This uses a dummy device called "count" (task number 4) and dump the current state to value number 1 "state".

Re: ESPEasy R120 Rules - [need help]

Posted: 04 Sep 2017, 21:31
by cracky
Hello, guys!

I really appreciate your help, thank you for that, especially grovkillen.
I tried the script you provided with dummy device and after some more settings it works :)

It looks like this:
Image

Devices:
all.PNG
touch.PNG
bec1.PNG
bec2.PNG
dummy.PNG
Rules:

Code: Select all

 on Touch#Twitch do
    if [Touch#Switch]=1.00
      TaskValueSet,4,1,0
    endif
 endon

    if [count#state]>1
      TaskValueSet,4,1,0
    else
      TaskValueSet,4,1,[count#state]+1
    endif
 endon

   on count#state=0 do
    gpio,1,1
    gpio,2,1
  endon
 
  on count#state=1 do
    gpio,1,0
  endon

  on count#state=2 do
    gpio,2,0
  endon

Re: ESPEasy R120 Rules - [need help]

Posted: 06 Sep 2017, 04:58
by grovkillen
Happy to have helped. Thanks for the update!

Re: ESPEasy R120 Rules - [need help]

Posted: 10 Sep 2017, 14:02
by cracky
Hello!

I still have a question, maybe you know how to do it.
In this case if I turn off the light from the button and then I want to start it from the openhab, it runs the rule where it counts the value of the dummy device and does not work.
So I think a way is to set up the dummy device than to set the switch. Is it possible to set a value on dummy device using MQTT :?:

Thank you!

Re: ESPEasy R120 Rules - [need help]

Posted: 10 Sep 2017, 15:05
by toffel969
cracky wrote: 10 Sep 2017, 14:02 Hello!

I still have a question, maybe you know how to do it.
In this case if I turn off the light from the button and then I want to start it from the openhab, it runs the rule where it counts the value of the dummy device and does not work.
So I think a way is to set up the dummy device than to set the switch. Is it possible to set a value on dummy device using MQTT :?:

Thank you!
No not directly... But you can send an event value. This event value can be written into a dummy device. So there is a workaround .
Check
Check https://www.letscontrolit.com/wiki/inde ... _Variables
Together with wikion dummy

Re: ESPEasy R120 Rules - [need help]

Posted: 11 Sep 2017, 17:31
by DrJeff
I love those capacitive touch buttons got a bag full of them and they work great behind plastic inside of cases or plates!
:D

Re: ESPEasy R120 Rules - [need help]

Posted: 12 Sep 2017, 14:34
by cracky
DrJeff & toffel969- thank you!

Short story: I made it work!


Long stroy:

Let me tell you what the structure of the project is and why I needed these rules :mrgreen:

I use a relay and touch button, ordered by esp8266 01 and I can:
- turn on and off the room light (2 channels) from the touch button (on the wall)
- turn on and off the room light from OpenHab via MQTT
- turn on and off the room light from Amazon Echo (Alexa) via OpenHab via MQTT :)

The problem was: If I turn off the light from the button and then I want to start it from the openhab, it runs the rule where it counts the value of the dummy device and does not work.
How I solved it, by adding a rule for count state and a wrong value for dummy device, to count it 0 after system boot :)

Code: Select all

on System#Boot do
  TaskValueSet 4,1,10 // default value at boot 
endon

on System#Boot do 
gpio,0,0
endon

on System#Boot do 
gpio,2,0 
endon

 on Touch#value do
    if [count#state]>1
      TaskValueSet,4,1,0
    else
      TaskValueSet,4,1,[count#state]+1
    endif
 endon

 on Touch#value do
    if [count#state]=0 do
    gpio,0,0
    gpio,2,0
  endon

 on Touch#value do
    if [count#state]=1 do
    gpio,0,1
  endon

 on Touch#value do
    if [count#state]=2 do
    gpio,2,1
  endon

Thank you guys!