import time # this is driving a SSR that's powering a AC-powered humidifier # we don't need voltage readings for this one class HumidifierV3: def __init__(self): self.last_toggle = 0 self.last_state = False self.cooldown = 5 def set(self, s, on): if on != self.last_state: if (time.time() - self.last_toggle) < self.cooldown: return if on: s.write(b"Z") s.flush() else: s.write(b"z") s.flush() if self.last_state != on: self.last_toggle = time.time() self.last_state = on