Skip to content

Instantly share code, notes, and snippets.

@CamDavidsonPilon
Last active January 8, 2023 01:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CamDavidsonPilon/2e0caaa3675b12198d421e83fc0d6ad9 to your computer and use it in GitHub Desktop.
Save CamDavidsonPilon/2e0caaa3675b12198d421e83fc0d6ad9 to your computer and use it in GitHub Desktop.
# -*- 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