Relay On when Temperature = x

160 views
Skip to first unread message

Keith

unread,
Feb 7, 2015, 11:27:35 PM2/7/15
to privat...@googlegroups.com
Is there a way to turn the relay on / off with certain temperature readings?

I've set it up using the Rules, that if sensor value is between x and y then relay on, but the relay never kicks on.

I've also tried setting it up with the siren on, and it does not work either for temperature.

Is there something I am missing, or is the program not written to allow the temperature to control a relay?

Thanks,
Keith

Gadjet Nut

unread,
Feb 8, 2015, 10:47:15 AM2/8/15
to privat...@googlegroups.com
Both should work. Have you configured the setting in globals.py:

RelayPin=12 

Where 12 is the GPIO header pin number which is connected to the relay.


Gadjet Nut

unread,
Feb 8, 2015, 11:10:20 AM2/8/15
to privat...@googlegroups.com
I ran a quick test and here is what you should see. I am using DHT22.py, but you would see the same using dallas.py. 

 - Edit your globals.py and set PrintToScreen = True
 - I have configured a rule that if the sensor value is between 20 and 30 then RelayOn
 - Relay is connected to pin 11 and I have set RelayPin = 11 in globals.py

Run dht22.py from the command line:

root@raspberrypi:/home# python dht22.py
Reading DHT22 sensor
Temperature = 21.8
Humidity = 22.7
/RELAYON,8,999,/n

From the above you can see the http request going to the server with a temperature value of 21.8 and then the server responds with /RELAYON,8,999,/n which is the command that dht22.py will use to trigger the relay. 




Keith

unread,
Feb 8, 2015, 11:29:50 AM2/8/15
to privat...@googlegroups.com
I tried your test, and I see the host update going to the server, however I never get a return of
 /RELAYON,8,999,/n

I'm using the Dallas.py program and a DS18B20 sensor.

I have the rule configured as IF Sensor value is between 0.00 AND 100.00
(Actual temperature is around 77 F )


For testing I hooked up a PIR and made it turn on the relay when motion is detected, and that works, so I know the relay is working, and wired up correctly. 

Gadjet Nut

unread,
Feb 8, 2015, 12:09:47 PM2/8/15
to privat...@googlegroups.com
Tested it on dallas.py:



Keith

unread,
Feb 8, 2015, 1:57:10 PM2/8/15
to privat...@googlegroups.com
I think I might be getting closer to figuring it out.

I think it may be set up backwards?  Relay Off will turn the relay on, but the relay has to be already be on (via motion detector) before it will stay on via the rules script for the temperature value.

It is really confusing me.

When I log in and run the alarm.py program with print to screen=true this is what I get when I'm using the PIR with Sensor open = relay off , Sensor closed = relay on  (*and no temperature rules configured for this test*)


And when motion is detected, the relay opens, but according to the log, the relay is shutting off, correct?  Sensor closed = 1, correct?  Or do I have that part wrong ?

Keith

unread,
Feb 8, 2015, 2:09:21 PM2/8/15
to privat...@googlegroups.com
I'm sure the next question will be what kind of relay I'm using, and here is a picture of it.

I connect GND to Ground
IN1 to Pin 12
And VCC gets connected to 5vdc


relay.jpg

Gadjet Nut

unread,
Feb 8, 2015, 2:48:18 PM2/8/15
to privat...@googlegroups.com
For a door switch or motion sensor the sensor is open when the circuit is broken (think of a reed switch opening when a door opens).

So now that you are able to see the relay message coming back from the server have you tried creating a rule for the temperature? The RELAYON message will make the GPIO high. If you have an inverted relay then configure the rule to go off when temperature range is met.

Keith

unread,
Feb 8, 2015, 3:09:20 PM2/8/15
to privat...@googlegroups.com
I think I finally got it working "good enough" to fit my needs.

I couldn't get the relay on/off to work correctly.  
I also had problems with the siren and chime.

It appears the instructions are wrong in globals.py.
For example:  Siren=GPIO18 is actually Pin 18 or GPIO24.

Once I figured that out, my siren/chime started working.  However it always has power going to it until an alarm is triggered, then for x seconds it goes low.  At least that is how mine is working.  Maybe my relay is inverted, I don't know.

Anyway, what I am trying to do is if Temp = X then trigger the relay (or siren/chime)  I can get it to trigger the chime, so that's what I'm using, and that will work for my case.

So it appears I finally figured out how to make it work for what I need.  Now I just get to test it out in the real world to see if the rest of my system works like I think it should.

Keith

unread,
Feb 13, 2015, 8:10:58 PM2/13/15
to privat...@googlegroups.com
For anyone else who has relay problems, be careful what you buy.

And the relay triggers on a LOW and not a HIGH.
So, the relay is always triggered, hence my confusion.  I mistakenly thought they relay would trigger on a high. 

Now it has been many many years since I took a digital electronics class, but isn't there a microchip that reverses that?  Anyone have any ideas how to make one of these cheap relays function the 'correct' way?

Gadjet Nut

unread,
Feb 13, 2015, 10:10:32 PM2/13/15
to
Save yourself the hassle and buy one that triggers when the input is high:


Or have you considered just revesing the rule. When the temperature is between x and y then Relay Off (instead of on).

Anthony Faugno

unread,
Mar 10, 2015, 4:55:06 PM3/10/15
to privat...@googlegroups.com
Do you offer a multiple channel relay?

Gadjet Nut

unread,
Mar 10, 2015, 6:38:03 PM3/10/15
to privat...@googlegroups.com
We are planning to. Do you want me to check with my supplier? They have both 2 and 4 channel relays ready built. 

Anthony Faugno

unread,
Mar 10, 2015, 8:27:00 PM3/10/15
to privat...@googlegroups.com
Yes please that would be great.

Gadjet Nut

unread,
Mar 10, 2015, 9:04:04 PM3/10/15
to privat...@googlegroups.com

We'll have these two in stock with 2 weeks.



Keith

unread,
Mar 10, 2015, 9:10:50 PM3/10/15
to privat...@googlegroups.com
Do those trigger when the input it high?
They look identical to the ones I have, and they trigger when the input is low.

Gadjet Nut

unread,
Mar 12, 2015, 11:39:20 PM3/12/15
to privat...@googlegroups.com
No they trigger on low. Is that an issue?
Reply all
Reply to author
Forward
0 new messages