Ejemplo n.º 1
0
 def calc_output(self):
     """calculate controll output and handle autotune"""
     if self.autotune != "none":
         if self.pidAutotune.run(self._cur_temp):
             params = self.pidAutotune.get_pid_parameters(self.autotune)
             self.kp = params.Kp
             self.ki = params.Ki
             self.kd = params.Kd
             _LOGGER.info(
                 "Set Kd, Ki, Kd. "
                 "Smart thermostat now runs on PID Controller. %s,  %s,  %s",
                 self.kp, self.ki, self.kd)
             self.pidController = pid_controller.PIDArduino(
                 self._keep_alive.seconds, self.kp, self.ki, self.kd,
                 self.minOut, self.maxOut, time.time)
             self.autotune = "none"
         self.control_output = self.pidAutotune.output
     else:
         _LOGGER.info("Calculating PID values")
         self.control_output = self.pidController.calc(
             self._cur_temp, self._target_temp)
     self.control_output = round(self.control_output)
     _LOGGER.info("Obtained current control output. %s",
                  self.control_output)
     self.set_controlvalue()
Ejemplo n.º 2
0
    def __init__(self, hass, 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_operation_mode, difference, away_temp, kp, ki,
                 kd, pwm, autotune, noiseband):
        """Initialize the thermostat."""
        self.hass = hass
        self._name = name
        self.heater_entity_id = heater_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._initial_operation_mode = initial_operation_mode
        self._saved_target_temp = target_temp if target_temp is not None \
            else away_temp
        if self.ac_mode:
            self._current_operation = STATE_COOL
            self._operation_list = [STATE_COOL, STATE_OFF]
            self.minOut = -difference
            self.maxOut = 0
        else:
            self._current_operation = STATE_HEAT
            self._operation_list = [STATE_HEAT, STATE_OFF]
            self.minOut = 0
            self.maxOut = difference
        if initial_operation_mode == STATE_OFF:
            self._enabled = False
            self._current_operation = STATE_OFF
        else:
            self._enabled = True
        self._active = False
        self._cur_temp = None
        self._min_temp = min_temp
        self._max_temp = max_temp
        self._target_temp = target_temp
        self._unit = hass.config.units.temperature_unit
        self._support_flags = SUPPORT_FLAGS
        if away_temp is not None:
            self._support_flags = SUPPORT_FLAGS | SUPPORT_AWAY_MODE
        self.difference = difference
        self._away_temp = away_temp
        self._is_away = False
        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)

        async_track_state_change(
            hass, sensor_entity_id, self._async_sensor_changed)
        async_track_state_change(
            hass, heater_entity_id, self._async_switch_changed)

        if self._keep_alive:
            async_track_time_interval(
                hass, self._async_keep_alive, self._keep_alive)

        sensor_state = hass.states.get(sensor_entity_id)
        if sensor_state and sensor_state.state != STATE_UNKNOWN:
            self._async_update_temp(sensor_state)