Page 1 of 1

rule to control relay

Posted: 01 May 2021, 15:48
by florin.ssk@gmail.com
Hello,


I have a wemos d1 mini whit espeasy to which a humidity sensor is attached.
I would like that when I register a certain value, (less than X) an ON command to be sent to the relay with the IP 192.x.x.x (esp01 + tasmota).

somebody can help me pls ?

Re: rule to control relay

Posted: 01 May 2021, 16:48
by Ath
Welcome.

First you need to have enabled the Rules feature on the Tools/ Advanced page:

Screenshot - 01_05_2021 , 16_38_07.png
Screenshot - 01_05_2021 , 16_38_07.png (10.31 KiB) Viewed 6887 times

(Tolerant last parameter is optional, both Rules checkboxes should be on)

After that you can enter a new rule in the Rules tab.

Code: Select all

on BME280#Humidity do
  if %eventvalue1% <> %v1%
    if %eventvalue% < 20 // A bit dry, turn humidifier on
      sendtohttp,192.x.x.x,80,/cm?cmnd=Power%20ON // Turn relay on
    endif
    if %eventvalue1% > 30 // Humid enough, humidifier off
      sendtohttp,192.x.x.x,80,/cm?cmnd=Power%20OFF // Turn relay off
    endif
  endif
  let,1,%eventvalue1% // Save last checked value
endon
I've assumed a BME280 sensor in this example, and the 20 and 30 used are just somewhat randomly selected values.

Re: rule to control relay

Posted: 01 May 2021, 20:30
by florin.ssk@gmail.com
humidity information is taken from a soil moisture sensor. I already have the active rule option, because I have another rule. I attach print screen with sensors.


Thanks for the help

Re: rule to control relay

Posted: 01 May 2021, 21:16
by Ath
florin.ssk@gmail.com wrote: 01 May 2021, 20:30 I attach print screen with sensors.
Please attach files or screenshots in this forum, not on external, usually unreliable, image storage. After a while they won't be available anymore, so we can't see what was going on.

And rules can be added in a [ code ] [ /code ] tag (without the spaces, I added these so it will show here)

Re: rule to control relay

Posted: 01 May 2021, 21:20
by Ath
Sending data to Domoticz is (much) easier by using a Controller, preferably the Domoticz MQTT controller, but you will need a MQTT server too (Mosquitto is often used in combination with Domoticz). Domoticz HTTP will do fine too.

Re: rule to control relay

Posted: 01 May 2021, 22:00
by florin.ssk@gmail.com
I have msqt too .
i have some sensors in the house.
termostat
some shelly 2.5 the control some blinds.
Outside i want to control 1 electrovalve to open/close the water when the soil is to dry. i have the info, but i do not know to make the next step.
i do not know how to configure the rule :(

i atached the file whit the img.

Thx

Re: rule to control relay

Posted: 02 May 2021, 13:54
by Ath
You can extend the current rule with what I posted before (cleaned it up a bit), that would then be like this:

Code: Select all

on Soil#Analog do // Values are passed via %eventvalue1%..%eventvalue4%, and %eventvalue% is an alias for %eventvalue1%
  SendToHTTP,192.168.0.115,8080,/json.htm?param=udevice&type=command&idx=26&nvalue=%eventvalue1%
  if %eventvalue% < 1 // A bit dry, turn water pump on
    SendToHTTP,192.x.x.x,80,/cm?cmnd=Power%20ON // Turn Tasmota relay on
  endif
  if %eventvalue1% > 3 // Wet enough, water pump off
    SendToHTTP,192.x.x.x,80,/cm?cmnd=Power%20OFF // Turn Tasmota relay off
  endif
endon
NB: Each Rules set can contain multiple rules, a new rule starts with 'on <event> do', and ends with 'endon'

Re: rule to control relay

Posted: 03 May 2021, 19:44
by florin.ssk@gmail.com
And....

it's Workig !!
THX !!!
Now, i just find the corect value when the relay must be on/off.

thx again !!!!!

Re: rule to control relay

Posted: 03 May 2021, 20:02
by Ath
Great! Thanks for reporting back.

Re: rule to control relay

Posted: 10 May 2021, 17:33
by florin.ssk@gmail.com
Hello again,

the rule made by you works very well. in this way thank you once again.
because the water pressure does not allow I would like to make 2 zones (zone 1 and zone 2) each zone controlled by a 1 relay, but not to run simultaneously. Can you help me change my rule so that
SendToHTTP, 192.x.x.ZZZ, 80, / cm? Cmnd = Power% 20ON // Turn Tasmota relay on
endif

to send the same order to another IP 192.x.x. YYY , but with a delay of 30 minutes?

Thank you,

Re: rule to control relay

Posted: 10 May 2021, 20:13
by Ath
That should be doable, just to be sure: The seconds relay should be turned on 30 min. after the first is turned on, and also off again 30 minutes after the first is turned off?

Code: Select all

on Soil#Analog do // Values are passed via %eventvalue1%..%eventvalue4%, and %eventvalue% is an alias for %eventvalue1%
  SendToHTTP,192.168.0.115,8080,/json.htm?param=udevice&type=command&idx=26&nvalue=%eventvalue1%
  if %eventvalue% < 1 // A bit dry, turn water pump on
    SendToHTTP,192.x.x.x,80,/cm?cmnd=Power%20ON // Turn Tasmota relay on
    TimerSet,1,1800 // Timer in seconds, 30m * 60 sec.
  endif
  if %eventvalue1% > 3 // Wet enough, water pump off
    SendToHTTP,192.x.x.x,80,/cm?cmnd=Power%20OFF // Turn Tasmota relay off
    TimerSet,2,1800 // Timer in seconds, 30m * 60 sec.
  endif
endon

on rules#timer=1 do
  SendToHTTP,192.x.x.yyy,80,/cm?cmnd=Power%20ON // Turn second Tasmota relay on
endon

on rules#timer=2 do
  SendToHTTP,192.x.x.yyy,80,/cm?cmnd=Power%20OFF // Turn second Tasmota relay off
endon
Another solution could be to start the second pump after the first one stops, and run it for the same amount of time, if you need that, just ask.

Re: rule to control relay

Posted: 11 May 2021, 19:12
by florin.ssk@gmail.com
THX!
i gone try like this !

Re: rule to control relay

Posted: 18 May 2021, 19:03
by florin.ssk@gmail.com
Hello,

Thank you for your effort. I eventually used variant number 1. in the meantime I discovered that in "domoticz" I can make rules. I used the rule there, which I find easier.
thanks again for your help.


for the delay I used the delay option.

Re: rule to control relay

Posted: 18 May 2021, 19:08
by Ath
Great, a solution is a solution ;) thanks for reporting back :)