-
-
Save CamDavidsonPilon/2e0caaa3675b12198d421e83fc0d6ad9 to your computer and use it in GitHub Desktop.
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
# -*- coding: utf-8 -*- | |
from __future__ import annotations | |
import time | |
from math import sin | |
from math import pi | |
from pioreactor.automations.temperature import Thermostat | |
class CycleTemp(Thermostat): | |
""" | |
Use 24hr temperature cycle | |
""" | |
automation_name = "cycle_temp" | |
published_settings = { | |
"target_temperature": {"datatype": "float", "unit": "℃", "settable": False} | |
} | |
def __init__(self, **kwargs) -> None: | |
self.bias_temperature = 35 | |
self.amplitude = 5 | |
initial_target_temperature = self.get_new_target_temperature() | |
super().__init__(target_temperature=initial_target_temperature, **kwargs) | |
def get_new_target_temperature(self): | |
current_seconds_in_day = time.time() % (60 * 60 * 24) | |
return self.bias_temperature + self.amplitude * sin(2 * pi * current_seconds_in_day / (60 * 60 * 24)) | |
def execute(self): | |
new_temp = self.get_new_target_temperature() | |
self.target_temperature = new_temp | |
self.logger.debug(f"Setting target temp to {self.target_temperature=}") | |
super().execute() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment