Help with Rules

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
jasonjordan
New user
Posts: 1
Joined: 21 Apr 2016, 07:14

Help with Rules

#1 Post by jasonjordan » 21 Apr 2016, 07:30

Howdy,

One of the functions I have my ESP8266 undertaking is control of the sump level in my Aquaponics system.

Because it's a 'flood and drain' setup, sometimes the sump will overflow if the timings should synchronise accidentally. So I need to create a ruleset that runs the standard flood & drain cycle but also checks regularly to ensure the sump level isn't too high (and if it is, switch the solenoid valve back on out of cycle to dump the excess water back into the Aquaponic Tubs).

Because my Ultrasonic Water Level Detector points down, the lower the number of centimeters, the higher the level of the water. I do not want the water level to drop below 25cms (away from the ultrasonic sensor) as that's the level where it starts overflowing.

GPIO2 controls a relay that opens a solenoid valve to the tubs.

Here's my ruleset - I am a beginner at ESP8266, ESP Easy and Programming. So please bear with me!

Code: Select all

On System#Boot do    
  gpio,2,0   //if the solenoid is open, close it
  timerSet,1,10 
endon

On Rules#Timer=1 do  
  gpio,2,1  // open the solenoid for 5 minutes
  timerSet,2,360   
endon

On Rules#Timer=2 do  
  gpio,2,0  // close the solenoid for 30 minutes to drain the tubs
  timerSet,1,1800   
    If [depth#centimeters] < 30
       gpio,2,1    // check to ensure the sump isn't flooding, if it is, turn the solenoid on out of cycle.
    else 
       gpio,2,0
  endif
endon
Can anyone help me with the logic and how rules work?

Cheers, Jason

BertB
Normal user
Posts: 1049
Joined: 25 Apr 2015, 14:39

Re: Help with Rules

#2 Post by BertB » 23 Apr 2016, 15:59

The third rule:

Code: Select all

On Rules#Timer=2 do 
  gpio,2,0  // close the solenoid for 30 minutes to drain the tubs
  timerSet,1,1800   
    If [depth#centimeters] < 30
       gpio,2,1    // check to ensure the sump isn't flooding, if it is, turn the solenoid on out of cycle.
    else
       gpio,2,0
  endif
endon
starts when timer 2 fires and then looks at your depth#centimeters sensor. Only once.
So, if you want action whenever depth#centimeters < 30, you have to make an event of that, like

Code: Select all

On depth#centimeters<30 do
  timerset,1,5 // reset timer 1 to 5 seconds. After that it will go back to your second rule.
endon

JR01
Normal user
Posts: 260
Joined: 14 Feb 2016, 21:04
Location: South Africa

Help with Rules: Switching a Geyser on/off at set times?

#3 Post by JR01 » 28 Apr 2016, 20:20

Hi, is there a rule statement allowing to read the clock, (which is in my case set with NTP). ? I need this to switch the geyser on at 05h00 in the morning, switch off at 08h00, on again 17h00, off at 20h00?
-----------
IOTPLAY. Tinkerer, my projects are @ http://GitHub.com/IoTPlay, and blog https://iotplay.org. Using RPi, Node-Red, ESP8266 to prove Industry 4.0 concepts.

andy
Normal user
Posts: 65
Joined: 26 Jan 2016, 23:07

Re: Help with Rules

#4 Post by andy » 28 Apr 2016, 20:29

Sure. The following assumes GPIO 5 going low turns on your geyser and high turns it off. Adjust the code as appropriate for your setup.

Code: Select all

on Clock#Time=all,05:00 do
 GPIO,5,0
endon

on Clock#Time=all,08:00 do
 GPIO,5,1
endon

on Clock#Time=all,17:00 do
 GPIO,5,0
endon

on Clock#Time=all,20:00 do
 GPIO,5,1
endon

JR01
Normal user
Posts: 260
Joined: 14 Feb 2016, 21:04
Location: South Africa

Re: Help with Rules

#5 Post by JR01 » 28 Apr 2016, 20:33

Thank you Andy !!!!!!! :mrgreen:
-----------
IOTPLAY. Tinkerer, my projects are @ http://GitHub.com/IoTPlay, and blog https://iotplay.org. Using RPi, Node-Red, ESP8266 to prove Industry 4.0 concepts.

JR01
Normal user
Posts: 260
Joined: 14 Feb 2016, 21:04
Location: South Africa

Re: Help with Rules: Week Day ????

#6 Post by JR01 » 28 Apr 2016, 20:38

Andy, what about week days? I would like have different on/off 's for different days? (or am I asking too much now....) :roll:
-----------
IOTPLAY. Tinkerer, my projects are @ http://GitHub.com/IoTPlay, and blog https://iotplay.org. Using RPi, Node-Red, ESP8266 to prove Industry 4.0 concepts.

andy
Normal user
Posts: 65
Joined: 26 Jan 2016, 23:07

Re: Help with Rules

#7 Post by andy » 28 Apr 2016, 20:43

That's a piece of cake too. Replace "all" with either "sun" "mon" "tue" etc - you get the idea.

JR01
Normal user
Posts: 260
Joined: 14 Feb 2016, 21:04
Location: South Africa

Re: Help with Rules

#8 Post by JR01 » 28 Apr 2016, 20:56

Wow, I LOVE RULES !!!! Rules RULE !!!!!

Then even I can stop asking silly questions..... 8-)

There is no such thing as a silly question ...

I modified the Wiki.
-----------
IOTPLAY. Tinkerer, my projects are @ http://GitHub.com/IoTPlay, and blog https://iotplay.org. Using RPi, Node-Red, ESP8266 to prove Industry 4.0 concepts.

yml020
Normal user
Posts: 14
Joined: 18 Apr 2016, 13:44
Location: South Africa

Re: Help with Rules

#9 Post by yml020 » 09 May 2016, 17:09

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's 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
TopOnlineOnline

JR01
Normal user
Posts: 260
Joined: 14 Feb 2016, 21:04
Location: South Africa

Re: Help with Rules

#10 Post by JR01 » 01 Jun 2016, 19:40

@Tozett, my rules are still not working. Do you see something wrong with these rules? They are not working. Just as reference, this is working:

http://192.168.2.63/control?cmd=GPIO,16,1

For instance, should the action name be at the top like I have it, or at the bottom? (I tried both). Or, does GPIO16 have problems with rules for instance?

----------------
And here is the Web log, so it does ACT, but the switch does not come on?
558032 : EVENT: Clock#Time=Wed,19:45
558037 : ACT : GeyserOn
------------------------------------
on GeyserOn do
GPIO,16,1
endon

on GeyserOff do
GPIO,16,0
endon

on Clock#Time=all,19:15 do
GeyserOn
endon

on Clock#Time=all,23:00 do
GeyserOff
endon

on Clock#Time=all,05:30 do
GeyserOn
endon

on Clock#Time=all,09:15 do
GeyserOff
endon
-----------
IOTPLAY. Tinkerer, my projects are @ http://GitHub.com/IoTPlay, and blog https://iotplay.org. Using RPi, Node-Red, ESP8266 to prove Industry 4.0 concepts.

tozett
Normal user
Posts: 734
Joined: 22 Dec 2015, 15:46
Location: Germany

Re: Help with Rules

#11 Post by tozett » 01 Jun 2016, 20:44

may try another gpio instead of #16 ?
seems that this is used for deepsleep reset: http://www.esp8266.nu/forum/viewtopic.php?t=54#p776

i found this: https://github.com/CHERTS/esp8266-gpio16

Code: Select all

[*] D0(GPIO16) can only be used as gpio read/write. no interrupt supported. no pwm/i2c/ow supported.

dduley
Normal user
Posts: 93
Joined: 06 Feb 2016, 17:56

Re: Help with Rules

#12 Post by dduley » 01 Jun 2016, 22:33

JR01 wrote:@Tozett, my rules are still not working. Do you see something wrong with these rules? They are not working. Just as reference, this is working:

http://192.168.2.63/control?cmd=GPIO,16,1

For instance, should the action name be at the top like I have it, or at the bottom? (I tried both). Or, does GPIO16 have problems with rules for instance?

----------------
And here is the Web log, so it does ACT, but the switch does not come on?
558032 : EVENT: Clock#Time=Wed,19:45
558037 : ACT : GeyserOn
------------------------------------
on GeyserOn do
GPIO,16,1
endon

on GeyserOff do
GPIO,16,0
endon

on Clock#Time=all,19:15 do
GeyserOn
endon

on Clock#Time=all,23:00 do
GeyserOff
endon

on Clock#Time=all,05:30 do
GeyserOn
endon

on Clock#Time=all,09:15 do
GeyserOff
endon
Hi Tozett,

Does it work if you replace the GeyserOn and GeyserOff with the GPIO,16, 0 or 1? Get rid of the two first statements and replace the Geyser* statement in the clock event with the actual GPIO on off statement.

At the appointed times does the log show that the Geyser events were sent?

Dave

JR01
Normal user
Posts: 260
Joined: 14 Feb 2016, 21:04
Location: South Africa

Re: Help with Rules

#13 Post by JR01 » 01 Jun 2016, 22:57

I changed to GPIO5 - with the rules as I had it, did not work, but as suggested by dduley, did work. Pity, as I wanted other things to be done in the GeyserOn action. Thank you all.

Thus, now working:

on Clock#Time=all,22:56 do
GPIO,5,1
endon
-----------
IOTPLAY. Tinkerer, my projects are @ http://GitHub.com/IoTPlay, and blog https://iotplay.org. Using RPi, Node-Red, ESP8266 to prove Industry 4.0 concepts.

dduley
Normal user
Posts: 93
Joined: 06 Feb 2016, 17:56

Re: Help with Rules

#14 Post by dduley » 01 Jun 2016, 23:44

JR01 wrote:I changed to GPIO5 - with the rules as I had it, did not work, but as suggested by dduley, did work. Pity, as I wanted other things to be done in the GeyserOn action. Thank you all.

Thus, now working:

on Clock#Time=all,22:56 do
GPIO,5,1
endon
Hi JR01,

Sorry I addressed the wrong user in my last post but glad its working. I have something else for you to try. Instead of just saying GeyserOn or Off in your clock statements try saying: sendTo 2,event,GeyserOn. Replace the "2" with whatever the unique unit number you have used on your ESP. This could also be used to send this event to other ESPs on your network so you could turn on lights to illuminate the Geyser without having to run wires out to the fountain etc.

Dave

Post Reply

Who is online

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