Created
May 21, 2021 04:27
-
-
Save Factoid/c7ce4b6cc2b1ae11aff37919a3f9b5c7 to your computer and use it in GitHub Desktop.
Funhouse Circuit Python to compare temperature inside vs. outside
This file contains 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
from adafruit_funhouse import FunHouse | |
import alarm | |
import board | |
import re | |
import adafruit_requests | |
import wifi | |
import socketpool | |
import ssl | |
from secrets import secrets | |
reg = re.compile('var obTemperature = "(\d+)"') | |
funhouse = FunHouse(default_bg=None) | |
TEMPERATURE_OFFSET = ( | |
0 # Degrees C to adjust the temperature to compensate for board produced heat | |
) | |
funhouse.peripherals.dotstars.fill(0x101010) | |
funhouse.display.brightness = 0.0 | |
funhouse.peripherals._buttons[0].deinit() | |
touch_alarm = alarm.pin.PinAlarm(pin=board.BUTTON_DOWN, value=True, pull=False) | |
wifi.radio.connect(secrets["ssid"], secrets["password"]) | |
pool = socketpool.SocketPool(wifi.radio) | |
requests = adafruit_requests.Session(pool, ssl.create_default_context()) | |
def get_outside_temp(): | |
try: | |
url = "https://weather.gc.ca/wxlink/site_js/s0000472_e.js" | |
response = requests.get(url) | |
return int(reg.search(response.text).group(1)) | |
except: | |
return None | |
def get_inside_temp(): | |
return funhouse.peripherals.temperature - TEMPERATURE_OFFSET | |
while True: | |
funhouse.peripherals.dotstars.fill(0x101000) | |
if get_outside_temp() < get_inside_temp(): | |
funhouse.peripherals.dotstars.fill(0x001000) | |
else: | |
funhouse.peripherals.dotstars.fill(0x100000) | |
funhouse.enter_light_sleep(5) | |
funhouse.peripherals.dotstars.fill(0) | |
alarm.light_sleep_until_alarms(touch_alarm) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment