ESPEasy R120 Rules - [need help]

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
User avatar
cracky
New user
Posts: 5
Joined: 06 Aug 2017, 18:56
Location: Bucharest

ESPEasy R120 Rules - [need help]

#1 Post by cracky » 06 Aug 2017, 19:05

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
configure.PNG (12.79 KiB) Viewed 8856 times

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!

User avatar
cracky
New user
Posts: 5
Joined: 06 Aug 2017, 18:56
Location: Bucharest

Re: ESPEasy R120 Rules - [need help]

#2 Post by cracky » 10 Aug 2017, 18:20

Anyone?:)

User avatar
grovkillen
Core team member
Posts: 3621
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: ESPEasy R120 Rules - [need help]

#3 Post by grovkillen » 10 Aug 2017, 20:12

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.
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you :idea: :idea: :idea:

Yann1420@live.co.uk
New user
Posts: 3
Joined: 25 Apr 2017, 08:55

Re: ESPEasy R120 Rules - [need help]

#4 Post by Yann1420@live.co.uk » 22 Aug 2017, 09:13

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.

User avatar
grovkillen
Core team member
Posts: 3621
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: ESPEasy R120 Rules - [need help]

#5 Post by grovkillen » 22 Aug 2017, 09:43

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".
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you :idea: :idea: :idea:

User avatar
cracky
New user
Posts: 5
Joined: 06 Aug 2017, 18:56
Location: Bucharest

Re: ESPEasy R120 Rules - [need help]

#6 Post by cracky » 04 Sep 2017, 21:31

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
all.PNG (17.88 KiB) Viewed 8479 times
touch.PNG
touch.PNG (17.78 KiB) Viewed 8479 times
bec1.PNG
bec1.PNG (20.03 KiB) Viewed 8479 times
bec2.PNG
bec2.PNG (20.47 KiB) Viewed 8479 times
dummy.PNG
dummy.PNG (20.63 KiB) Viewed 8479 times
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

User avatar
grovkillen
Core team member
Posts: 3621
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: ESPEasy R120 Rules - [need help]

#7 Post by grovkillen » 06 Sep 2017, 04:58

Happy to have helped. Thanks for the update!
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you :idea: :idea: :idea:

User avatar
cracky
New user
Posts: 5
Joined: 06 Aug 2017, 18:56
Location: Bucharest

Re: ESPEasy R120 Rules - [need help]

#8 Post by cracky » 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!

User avatar
toffel969
Normal user
Posts: 469
Joined: 03 Jan 2017, 10:58
Location: Germany

Re: ESPEasy R120 Rules - [need help]

#9 Post by toffel969 » 10 Sep 2017, 15:05

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
Domoticz on Raspi 2 -- 14 ESP units (hacked Sonoff,NodeMCUs, Wemos, self-built units) running with RC140- Mega 2.0.0 dev8

DrJeff
New user
Posts: 1
Joined: 11 Sep 2017, 17:10

Re: ESPEasy R120 Rules - [need help]

#10 Post by DrJeff » 11 Sep 2017, 17:31

I love those capacitive touch buttons got a bag full of them and they work great behind plastic inside of cases or plates!
:D

User avatar
cracky
New user
Posts: 5
Joined: 06 Aug 2017, 18:56
Location: Bucharest

Re: ESPEasy R120 Rules - [need help]

#11 Post by cracky » 12 Sep 2017, 14:34

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!

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 21 guests