diff --git a/tasmota/my_user_config.h b/tasmota/my_user_config.h index c60c447a0..8e174630e 100644 --- a/tasmota/my_user_config.h +++ b/tasmota/my_user_config.h @@ -684,7 +684,6 @@ #define THERMOSTAT_TEMP_RAMPUP_DELTA_IN 4 // Default minimum delta temperature to target to get into rampup mode, in tenths of degrees celsius #define THERMOSTAT_TEMP_RAMPUP_DELTA_OUT 2 // Default minimum delta temperature to target to get out of the rampup mode, in tenths of degrees celsius #define THERMOSTAT_TEMP_PI_RAMPUP_ACC_E 20 // Default accumulated error when switching from ramp-up controller to PI -#define THERMOSTAT_ENERGY_OUTPUT_MAX 10 // Default maximum allowed energy output for thermostat valve in Watts #define THERMOSTAT_TIME_OUTPUT_DELAY 180 // Default output delay between state change and real actuation event (f.i. valve open/closed) #define THERMOSTAT_TEMP_INIT 180 // Default init target temperature for the thermostat controller diff --git a/tasmota/xdrv_39_thermostat.ino b/tasmota/xdrv_39_thermostat.ino index 25005717f..b6d2e2739 100644 --- a/tasmota/xdrv_39_thermostat.ino +++ b/tasmota/xdrv_39_thermostat.ino @@ -146,13 +146,22 @@ struct THERMOSTAT { int32_t time_total_pi; // Time total (proportional + integral) of the PI controller uint16_t kP_pi = 0; // kP value for the PI controller uint16_t kI_pi = 0; // kP value for the PI controller multiplied by 100 +<<<<<<< HEAD int16_t temp_measured = 0; // Temperature measurement received from sensor in tenths of degrees uint8_t time_output_delay = THERMOSTAT_TIME_OUTPUT_DELAY; // Output delay between state change and real actuation event (f.i. valve open/closed) uint8_t counter_rampup_cycles = 0; // Counter of ramp-up cycles +======= +>>>>>>> new_branch_dev int32_t temp_rampup_meas_gradient = 0; // Temperature measured gradient from sensor in thousandths of degrees per hour calculated during ramp-up uint32_t timestamp_rampup_start = 0; // Timestamp where the ramp-up controller mode has been started uint32_t time_rampup_deadtime = 0; // Time constant of the thermostat system (step response time) uint32_t time_rampup_nextcycle = 0; // Time where the ramp-up controller shall start the next cycle +<<<<<<< HEAD +======= + int16_t temp_measured = 0; // Temperature measurement received from sensor in tenths of degrees + uint8_t time_output_delay = THERMOSTAT_TIME_OUTPUT_DELAY; // Output delay between state change and real actuation event (f.i. valve open/closed) + uint8_t counter_rampup_cycles = 0; // Counter of ramp-up cycles +>>>>>>> new_branch_dev uint8_t output_relay_number = THERMOSTAT_RELAY_NUMBER; // Output relay number uint8_t input_switch_number = THERMOSTAT_SWITCH_NUMBER; // Input switch number uint8_t temp_sens_number = THERMOSTAT_TEMP_SENS_NUMBER; // Temperature sensor number @@ -178,7 +187,10 @@ struct THERMOSTAT { int8_t temp_hysteresis = THERMOSTAT_TEMP_HYSTERESIS; // Range hysteresis for temperature PI controller, in tenths of degrees celsius uint8_t temp_frost_protect = THERMOSTAT_TEMP_FROST_PROTECT; // Minimum temperature for frost protection, in tenths of degrees celsius uint16_t power_max = THERMOSTAT_POWER_MAX; // Maximum output power in Watt +<<<<<<< HEAD uint16_t energy_thermostat_output_max = THERMOSTAT_ENERGY_OUTPUT_MAX; // Maximum allowed energy output for thermostat valve in Watts +======= +>>>>>>> new_branch_dev ThermostatBitfield status; // Bittfield including states as well as several flags } Thermostat; @@ -320,9 +332,17 @@ bool HeatStateManualToAuto() bool change_state; // If switch input inactive +<<<<<<< HEAD // AND no switch input action (time in current state) bigger than a pre-defined time // then go to automatic if ((ThermostatSwitchStatus(Thermostat.input_switch_number) == 0) +======= + // AND sensor alive + // AND no switch input action (time in current state) bigger than a pre-defined time + // then go to automatic + if ((ThermostatSwitchStatus(Thermostat.input_switch_number) == 0) + &&(Thermostat.status.sensor_alive == IFACE_ON) +>>>>>>> new_branch_dev && ((uptime - Thermostat.timestamp_input_on) > ((uint32_t)Thermostat.time_manual_to_auto * 60))) { change_state = true; } @@ -424,7 +444,11 @@ void ThermostatCalculatePI() // Reset of antiwindup // If error does not lay within the integrator scope range, do not use the integral // and accumulate error = 0 +<<<<<<< HEAD if (abs(Thermostat.temp_pi_error) > Thermostat.temp_reset_anti_windup) { +======= + if (abs(Thermostat.temp_pi_error) > (int16_t)Thermostat.temp_reset_anti_windup) { +>>>>>>> new_branch_dev Thermostat.time_integral_pi = 0; Thermostat.temp_pi_accum_error = 0; } @@ -501,7 +525,11 @@ void ThermostatCalculatePI() } } // If target value has not been reached +<<<<<<< HEAD // AND we are withing the histeresis +======= + // AND we are withinvr the histeresis +>>>>>>> new_branch_dev // AND gradient is positive // then set value to 0 else if ((Thermostat.temp_pi_error > 0) @@ -700,6 +728,15 @@ void ThermostatWork() break; case THERMOSTAT_MANUAL_OP: // State manual operation following input switch Thermostat.time_ctr_checkpoint = 0; +<<<<<<< HEAD +======= + if (ThermostatSwitchStatus(Thermostat.input_switch_number) == 1) { + Thermostat.status.command_output = IFACE_ON; + } + else { + Thermostat.status.command_output = IFACE_OFF; + } +>>>>>>> new_branch_dev break; } bool output_command; @@ -825,9 +862,15 @@ void CmndTempMeasuredSet(void) uint32_t timestamp = uptime; // Calculate temperature gradient if temperature value has changed if (value != Thermostat.temp_measured) { +<<<<<<< HEAD int16_t temp_delta = (value - Thermostat.temp_measured); // in tenths of degrees uint32_t time_delta = (timestamp - Thermostat.timestamp_temp_meas_change_update); // in seconds Thermostat.temp_measured_gradient = (int32_t)((360000 * (int32_t)temp_delta) / (int32_t)time_delta); // hundreths of degrees per hour +======= + int32_t temp_delta = (value - Thermostat.temp_measured); // in tenths of degrees + uint32_t time_delta = (timestamp - Thermostat.timestamp_temp_meas_change_update); // in seconds + Thermostat.temp_measured_gradient = (int32_t)((360000 * temp_delta) / ((int32_t)time_delta)); // hundreths of degrees per hour +>>>>>>> new_branch_dev Thermostat.temp_measured = value; Thermostat.timestamp_temp_meas_change_update = timestamp; } @@ -1133,6 +1176,19 @@ bool Xdrv39(uint8_t function) AddLog_P2(LOG_LEVEL_DEBUG, PSTR("Thermostat.time_integral_pi: %s"), result_chr); dtostrfd(Thermostat.time_total_pi, 0, result_chr); AddLog_P2(LOG_LEVEL_DEBUG, PSTR("Thermostat.time_total_pi: %s"), result_chr); +<<<<<<< HEAD +======= + dtostrfd(Thermostat.temp_measured_gradient, 0, result_chr); + AddLog_P2(LOG_LEVEL_DEBUG, PSTR("Thermostat.temp_measured_gradient: %s"), result_chr); + dtostrfd(Thermostat.time_rampup_deadtime, 0, result_chr); + AddLog_P2(LOG_LEVEL_DEBUG, PSTR("Thermostat.time_rampup_deadtime: %s"), result_chr); + dtostrfd(Thermostat.temp_rampup_meas_gradient, 0, result_chr); + AddLog_P2(LOG_LEVEL_DEBUG, PSTR("Thermostat.temp_rampup_meas_gradient: %s"), result_chr); + dtostrfd(Thermostat.time_ctr_changepoint, 0, result_chr); + AddLog_P2(LOG_LEVEL_DEBUG, PSTR("Thermostat.time_ctr_changepoint: %s"), result_chr); + dtostrfd(Thermostat.temp_rampup_output_off, 0, result_chr); + AddLog_P2(LOG_LEVEL_DEBUG, PSTR("Thermostat.temp_rampup_output_off: %s"), result_chr); +>>>>>>> new_branch_dev AddLog_P2(LOG_LEVEL_DEBUG, PSTR("------ Thermostat End ------")); AddLog_P2(LOG_LEVEL_DEBUG, PSTR("")); #endif