Page 1 of 1

Rules examples

Posted: 12 Apr 2016, 00:20
by maluko
Thanks to bring us this type of rules that we can play with.

i know that this feature stil at beta but we want to understand the "how to" to start to mesh with rules.

So at this time i wonder if it is possible to put a timer on switch input like relay.

my system:

domoticz virtual switch on irrigation with 15m of timer to switch off,

domoticz send to esp01 by http command, but i am afraid that the command off dont arrived so its any change to put a security rule like this?

device= Switch input
name= relay
task= 1

if gpio0=1 do
timer 20m
gpio0=0
endif

thanks

Re: Rules examples

Posted: 13 Apr 2016, 15:20
by Martinus
If you upgrade to R100, you can now send events from http to ESP:

Code: Select all

 http://<ESP-ip>/control?cmd=event,givemesomewater
So you can use them in the rules tab like this example:

Code: Select all

on givemesomewater do
  gpio,2,1  // open valve
  timerSet 1,600 // 10 minute timer
endon

on Rules#Timer=1 do
  gpio,2,0 // close valve
endon
This can be done without using a task setup.

Re: Rules examples

Posted: 13 Apr 2016, 23:18
by grz3
any chance to use something like this?
to compare PN532 tags?

Code: Select all

on pn532#tag do
if [pn532#tag]="4034998235" // correct tag
    gpio,15,1  //green led - ok
   timerSet,1,1
else
    gpio,13,1  //red led - stop
   timerSet,1,1
endif
endon
on Rules#timer=1 do
    gpio,15,0
    gpio,13,0
endon

Re: Rules examples

Posted: 13 Apr 2016, 23:53
by maluko
Martinus wrote:If you upgrade to R100, you can now send events from http to ESP:

Code: Select all

 http://<ESP-ip>/control?cmd=event,givemesomewater
So you can use them in the rules tab like this example:

Code: Select all

on givemesomewater do
  gpio,2,1  // open valve
  timerSet 1,600 // 10 minute timer
endon

on Rules#Timer=1 do
  gpio,2,0 // close valve
endon
This can be done without using a task setup.
work like a charm

good work....again :)

thanks

Re: Rules examples

Posted: 14 Apr 2016, 19:58
by BertB
I added the examples to the Rules tutorial.

Re: Rules examples

Posted: 15 Apr 2016, 01:19
by hamster
I was wondering if its possible to use an 'OR' function
here is my attempt at a thermostat control based on occupancy
(the Or doesn't seem to work?)

Code: Select all

on temp1#Temperature>40 or occupied#Output=0 do
mcpgpio,23,0
gpio,0,0
endon
 
on temp1#Temperature<38 do
if [occupied#Output]=1  
mcpgpio,23,1
gpio,0,1
endon

Re: Rules examples

Posted: 24 Apr 2016, 23:43
by andy
hamster wrote:I was wondering if its possible to use an 'OR' function
here is my attempt at a thermostat control based on occupancy
(the Or doesn't seem to work?)

Code: Select all

on temp1#Temperature>40 or occupied#Output=0 do
mcpgpio,23,0
gpio,0,0
endon
 
on temp1#Temperature<38 do
if [occupied#Output]=1  
mcpgpio,23,1
gpio,0,1
endon
Booleans do not work, so just set up enough rules. Also, you may want to define on and off events, then call them with rules:

On thermon do
mcpgpio,23,1
gpio,0,1
endon

On thermoff do
mcpgpio,23,0
gpio,0,0
endon

on temp1#Temperature<38 do
if [occupied#Output]=1
event,thermon
endon

on temp1#Temperature>40 do
event,thermoff
endon

on occupied#Output=0 do
event,thermoff
endon

Re: Rules examples

Posted: 25 Apr 2016, 08:15
by tozett
@BertB
i think, it is most valuable to have lots of examples of rules in the wiki. can you add this?

(i had the experience with https://sourceforge.net/p/linknx/wiki/Main_Page/
which is a super lean an powerful rules-engine, but the lack of rule-explanation makes it hard to have fun with it..)

Re: Rules examples

Posted: 25 Apr 2016, 12:57
by yml020
Hi @Martinus or anyone else.
I fall under the NOOBS category, but still in the box !! Big newbe.
I do not have an Arduino, only a RasPi 2 for the Domoticz Server and a lot of ESP8266 with ESP Easy R78, so I cannot compile the source code into binary files.
Can someone please point me in a direction to get hold of a R104 binary, and a pointer to some Rules Examples or the Rules Tutorial mentioned before.
Many thanks to all who are developing this wonderfull firmware. It sure beats LUA.
:)

Re: Rules examples

Posted: 25 Apr 2016, 13:26
by tozett
for rules (and everything else), the wiki (will fill up) can be a start

http://www.esp8266.nu/index.php/Tutorial_Rules


for the binary, i could compile, but dont want this for lots of differnt modulse, so
its not that difficult to get yourself running. give it a try...
the forum has some entries for help, but again, good start is the wiki:

http://www.esp8266.nu/index.php/Tutoria ... are_Upload

Re: Rules examples

Posted: 25 Apr 2016, 13:29
by tozett
yml020 wrote: ... to get hold of a R104 binary,
it instantly checked github,
https://github.com/ESP8266nu/ESPEasy/bl ... eNotes.ino
but only found r103 at the moment. may a typo?
but r103 will get you going too...

Re: Rules examples

Posted: 25 Apr 2016, 14:01
by yml020
Thank you tozett for the tutorial.
But, with all due respect, to go through the whole process of setting up the Arduino IDE and then getting all the files and things in place, is a route that I really would not like to take.
I think Martinez would have everything ready to go, and with one or two clicks could possibly have a "standard type" binary, like R78. It is to people like him that I would plead to get hold of a copy.

Re: Rules examples

Posted: 25 Apr 2016, 14:04
by tozett
i can do one binary like this, if you like:
give a (public) place to upload ...

Re: Rules examples

Posted: 25 Apr 2016, 14:13
by yml020
I would really appreciate that. Without knowing exactly what is going on there, that dropdown seems like the standard things that need to be set to upload the file to the ESP.
Now, just a public place ????

Re: Rules examples

Posted: 25 Apr 2016, 14:25
by tozett

Re: Rules examples

Posted: 25 Apr 2016, 14:48
by yml020
Is it correct that it wants to download an .EXE file that must be run first?? Looks like to install a download manager ?!?!
My anti virus app (that I cannot switch off) the goes mad showing all sorts of bugs.

Re: Rules examples

Posted: 25 Apr 2016, 15:18
by Martinus
andy wrote: Booleans do not work, so just set up enough rules. Also, you may want to define on and off events, then call them with rules:

Code: Select all

On thermon do
 mcpgpio,23,1
 gpio,0,1
endon

On thermoff do
 mcpgpio,23,0
 gpio,0,0
endon

on temp1#Temperature<38 do
 if [occupied#Output]=1  
 event,thermon
endon
Creating events from within the rules section creates recursive calls to the engine. Actually not tested/supported but it could work. Current version could become unstable due to high RAM usage when the engine calls itself.

I've made some changes here and R104 should handle recursive calls better than earlier versions. It will also protect against loop conditions that would otherwise crash the system.

Re: Rules examples

Posted: 25 Apr 2016, 16:05
by tozett
yml020 wrote:Is it correct that it wants to download an .EXE file that must be run first?? Looks like to install a download manager ?!?!
My anti virus app (that I cannot switch off) the goes mad showing all sorts of bugs.
no. i uploaded a binary.
where to put?
(google gives a lot of options, but whom will you trust ...)

i can make a md5 hash, if you want...

Re: Rules examples

Posted: 25 Apr 2016, 16:38
by andy
Martinus wrote:
andy wrote: Booleans do not work, so just set up enough rules. Also, you may want to define on and off events, then call them with rules:

Code: Select all

On thermon do
 mcpgpio,23,1
 gpio,0,1
endon

On thermoff do
 mcpgpio,23,0
 gpio,0,0
endon

on temp1#Temperature<38 do
 if [occupied#Output]=1  
 event,thermon
endon
Creating events from within the rules section creates recursive calls to the engine. Actually not tested/supported but it could work. Current version could become unstable due to high RAM usage when the engine calls itself.

I've made some changes here and R104 should handle recursive calls better than earlier versions. It will also protect against loop conditions that would otherwise crash the system.
That's good to know, thanks.

I came up with the idea because there's no good shortcut to set two GPIO's manually. I need to open or close two relays if I need the pump off or on while servicing it. I set a rule called Poff to turn both relays off, and Ponn to turn them on. Interestingly, Pon wouldn't work, so I had to change it to Ponn. Maybe Pon is a reserved variable name? Now I can just type event,Poff (or event,Ponn) from the Tools page to manually control it. I then realized I could eliminate the GPIO calls in the rules and replace them with Ponn or Poff. It also reduces the number of characters in my rules section from 450 to 375 (or so). It's been working fine for the past week, I'm running version 101.

Re: Rules examples

Posted: 25 Apr 2016, 17:43
by Martinus
andy wrote:Interestingly, Pon wouldn't work, so I had to change it to Ponn. Maybe Pon is a reserved variable name?
No, you have caught a bug (every event name ending with 'on ' would not process at all)
Will be fixed in R105...

Re: Rules examples

Posted: 26 Apr 2016, 07:55
by yml020
tozett wrote:
yml020 wrote:Is it correct that it wants to download an .EXE file that must be run first?? Looks like to install a download manager ?!?!
My anti virus app (that I cannot switch off) the goes mad showing all sorts of bugs.
no. i uploaded a binary.
where to put?
(google gives a lot of options, but whom will you trust ...)

i can make a md5 hash, if you want...
Thank you very much tozett, but there is a member that contacted me on mail and uploaded a R104 for me. I have downloaded it and will test it later. I need to prepare a new device first.

Many thanks.

Re: Rules examples

Posted: 26 Apr 2016, 08:05
by tozett
grz3 wrote:any chance to use something like this?
to compare PN532 tags?

Code: Select all

on pn532#tag do
if [pn532#tag]="4034998235" // correct tag
    gpio,15,1  //green led - ok
   timerSet,1,1
else
    gpio,13,1  //red led - stop
   timerSet,1,1
endif
endon
on Rules#timer=1 do
    gpio,15,0
    gpio,13,0
endon
did you tried this, if it works? (will build something similar myself..)
looks to me, if it is normal like other comparison...

Re: Rules examples

Posted: 26 Apr 2016, 08:32
by grz3
tozett wrote:
grz3 wrote:any chance to use something like this?
to compare PN532 tags?

Code: Select all

on pn532#tag do
if [pn532#tag]="4034998235" // correct tag
    gpio,15,1  //green led - ok
   timerSet,1,1
else
    gpio,13,1  //red led - stop
   timerSet,1,1
endif
endon
on Rules#timer=1 do
    gpio,15,0
    gpio,13,0
endon
did you tried this, if it works? (will build something similar myself..)
looks to me, if it is normal like other comparison...
tried, but not working, the quotes are kind of problem I think.. :-( that is why I put this question here to anybody willing to help me...

Re: Rules examples

Posted: 26 Apr 2016, 08:51
by tozett
http://www.esp8266.nu/forum/viewtopic.p ... 1430#p6198

there is an working !! example of the same with IR-input.
another user stated this. may you try again without ""

if i find time this week, i will also try this...

Re: Rules examples

Posted: 27 Apr 2016, 09:40
by yml020
I have a PC problem. Yes, I know this is the wrong forum for that !!!

With R78 if I send this:-
http://192.168.1.31/control?cmd=GPIO,2,0
I get this in the IE window:-
GPIO 2 Set to 0

With R104 if I send this:-
http://192.168.1.32/control?cmd=GPIO,2,0
I get this in a box at the bottom of the screen asking:-
Do you want to open or save CONTROL.JSON from 192.168.1.32? OPEN SAVE CANCEL.

This is in the file:-
{
"log": "GPIO 2 Set to 1",
"plugin": 1,
"pin": 2,
"mode": "output",
"state": 1
}

Is this needed for Rules to speak to each other between devices ??

This becomes a real pain after a while. I have tried all settings in IE 11 to stop asking what to do with the .JSON file but without success.

Any pointers please ?

Re: Rules examples

Posted: 27 Apr 2016, 13:46
by tozett
Tried with Googles Chrome-browser ?

Re: Rules examples

Posted: 28 Apr 2016, 08:54
by yml020
Hello.
I installed Chrome and now it display the result of the command.
Cool.
Thank you very much for the assistance.

Rules examples ~ Variables?

Posted: 28 Apr 2016, 21:40
by JR01
I want to switch on/off the geyser based on timer if a variable, which I want to pass into ESP with MQTT is not set, and visa versa, want to be able to override setting on/off via web page and then to override the schedule rules.

One way is to pass a variable by publishing with MQTT, like /ESP12-01/Switch/<variable name here> with say payload 1, then create nested rules that looks for this variable, and only allow the rules to switch on/off if 1 has been passed in?

Can one work with variables? will this work?

Re: Rules examples

Posted: 28 Apr 2016, 21:58
by JR01
I am still vague on how the rules language works. On the tutorial, it does not explain how the 'event' is built up. For instance,
Example 1:
On PIR#Switch do
if [LDR#Light]<500

Is PIR the <Device Name> and Switch the <Device Value Name> ? or per notation of the pub template, the /%tskname%/%valname% ?

Re: Rules examples

Posted: 29 Apr 2016, 10:08
by tozett
look here: ?
http://www.esp8266.nu/forum/viewtopic.p ... les+syntax

the wiki is something short in explanation of rules,
but it think this comes to

[devicename#valuename1]

you can control/debug this in the log of the ESPeasy...

Re: Rules examples

Posted: 08 May 2016, 19:37
by yml020
Hi.

Should this work ? So at 19 deg it does nothing, a sort of hysteresis. gpio-16 is the heater.

What I am asking is if the if-endif should work. Only one of them works and never the other one. Can I have 2 in one do?

on Rules#Timer=5 do
if [DHT_01#Temperature] < 19
gpio,16,1
endif
if [DHT_01#Temperature] > 19
gpio,16,0
endif
timerSet 5,10
endon


This does work but I want to use two different temperatures.

on Rules#Timer=5 do
if [DHT_01#Temperature] > 19
gpio,16,0
else
gpio,16,1
endif
timerSet 5,10
endon

Re: Rules examples

Posted: 18 Oct 2016, 23:27
by maluko
hi

i have a wemos D1 mini with 1 relay and 2 ds18b20 and my goal is to put this with rules comparation.

i have test with:

On temp2#Temperature>temp1#Temperature do
gpio,5,0
endon

On temp1#Temperature>temp2#Temperature do
gpio,5,1
endon

but like i have 10s for temp sensor delay so after this time the relay goes on and off, wait 10s then on and off.

can anyone help

thanks



edit:

i think i did it

On temp1#Temperature>[temp2#Temperature] do
gpio,5,1
endon

On temp2#Temperature>[temp1#Temperature] do
gpio,5,0
endon


if you want that start with 1ºc difference, can put on temp formula like %value%+1

Re: Rules examples

Posted: 20 Oct 2016, 23:18
by maluko
i had a problem, i think it is the rule:
this is the log of domoticz switch actived by relay on wemos.

2016-10-20 21:45:40 Off
2016-10-20 21:45:37 On
2016-10-20 21:37:54 Off
2016-10-20 21:37:51 On
2016-10-20 21:26:12 Off
2016-10-20 21:26:09 On
2016-10-20 20:14:37 Off
2016-10-20 20:14:34 On
2016-10-20 19:57:50 Off
2016-10-20 19:57:48 On
2016-10-20 19:22:13 Off here is when the temp2 > temp 1 so turn off the relay but next appear a lot of on/off between 2/3second that i dont understand, this happen too when temp1>temp2 but in that case on inverse. the temperatura was 10 or more ºC difference.
2016-10-20 18:13:48 On
2016-10-20 18:13:45 Off
2016-10-20 17:31:49 On
2016-10-20 17:31:46 Off
2016-10-20 17:25:37 On
2016-10-20 17:25:33 Off
2016-10-20 16:13:02 On
2016-10-20 16:12:56 Off
2016-10-20 15:02:58 On
2016-10-20 15:02:53 Off
2016-10-20 14:13:42 On
2016-10-20 14:13:39 Off
2016-10-20 14:12:36 On
2016-10-20 14:12:34 Off

can any help on revison of rules?

thanks

gpio in rules?

Posted: 22 Oct 2016, 19:11
by timsson
Hi,
how can i make a rule with gpios?

on gpio,2#state = 1 do // ?????
......
endon

Re: Rules examples

Posted: 23 Oct 2016, 18:54
by iron
The "not so obvious" part is that you have to declare that gpio as an input switch.
Check this thread :
http://www.esp8266.nu/forum/viewtopic.php?f=6&t=2039

Re: Rules examples

Posted: 26 Oct 2016, 22:36
by timsson
iron wrote:The "not so obvious" part is that you have to declare that gpio as an input switch.
Check this thread :
http://www.esp8266.nu/forum/viewtopic.php?f=6&t=2039
ohh.... thanks!
an other question:
timerSet,1,random(120,600) possible???

Re: Rules examples

Posted: 15 Nov 2016, 01:05
by reddo
Hi guys. I have an ESP01 with 2 DS18B20's which I use for Domoticz, controlling a circulation pump for my underfloor heating. Now, is it possible to make a rule that calculates the difference between the 2 temps and sends that as a variable to Domoticz too ?

Re: Rules examples

Posted: 15 Nov 2016, 17:10
by CherAlban
Hi,

I am also struggeling with the rules. I am using Domoticz with espEasy R145 on an ESP8266-12F with a relay on GPIO-4 to control my car pre-heating. What I try to implement is:

- When triggered from Domoticz (preheat20), espEasy shall close the relay for 20 minutes, and after opening it again report the 'Off' status back to Domoticz .

The set of rules below provides this functionality, except that I can't make espEasy report the 'Off' status back to Domoticz. I can see the switch status changing form 0 > 1 > 0 in espeays, but it does not report the change of status to Domoticz.

Is there any rule that forces a status update?

CherAlban

Code: Select all

on preheatOn do
 GPIO,4,1
 inputswitchstate 0,1
endon

on preheatOff do
 GPIO,4,0
 inputswitchstate 0,0
endon

on preheat20 do
  timerSet 1,1200 //20 minutes timer
  event,preheatOn
endon

on Rules#Timer=1 do
 event,preheatOff
endon

Re: Rules examples

Posted: 17 Mar 2017, 09:58
by mvn77
Вы можете посылать команды через UART правил? Для того, чтобы отправить SMS через модем/

Re: Rules examples

Posted: 12 Apr 2017, 20:30
by darek2
Hello
Sorry for my English (translate.google) ;)
I have sonoff basic 5 pin. Firmware Build: 120 easyesp
Pin gpio 14 dht11 it works.
"http://192.168.1.60/control?cmd=GPIO,12,1" work :D

I need to run a fan in the bathroom depending on the humidity.
Humidity > 30 gpio,12,1 .
Theoretically simple :D .
Level Control this does not work.
I'm testing different "rules".
Unfortunately I am an amateur and that is my beginnings :)
Please help :oops:

Re: Rules examples

Posted: 13 Apr 2017, 23:19
by paxi

Code: Select all

On sensorname#valuename do
    If [sensorname#valuname] > 30
        Gpio 12,1
    Else
        Gpio 12,0 
    Endif
Endon
But if you really want to bring RH below 30% it may be easier to skip the esp and let the fan run permanently. :D

Re: Rules examples

Posted: 25 Apr 2017, 11:54
by rene9900
i am having a challenge with my wemos mini running ESPEasy i have a DS1820 and all is working fine, except i want to monitor my freezer, and if the temperature goes above -15 towards 0 degrees..
i currently have 2 other wemos running dht11 and dth22 and made the rule to get notification via email like the one below here, when i change to value > -18 < -15 i get no triggering
any suggestions how to get it to act and then publish on my requested temperatures?


on temp#Temperature do
if [temp#Temperature] > 28 // over skifter til HIGH
gpio,5,1
Publish /esp42/WARNING,[temp#Temperature]
endif
if [temp#Temperature] < 27 // under skifter til LOW
gpio,5,0
Publish /esp42/Normal,[temp#Temperature]
endif
endon