Created
February 21, 2022 12:01
-
-
Save crbyxwpzfl/4413422f8fe828141f09e5f8000ab783 to your computer and use it in GitHub Desktop.
python for hb thermostat colling fan 3141
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import privates variable | |
import sys | |
characteristic = sys.argv[3].strip("''") | |
Statuspath = "/home/pi/spinala/Status.txt" | |
if sys.argv[1] == "Get": | |
if characteristic == "Name": | |
print("raspberry") | |
sys.exit() | |
if characteristic == "TemperatureDisplayUnits": | |
print("CELSIUS") | |
sys.exit() | |
if characteristic == "HeatingThresholdTemperature": | |
print("0") | |
sys.exit() | |
if characteristic == "TargetTemperature" or characteristic == "CoolingThresholdTemperature": | |
print("10") | |
sys.exit() | |
if characteristic == "CurrentHeatingCoolingState" or characteristic == "TargetHeatingCoolingState": | |
f = open(Statuspath, 'r') | |
status = f.read() | |
f.close() | |
import RPi.GPIO as GPIO | |
GPIO.setwarnings(False) | |
fan = 21 | |
GPIO.setmode(GPIO.BCM) | |
GPIO.setup(fan,GPIO.OUT) | |
#cool | |
if int(status) == 2: | |
GPIO.output(fan,1) | |
#heat | |
if int(status) == 1: | |
GPIO.output(fan,0) | |
print(status) | |
sys.exit() | |
if characteristic == "CurrentTemperature": | |
#read cpu temp | |
from gpiozero import CPUTemperature | |
cpu = CPUTemperature() | |
cputemp = round(cpu.temperature) | |
#set status to cooling | |
if cputemp > 40: | |
f = open(Statuspath, 'w') | |
f.write("2") #status cool | |
f.close | |
#set status to heating | |
if cputemp < 30: | |
f = open(Statuspath, 'w') | |
f.write("1") #status heat | |
f.close | |
print(cputemp) | |
sys.exit() | |
if sys.argv[1] == "Set": | |
if characteristic == "TargetHeatingCoolingState": | |
value = sys.argv[4].strip("''") | |
value = int(value) | |
import RPi.GPIO as GPIO | |
GPIO.setwarnings(False) | |
fan = 21 | |
GPIO.setmode(GPIO.BCM) | |
GPIO.setup(fan,GPIO.OUT) | |
#off | |
if int(value) == 0 or int(value) == 3: | |
#not handled on purpose | |
sys.exit() | |
#heat | |
if int(value) == 1: | |
GPIO.output(fan,0) | |
f = open(Statuspath, 'w') | |
f.write(value) | |
f.close | |
sys.exit() | |
#cool | |
if int(value) == 2: | |
GPIO.output(fan,1) | |
f = open(Statuspath, 'w') | |
f.write(value) | |
f.close | |
sys.exit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment