rule to control relay

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
florin.ssk@gmail.com
New user
Posts: 7
Joined: 01 May 2021, 15:40

rule to control relay

#1 Post by florin.ssk@gmail.com » 01 May 2021, 15:48

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 ?

User avatar
Ath
Normal user
Posts: 3415
Joined: 10 Jun 2018, 12:06
Location: NL

Re: rule to control relay

#2 Post by Ath » 01 May 2021, 16:48

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 6807 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.
/Ton (PayPal.me)

florin.ssk@gmail.com
New user
Posts: 7
Joined: 01 May 2021, 15:40

Re: rule to control relay

#3 Post by florin.ssk@gmail.com » 01 May 2021, 20:30

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
Attachments
sensor.jpg
sensor.jpg (164.59 KiB) Viewed 6783 times
rule.jpg
rule.jpg (117.07 KiB) Viewed 6783 times
Last edited by florin.ssk@gmail.com on 01 May 2021, 22:02, edited 4 times in total.

User avatar
Ath
Normal user
Posts: 3415
Joined: 10 Jun 2018, 12:06
Location: NL

Re: rule to control relay

#4 Post by Ath » 01 May 2021, 21:16

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)
/Ton (PayPal.me)

User avatar
Ath
Normal user
Posts: 3415
Joined: 10 Jun 2018, 12:06
Location: NL

Re: rule to control relay

#5 Post by Ath » 01 May 2021, 21:20

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.
/Ton (PayPal.me)

florin.ssk@gmail.com
New user
Posts: 7
Joined: 01 May 2021, 15:40

Re: rule to control relay

#6 Post by florin.ssk@gmail.com » 01 May 2021, 22:00

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

User avatar
Ath
Normal user
Posts: 3415
Joined: 10 Jun 2018, 12:06
Location: NL

Re: rule to control relay

#7 Post by Ath » 02 May 2021, 13:54

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'
/Ton (PayPal.me)

florin.ssk@gmail.com
New user
Posts: 7
Joined: 01 May 2021, 15:40

Re: rule to control relay

#8 Post by florin.ssk@gmail.com » 03 May 2021, 19:44

And....

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

thx again !!!!!

User avatar
Ath
Normal user
Posts: 3415
Joined: 10 Jun 2018, 12:06
Location: NL

Re: rule to control relay

#9 Post by Ath » 03 May 2021, 20:02

Great! Thanks for reporting back.
/Ton (PayPal.me)

florin.ssk@gmail.com
New user
Posts: 7
Joined: 01 May 2021, 15:40

Re: rule to control relay

#10 Post by florin.ssk@gmail.com » 10 May 2021, 17:33

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,

User avatar
Ath
Normal user
Posts: 3415
Joined: 10 Jun 2018, 12:06
Location: NL

Re: rule to control relay

#11 Post by Ath » 10 May 2021, 20:13

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.
/Ton (PayPal.me)

florin.ssk@gmail.com
New user
Posts: 7
Joined: 01 May 2021, 15:40

Re: rule to control relay

#12 Post by florin.ssk@gmail.com » 11 May 2021, 19:12

THX!
i gone try like this !

florin.ssk@gmail.com
New user
Posts: 7
Joined: 01 May 2021, 15:40

Re: rule to control relay

#13 Post by florin.ssk@gmail.com » 18 May 2021, 19:03

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.
Attachments
delay.jpg
delay.jpg (38.92 KiB) Viewed 6102 times
qqqq.jpg
qqqq.jpg (55.9 KiB) Viewed 6102 times

User avatar
Ath
Normal user
Posts: 3415
Joined: 10 Jun 2018, 12:06
Location: NL

Re: rule to control relay

#14 Post by Ath » 18 May 2021, 19:08

Great, a solution is a solution ;) thanks for reporting back :)
/Ton (PayPal.me)

Post Reply

Who is online

Users browsing this forum: Google [Bot] and 14 guests