Скрипт прикладываю
Статичные данные (скриншот) при логировании из данного скрипта, логирование приделал, тк по анализу данных стало понятно что не отрабатывает коэффициент коррекции по уличной температуре при ее изменении
var CoolingTower_Sensor_T = 'wb-mai6_173/IN 1 N Temperature';
var Outdoor_Sensor_T = 'Teploluxe2000_MGMNT/T1_temp';
var Room_TempSensor = "wb-mai6_173/IN 1 P Temperature";
//Regulation Outputs 0-10v
var CoolingTower_Output_AO = 'wb-mao4_88/Channel 1';
var RoomCooling_Fan_1_Output_AO = 'wb-mao4_88/Channel 2';
var RoomCooling_Fan_2_Output_AO = 'wb-mao4_88/Channel 3';
//Output values
var Regulation_Output = [1000,0,0];
//Settings
// device-ID 0-CoolingTower
var Setpoints = [31,32,33];
var CoolingTower_TempSetpoint = 31.1;
var CoolingTower_TempHystresis = 2.1;
var Voltage_Cooling_Max = [9900,10000,10000];
var Voltage_Cooling_Off = [1060,0,0];
var Cooling_Up_Step = [120,0,0];
var Cooling_Down_Step = [200,0,0];
var Outdor_Factor = [20,0,0];
var Error_Factor = [30,0,0];
var Iterations_Factor_Decrease = [0.5,1,1];
var Iterations_Factor_Increase = [0.9,1,1];
//temp vars
var Outdoor_Temperature = dev[Outdoor_Sensor_T] || 0;
var DV_Iterations_cooling = [0,0,0]
var CoolingTower_Temp_LastCycle = dev['ADC_Temp_Control/CT_TempSensor'] || 0;
var CoolingTower_Temp_Error = 0;
var CoolingTower_Current_Temp = dev[CoolingTower_Sensor_T] || 0;
var CoolingTower_Iterations_cooling =0;
var RoomCooling_Hystresis = 0.2;
var RoomCoolingPlusHystresis = 0;
var RoomCoolingMinusHystresis = 0;
var ADC_Temp_Controls = {
WinterMode: {
type: 'switch',
title: 'Winter mode',
value: false,
readonly: true,
order: 3,
},
CT_AutoMode: {
type: 'switch',
title: 'Cooling Tower Auto on',
value: true,
readonly: false,
order: 4,
},
CT_TempSensor: {
type: 'value',
units: 'deg C',
precision: 0.1,
title: 'Cooling Tower outlet temperature',
value: 0,
order: 8,
readonly: false,
},
CT_Regulation_Output: {
type: 'value',
units: 'mV',
precision: 1,
min: 0,
max: 10000,
title: 'Cooling Tower Regulation output',
value: Regulation_Output[0],
order: 14,
readonly: false,
},
CT_Setpoint: {
type: 'value',
units: 'deg C',
precision: 0.1,
title: 'Cooling Tower setpoint',
value: CoolingTower_TempSetpoint,
order: 16,
readonly: false,
},
CT_Hystresis: {
type: 'value',
units: 'deg C',
precision: 0.1,
title: 'Cooling Tower Hystresis',
value: CoolingTower_TempHystresis,
order: 16,
readonly: false,
},
RC_AutoMode: {
type: 'switch',
title: 'Room Cooling Auto on',
value: true,
readonly: false,
order: 20,
},
RC_TempSensor: {
type: 'value',
units: 'deg C',
precision: 0.1,
title: 'Room temperature',
value: 0,
order: 21,
readonly: false,
},
RC_Setpoint: {
type: 'value',
units: 'deg C',
precision: 0.1,
title: 'Room Cooling setpoint',
value: 25,
order: 22,
readonly: false,
},
RC_Fan_1: {
type: 'switch',
title: 'Room Cooling Fan1 on',
value: true,
readonly: false,
order: 23,
},
RC_Fan_2: {
type: 'switch',
title: 'Room Cooling Fan2 on',
value: true,
readonly: false,
order: 24,
},
};
defineVirtualDevice('ADC_Temp_Control', {
title: 'ADC temperature control',
cells: ADC_Temp_Controls,
});
function DownVolt_Cooler(Device_ID, Current_T, Last_T, Setpoint, Hystresis) {
Outdoor_Temperature = dev[Outdoor_Sensor_T];
var SetpointMinusHystresis = Setpoint - Hystresis;
var Temperature_Error = Current_T - Setpoint;
if (Current_T > SetpointMinusHystresis) {
if (Current_T < Last_T) {
DV_Iterations_cooling[Device_ID]--;
if (DV_Iterations_cooling[Device_ID] < 1) {DV_Iterations_cooling[Device_ID] = 1;}
Regulation_Output[Device_ID] -= Math.floor((Cooling_Down_Step[Device_ID] - Outdor_Factor[Device_ID] * Outdoor_Temperature - Error_Factor[Device_ID] * Temperature_Error)/((1/DV_Iterations_cooling[Device_ID])*Iterations_Factor_Decrease[Device_ID]));
}
if (Current_T > Last_T) {
DV_Iterations_cooling[Device_ID]++;
Regulation_Output[Device_ID] += Math.floor((Cooling_Up_Step[Device_ID] + Outdor_Factor[Device_ID] * Outdoor_Temperature + Error_Factor[Device_ID] * Temperature_Error)/(DV_Iterations_cooling[Device_ID]*Iterations_Factor_Increase[Device_ID]));
}
}
if (Current_T > Setpoint) {DV_Iterations_cooling[Device_ID]=0;}
if (Current_T < SetpointMinusHystresis) {
Regulation_Output[Device_ID] = Voltage_Cooling_Off[Device_ID];
DV_Iterations_cooling[Device_ID] = 0;
}
if (Regulation_Output[Device_ID] > Voltage_Cooling_Max[Device_ID]) {Regulation_Output[Device_ID] = Voltage_Cooling_Max[Device_ID];}
if (Regulation_Output[Device_ID] < Voltage_Cooling_Off[Device_ID]) {Regulation_Output[Device_ID] = Voltage_Cooling_Off[Device_ID];}
log.info(dev['Teploluxe2000_MGMNT/T1_temp']);
//log.info("Outdoor_Temperature: ",Outdoor_Temperature,"Current_T:",Current_T,"Last_T:",Last_T,"Regulation_Output:",Regulation_Output[Device_ID],": ",dev['Teploluxe2000_MGMNT/T1_temp']);
return Regulation_Output[Device_ID];
}
defineRule("cron_every_1_sec", {
when: cron("@every 2s"), //also @every 1h30m10s more: https://pkg.go.dev/github.com/robfig/cron#hdr-CRON_Expression_Format
then: function () {
dev['ADC_Temp_Control/CT_TempSensor'] = dev[CoolingTower_Sensor_T];
if (dev['ADC_Temp_Control/CT_AutoMode']) {
dev['ADC_Temp_Control/CT_Regulation_Output'] = DownVolt_Cooler(0, dev[CoolingTower_Sensor_T], CoolingTower_Temp_LastCycle, dev['ADC_Temp_Control/CT_Setpoint'], dev['ADC_Temp_Control/CT_Hystresis'])
//log.info("T-Error:",CoolingTower_Temp_Error.toFixed(2)," T-Outdor:",Outdoor_Temperature.toFixed(2)," Setp-Hyst:",CoolingTowerSetpointMinusHystresis.toFixed(2)," Curr-T:",CoolingTower_Current_Temp.toFixed(2)," CoolingTower_Regulation_Output:",Math.floor(CoolingTower_Regulation_Output));
}
CoolingTower_Temp_LastCycle = dev['ADC_Temp_Control/CT_TempSensor'];
dev[CoolingTower_Output_AO] = dev['ADC_Temp_Control/CT_Regulation_Output'];
},
});