mholgatem / ThermOS

Another Raspberry Pi Thermostat
https://mholgatem.github.io/ThermOS/
MIT License
77 stars 17 forks source link

Please Help #6

Closed BobDeath closed 7 years ago

BobDeath commented 7 years ago

I need to make the relay GPIO signals active low (signals are "inverted" for my cheap relays) is there a simple way to do this I am not very fluent in Java

mholgatem commented 7 years ago

There is good news and bad news. You don't have to work with Java! So the code that you are looking for is located in the files thermostat_daemon.py and thermostat_web.py ( it's written in Python ). It's relatively easy to change the code for your purposes, but let me give you a warning first.

WARNING

I highly stress that you buy a RELAY THAT DEFAULTS OPEN. If you use a relay that defaults closed, then anytime that your pi is rebooting or if the sd card corrupts or the app crashes, all of your terminals will be active. I picked up an 8 channel on Amazon for $15 and an 8 channel on Ebay for $9 (free 2 week shipping). It's definitely worth it.

INSTRUCTIONS

If you are still determined to continue, this is what you will need to do: FIRST, In thermostat_daemon.py, create 2 Global variables (just above class ThermOSDaemon(object):

GPIO_ON = GPIO.LOW GPIO_OFF = GPIO.HIGH

SECOND, Change the gpio initial state FROM:

GPIO.setup(self.config['heater_pin'], GPIO.OUT, initial=GPIO.LOW) GPIO.setup(self.config['ac_pin'], GPIO.OUT, initial=GPIO.LOW) GPIO.setup(self.config['fan_pin'], GPIO.OUT, initial=GPIO.LOW)

TO:

GPIO.setup(self.config['heater_pin'], GPIO.OUT, initial=GPIO_OFF) GPIO.setup(self.config['ac_pin'], GPIO.OUT, initial=GPIO_OFF) GPIO.setup(self.config['fan_pin'], GPIO.OUT, initial=GPIO_OFF)

THIRD, Change all lines that read:

GPIO.output(self.config[...], True)

to

GPIO.output(self.config[...], GPIO_ON)

And all lines that read:

GPIO.output(self.config[...], False)

to

GPIO.output(self.config[...], GPIO_OFF)

LASTLY, you will need to repeat those steps for thermostat_web.py

  1. add global variables GPIO_ON, GPIO_OFF [ LINE 49 ]
  2. edit GPIO.setup GPIO.setup(..., GPIO.OUT, initial = GPIO_OFF) [ LINE 56, LINE 645 ]
  3. change GPIO.output(oldPins, False) to GPIO.output(oldPins, GPIO_OFF) [ LINE 633 ]
  4. edit LINE 225 from this: temp = "ON" if type(value) == int and GPIO.input(value) else "OFF" to this: temp = "ON" if type(value) == int and GPIO.input(value) == GPIO_ON else "OFF"

This is untested code, so it may introduce some bugs that you'll need to work around!

BobDeath commented 7 years ago

thank you for responding so fast , The solution I ended up with was to make a simple inverter with NPN transistor and 2 resistors per relay.. But i will play the code you sent me for the education and experience. I like playing around with PYTHON

mholgatem commented 7 years ago

ooh, that's a good solution. I didn't even think of doing something like that. Let me know if you run into anything else.