Page 1 of 1

Water Level Control Relay Rule

Posted: 16 Feb 2018, 12:12
by Michael_BruceLee
Hi Guys,

i´m new to the Rules business and i´ve built together a Waterlevel Sensor (HC-SR04) with an NodeMCU V3 Board and want to toggle a 1channel Relay when a certain Waterlevel has reached.
It´s for my Dog´s trinkin place ;-)
So for example his watter bowl is full and the distance betwenn the water and the sensor is 40cm, and he comes and drinks out of his bowl the waterlevel decreases to for example 20cm distance to the sensor, esp easy should toggle my relay to pump new water in the bowl. The relay should be toggled for about 20sec. to not overfill the bowl.
how do i write this rule? i´ve tried a lot but nothing works, as i´ve said i really ned your help because i´m new to the rules game here.
would be awesome if someone could help me out here!!
thanks a lot

Mike

Re: Water Level Control Relay Rule

Posted: 16 Feb 2018, 12:14
by Michael_BruceLee
sorry i mean if he waterlevel increase when he drinks to for example 60cm....

Re: Water Level Control Relay Rule

Posted: 17 Feb 2018, 17:21
by budman1758
Have you read the Wiki page?
https://www.letscontrolit.com/wiki/inde ... rial_Rules

What you want to do is quite easy.

Re: Water Level Control Relay Rule

Posted: 18 Feb 2018, 14:26
by Michael_BruceLee
thanks for your reply.
yes i´ve read the wiki page but i don´t get is ;-) as i told you it´s my first rule.
and i don´t know how to connect these 3 things ( ultrasonic sensor, relay, motion sensor)
the motion sensor because everything should be off if the dog is around and drinks.
so for my logic it should be something like:
bowl empty (45cm)
bowl full (35cm)

if ultrasonic sensor > 44cm
then send command on to relay switch
if ultrasonic sensor > 35cm
then send command off to relay switch

but the syntax is more then wrong ;-) and i don´t really know how i will put the motion sensor in there.

thanks for your help

Re: Water Level Control Relay Rule

Posted: 18 Feb 2018, 14:40
by Michael_BruceLee
on Wasserstand#Distance>44 do
if [Bewegung#Contact]=0
gpio,13,0
else
gpio,13,1
endif
endon

Ultrasonic Sensor Name = Wasserstand, Value: Distance
Pir Sensor Name = Bewegung, Value: Contact , 1=On, 0=Off
Relay Switch Name = Relay, Value: Switch, gpio 13 , 0=On, 1=Off

would this be right? but how do i connect the relay toggle off rule when distance is <35?

Re: Water Level Control Relay Rule

Posted: 18 Feb 2018, 18:42
by budman1758
You did not mention the pir sensor at first. That changes things quite a bit because rules don't allow multiple "if" or "and" statements. So I would look at creating "events" based on the water level. This way you can make up for the rule limits. Something like this....

On [waterlevel]=50
event,fill
else
endon

on fill do
if pir = whatever
gpio 1 1
else
gpio 1 0

Something along those lines. Using events allows you to take more than one thing into consideration when evaluating what to do and when to do it. Also you can use either the pulse commands for the gpio or timers so the water does not overfill. :lol:
Hope this is helpful.

Re: Water Level Control Relay Rule

Posted: 20 Feb 2018, 22:38
by Michael_BruceLee
thanks alot man!!! now it works!!
great!!