Example #1
0
 def __init__(self, name, heater_entity_id, sensor_entity_id, min_temp,
              max_temp, target_temp, ac_mode, min_cycle_duration,
              cold_tolerance, hot_tolerance, keep_alive, initial_hvac_mode,
              away_temp, precision, unit, difference, kp, ki, kd, pwm,
              autotune, noiseband):
     """Initialize the thermostat."""
     self._name = name
     self.heater_entity_id = heater_entity_id
     self.sensor_entity_id = sensor_entity_id
     self.ac_mode = ac_mode
     self.min_cycle_duration = min_cycle_duration
     self._cold_tolerance = cold_tolerance
     self._hot_tolerance = hot_tolerance
     self._keep_alive = keep_alive
     self._hvac_mode = initial_hvac_mode
     self._saved_target_temp = target_temp or away_temp
     self._temp_precision = precision
     if self.ac_mode:
         self._hvac_list = [HVAC_MODE_COOL, HVAC_MODE_OFF]
         self.minOut = -difference
         self.maxOut = 0
     else:
         self._hvac_list = [HVAC_MODE_HEAT, HVAC_MODE_OFF]
         self.minOut = 0
         self.maxOut = difference
     self._active = False
     self._cur_temp = None
     self._temp_lock = asyncio.Lock()
     self._min_temp = min_temp
     self._max_temp = max_temp
     self._target_temp = target_temp
     self._unit = unit
     self._support_flags = SUPPORT_FLAGS
     if away_temp:
         self._support_flags = SUPPORT_FLAGS | SUPPORT_PRESET_MODE
     self._away_temp = away_temp
     self._is_away = False
     self.difference = difference
     self.kp = kp
     self.ki = ki
     self.kd = kd
     self.pwm = pwm
     self.autotune = autotune
     self.sensor_entity_id = sensor_entity_id
     self.time_changed = time.time()
     if self.autotune != "none":
         self.pidAutotune = pid_controller.PIDAutotune(
             self._target_temp, self.difference, self._keep_alive.seconds,
             self._keep_alive.seconds, self.minOut, self.maxOut, noiseband,
             time.time)
         _LOGGER.warning(
             "Autotune will run with the next Setpoint Value you set."
             "changes, submited after doesn't have any effekt until it's finished"
         )
     else:
         self.pidController = pid_controller.PIDArduino(
             self._keep_alive.seconds, self.kp, self.ki, self.kd,
             self.minOut, self.maxOut, time.time)
Example #2
0
 def __init__(self, name, heater_entity_id, sensor_entity_id, min_temp, max_temp, target_temp, ac_mode, keep_alive,
              sampling_period, initial_hvac_mode, away_temp, eco_temp, boost_temp, comfort_temp, home_temp,
              sleep_temp, activity_temp, precision, unit, difference, kp, ki, kd, pwm, autotune, noiseband,
              lookback):
     """Initialize the thermostat."""
     self._name = name
     self.heater_entity_id = heater_entity_id
     self.sensor_entity_id = sensor_entity_id
     self.ac_mode = ac_mode
     self._keep_alive = keep_alive
     self._sampling_period = sampling_period.seconds
     self._hvac_mode = initial_hvac_mode
     self._saved_target_temp = target_temp or away_temp
     self._temp_precision = precision
     if self.ac_mode:
         self._hvac_list = [HVAC_MODE_COOL, HVAC_MODE_OFF]
         self.minOut = -difference
         self.maxOut = 0
     else:
         self._hvac_list = [HVAC_MODE_HEAT, HVAC_MODE_OFF]
         self.minOut = 0
         self.maxOut = difference
     self._active = False
     self._current_temp = None
     self._cur_temp_time = None
     self._previous_temp = None
     self._previous_temp_time = None
     self._temp_lock = asyncio.Lock()
     self._min_temp = min_temp
     self._max_temp = max_temp
     self._target_temp = target_temp
     self._unit = unit
     self._support_flags = SUPPORT_FLAGS
     if away_temp:
         self._support_flags = SUPPORT_FLAGS | SUPPORT_PRESET_MODE
     self._attr_preset_mode = 'none'
     self._away_temp = away_temp
     self._eco_temp = eco_temp
     self._boost_temp = boost_temp
     self._comfort_temp = comfort_temp
     self._home_temp = home_temp
     self._sleep_temp = sleep_temp
     self._activity_temp = activity_temp
     # self._is_away = False
     self.difference = difference
     self.kp = kp
     self.ki = ki
     self.kd = kd
     self.pwm = pwm.seconds
     self.p = self.i = self.d = 0
     self.control_output = 0
     self._force_on = False
     self._force_off = False
     self.autotune = autotune
     self._lookback = lookback.seconds
     self.sensor_entity_id = sensor_entity_id
     self.time_changed = time.time()
     self._last_sensor_update = time.time()
     if self.autotune != "none":
         self.pidAutotune = pid_controller.PIDAutotune(self._target_temp, self.difference,
                                                       max(1, self._sampling_period), self._lookback, self.minOut,
                                                       self.maxOut, noiseband, time.time)
         _LOGGER.warning("Autotune will run with the next Setpoint Value you set. Changes, submitted after doesn't "
                         "have any effect until it's finished")
     else:
         _LOGGER.debug("PID Gains: kp = %s, ki = %s, kd = %s", self.kp, self.ki, self.kd)
         self.pidController = pid_controller.PID(self.kp, self.ki, self.kd, self.minOut, self.maxOut,
                                                 self._sampling_period)
         self.pidController.mode = "AUTO"