Difference between revisions of "Tutorial Rules"

From Let's Control It
Jump to navigation Jump to search
Line 20: Line 20:
 
Timers can be used to time things.
 
Timers can be used to time things.
  
Some exmples:
+
'''Some exmples:'''
 
  Example 1:
 
  Example 1:
 
  On PIR#Switch do
 
  On PIR#Switch do
Line 28: Line 28:
 
  endon
 
  endon
  
In other words: If the PIR switch is set and if the light value < 500, then set GPIO port 16 of the ESP.
+
'''In other words: If the PIR switch is set and if the light value < 500, then set GPIO port 16 of the ESP.'''
  
 
  Example 2:
 
  Example 2:
Line 41: Line 41:
 
  endon
 
  endon
  
 +
'''Hereunder a timer example.'''
 
  Example 3:
 
  Example 3:
 
  On System#Boot do    //When the ESP boots, do
 
  On System#Boot do    //When the ESP boots, do
Line 55: Line 56:
 
  endon
 
  endon
  
 +
'''It is even possible to invoke the start of a Rule with a http call in an ESP.'''
  
 +
When you enter this with the correct IP address in the URL of your browser:
 +
http://<ESP-ip>/control?cmd=event,givemesomewater
 +
 +
And have this rule in the addressed ESP:
 +
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
 +
 +
Provided that you also have the valve etc, the plants will be happy.
 
To enable rules, go to Tools/Advanced and check the Rules checkbox.
 
To enable rules, go to Tools/Advanced and check the Rules checkbox.
  

Revision as of 19:56, 14 April 2016

WIP.gif


Beware.jpg

Information on this page is based on preliminary development. Beware that functionality may be incomplete, not fully tested and subject to change. It may even be removed in future releases if it turns out be unstable or based on erroneous interpretation of the operation of third-party technology. At this stage, we provide the information to support development and testing.

Along with ESP Easy R086, a new experimental feature was enabled, named Rules. Rules can be used to create very simple flows to control devices on your ESP.

The syntax of a rule can be:

on <event>[=,<,>][value] do <action>

or

on <event>[=,<,>][value] do
 <action>
 <action>
endon

Also simple if ... else ... endif statements are possible, but nesting and Boolean logic are not supported. Task values can be obtained in the same way as with the LCD and OLED template with [Device Name#Value Name] Timers can be used to time things.

Some exmples:

Example 1:
On PIR#Switch do
  if [LDR#Light]<500
    gpio,16,[PIR#Switch]
  endif
endon

In other words: If the PIR switch is set and if the light value < 500, then set GPIO port 16 of the ESP.

Example 2:
on SR04#range<100 do
  if [ldr#lux]<500
    gpio,2,0
    gpio,16,1
  else
    gpio,2,1
    gpio,16,0
  endif
endon

Hereunder a timer example.

Example 3:
On System#Boot do    //When the ESP boots, do
  servo,1,12,0
  timerSet,1,10      //Set Timer 1 for the next event in 10 seconds
endon
On Rules#Timer=1 do  //When Timer1 expires, do
  servo,1,12,30
  timerSet,2,1       //Set Timer 2 for the next event in 1 second
endon
On Rules#Timer=2 do  //When Timer2 expires, do
  servo,1,12,0
  timerSet,1,30      //Set Timer1 for the next event in 30 seconds
endon

It is even possible to invoke the start of a Rule with a http call in an ESP.

When you enter this with the correct IP address in the URL of your browser:

http://<ESP-ip>/control?cmd=event,givemesomewater

And have this rule in the addressed ESP:

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

Provided that you also have the valve etc, the plants will be happy. To enable rules, go to Tools/Advanced and check the Rules checkbox.

Advanced.jpg

After clicking Submit, you will find a new page added. Here you can start experimenting with Rules:

Rules1.jpg

The example above shows an experiment with a LED, connected via a resistor of 1k to GPIO12. To be able to read the state of the LED (on or off) a switch input is created with the same GPIO port:

Switch.jpg

After rebooting the ESP, the LED will start blinking 10 seconds on en 10 seconds off.

Enjoy.