Ds18b20 and relay rule

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
smartie
New user
Posts: 9
Joined: 10 Feb 2017, 23:09

Ds18b20 and relay rule

#1 Post by smartie » 21 Apr 2017, 17:08

Hi

How do you write a rule for a sonoff and espeasy with a ds18b20 temp,

I wish to turn relay on or off if temp gets above say 30 degrees or below 30 degrees

Thanks for your help,

Shardan
Normal user
Posts: 1156
Joined: 03 Sep 2016, 23:27
Location: Bielefeld / Germany

Re: Ds18b20 and relay rule

#2 Post by Shardan » 21 Apr 2017, 20:49

Hello,

I'll give it a try, be aware I couldn't test it.

<task> The name you gave the DS18B20 task.
<value> The name you gave the value within the task, e.g. "temperature"

Code: Select all

on <task>#<value> do
    if [<task>#<value>] > 30
        gpio,<GPIO of relay>,1                    switches GPIO to high if temperature is above 30°
    endif
    if [<task>#<value>] < 29
        gpio,<GPIO of relay>,0                    switches GPIO to low if temperature is above 30°
    endif
endon
I've chosen 30° and 29°, not 30° and 30° for a reason.
This gap ("hysteresis") avoids "flickering", a quick on/off/on/off switching if the value is fluctuating around 30°.
If you have a "Sonoff basic" the GPIO for the relay is GPIO12. so the lines should read "gpio,12,1" and "gpio,12,0" for that.


Regards
Shardan
Regards
Shardan

smartie
New user
Posts: 9
Joined: 10 Feb 2017, 23:09

Re: Ds18b20 and relay rule

#3 Post by smartie » 22 Apr 2017, 10:45

Hi

Thankyou will try later and report back

peces
New user
Posts: 7
Joined: 22 Feb 2018, 22:51

Re: Ds18b20 and relay rule

#4 Post by peces » 22 Feb 2018, 22:54

Hi,
I needed it, tried it, and Shardan's rule works perfectly !
So thank you very much !

zulfiqaradil
New user
Posts: 4
Joined: 22 Feb 2018, 20:42

Re: Ds18b20 and relay rule

#5 Post by zulfiqaradil » 23 Feb 2018, 08:48

Shardan wrote: 21 Apr 2017, 20:49 Hello,

I'll give it a try, be aware I couldn't test it.

<task> The name you gave the DS18B20 task.
<value> The name you gave the value within the task, e.g. "temperature"

Code: Select all

on <task>#<value> do
    if [<task>#<value>] > 30
        gpio,<GPIO of relay>,1                    switches GPIO to high if temperature is above 30°
    endif
    if [<task>#<value>] < 29
        gpio,<GPIO of relay>,0                    switches GPIO to low if temperature is above 30°
    endif
endon
I've chosen 30° and 29°, not 30° and 30° for a reason.
This gap ("hysteresis") avoids "flickering", a quick on/off/on/off switching if the value is fluctuating around 30°.
If you have a "Sonoff basic" the GPIO for the relay is GPIO12. so the lines should read "gpio,12,1" and "gpio,12,0" for that.


Regards
Shardan
You need to set threshold level to avoid flickering in your case.

Shardan
Normal user
Posts: 1156
Joined: 03 Sep 2016, 23:27
Location: Bielefeld / Germany

Re: Ds18b20 and relay rule

#6 Post by Shardan » 23 Feb 2018, 11:29

A threshhold says "Switch at x°C".
This - without a hysteresis defined - will directly lead to flickering relays.

It's for a reason i've chosen a wide hysteresis of 1°C for this example.

Rgds
Shardan
Regards
Shardan

User avatar
grovkillen
Core team member
Posts: 3621
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: Ds18b20 and relay rule

#7 Post by grovkillen » 23 Feb 2018, 19:51

Here's what happens with a system with no hysteresis...

Thermostat in my bathroom
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you :idea: :idea: :idea:

Shardan
Normal user
Posts: 1156
Joined: 03 Sep 2016, 23:27
Location: Bielefeld / Germany

Re: Ds18b20 and relay rule

#8 Post by Shardan » 23 Feb 2018, 20:30

hey... if you modify that a bit you may use it as a kind of pulse width modulation... :twisted:
Regards
Shardan

User avatar
grovkillen
Core team member
Posts: 3621
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: Ds18b20 and relay rule

#9 Post by grovkillen » 23 Feb 2018, 21:35

Shardan wrote: 23 Feb 2018, 20:30 hey... if you modify that a bit you may use it as a kind of pulse width modulation... :twisted:
Hehe probably. I really can't understand how they missed that part...
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you :idea: :idea: :idea:

zulfiqaradil
New user
Posts: 4
Joined: 22 Feb 2018, 20:42

Re: Ds18b20 and relay rule

#10 Post by zulfiqaradil » 23 Feb 2018, 22:11

I dont think so PWM is the solution.
Just do like this to get rid of it
First add two local variable for example Lower_Threshold and Higher_Threshold and now set Lower_Threshold value to 29C and for Higher_Threshold set it to 30C and with this setting now you have two fixed values one is 29C and 2nd is 30C and in your case you want to switch that thermostat to set OFF if reach 30C and back ON if its <30 and this is the point you need to use these two threshold levels accept your actual temperature value like this

Code: Select all

on Current_Temp#Current_Temp_Value do
    if [Current_Temp_Value #Higher_Threshold ] > 30  // Turn off relay 
        gpio,<GPIO of relay>,1                   
    endif
    if [Current_Temp_Value #Lower_Threshold ] < 29  // Turn on relay with one degree of freedom
        gpio,<GPIO of relay>,0                   
    endif
endon
This is just overview the logic which I meant to and I hope you get my point

Post Reply

Who is online

Users browsing this forum: No registered users and 41 guests