switching relay with Temperature and/or Humidity

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
Beliar_666
New user
Posts: 8
Joined: 11 Apr 2019, 00:08

switching relay with Temperature and/or Humidity

#1 Post by Beliar_666 » 03 Feb 2021, 15:46

Hello,

I want o switch a relay when my temp is under a certain value, and switch back when the value is reached back.

I Use a BME280 to measure and a relay connected to gpio12 I have figured out to switch the relay with following rule

Code: Select all

On System#Boot do
 gpio,13,1
endon

on Aussen#temperature do
  if %eventvalue1% > 27
          gpio,13,0

endif
  else
   on Aussen#temperature do
  if %eventvalue1% < 27
          gpio,13,1

  endif
endon
Is this the right way? I tried it out and it works, but maybe i could do the ruleset better?

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: switching relay with Temperature and/or Humidity

#2 Post by TD-er » 03 Feb 2021, 16:34

Nope that's not the right way.

The "on ... do" part of the rules mark a block of code that should be handled when there is an event.
So you cannot have an else part starting with on...do

If you try to match the same event for several values, it is best to check the %eventvalue1% values within this on...do .... endon block.

See also https://espeasy.readthedocs.io/en/lates ... Rules.html

Beliar_666
New user
Posts: 8
Joined: 11 Apr 2019, 00:08

Re: switching relay with Temperature and/or Humidity

#3 Post by Beliar_666 » 03 Feb 2021, 18:27

ok, i tried the quick and dirty way, this also works:

Code: Select all

On System#Boot do
 gpio,13,1
endon

on Aussen#temperature>27 do
          gpio,13,0
endon   

on Aussen#temperature<27 do
          gpio,13,1
endon
Is this the better way?

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

Re: switching relay with Temperature and/or Humidity

#4 Post by Ath » 03 Feb 2021, 19:58

You'd better, as suggested, have 1 event handler (on .. do/endon) like this:

Code: Select all

On System#Boot do
  gpio,13,1
endon

on Aussen#temperature do
  if %eventvalue1% > 27
    gpio,13,0
  endif
  if %eventvalue1% < 27
    gpio,13,1
  endif
endon
/Ton (PayPal.me)

Beliar_666
New user
Posts: 8
Joined: 11 Apr 2019, 00:08

Re: switching relay with Temperature and/or Humidity

#5 Post by Beliar_666 » 04 Feb 2021, 18:24

Ok, i tried it out and it works. I don´t understand it very well, but what exactly means %eventvalue1% and can i use %eventvalue1% in every rule or do i have to give it different numbers, e.g. %eventvalue1% , %eventvalue2% ... ?

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

Re: switching relay with Temperature and/or Humidity

#6 Post by Ath » 04 Feb 2021, 20:05

The up to date documentation on Rules can be found here: https://espeasy.readthedocs.io/en/lates ... Rules.html

Every event that's executed can get up to 4 arguments. These can be accessed by the %eventvalue1% through %eventvalue4% names. There is also %eventvalue%, and that's an alias for %eventvalue1%, often used when only 1 value is passed to the eventhandler.
The use of %eventvalue1..4% is advised over the use of [Task#Value], even if that should be the same value, as events are queued, including the values at that time, but other events, executed before the event at hand, can possibly alter the value, or a sensor may get new data, and that will get its own event queued after the current one.
/Ton (PayPal.me)

Post Reply

Who is online

Users browsing this forum: No registered users and 20 guests