So I decided to drop the loop inside loop as the arrays were not synchronising.
The time to troubleshoot would be more than the loop would save me time from programming the full code bit by bit.
Just for future reference if someone wants to do the same:
The "First_Run" bit is to fill the PLC DB so it doesn't overwrite the actual settings with an empty DB.
async function SyncSetpoint() {
var Heater = getObject("enum.functions.HeatingUp.setpoint").common.members;
var PLC = getObject("enum.functions.PlcHeatingUp.setpoint").common.members;
for(let i = 0; i < Heater.length; i++) {
on(PLC[i], function (dp) {
if(dp.state.c != scriptName) setState(Heater[i], dp.state.val);
return;
});
on(Heater[i], function (dp) {
if(dp.state.c != scriptName) setState(PLC[i], dp.state.val);
});
await wait(1000);
}
}
async function SyncProfile() {
var Heater = getObject("enum.functions.HeatingUp.profile").common.members;
var PLC = getObject("enum.functions.PlcHeatingUp.profile").common.members;
for(let i = 0; i < Heater.length; i++) {
on(PLC[i], function (dp) {
if(dp.state.c != scriptName) setState(Heater[i], dp.state.val);
return;
});
on(Heater[i], function (dp) {
if(dp.state.c != scriptName) setState(PLC[i], dp.state.val);
});
await wait(1000);
}
}
async function SyncBoost() {
var Heater = getObject("enum.functions.HeatingUp.boost").common.members;
var PLC = getObject("enum.functions.PlcHeatingUp.boost").common.members;
for(let i = 0; i < Heater.length; i++) {
on(PLC[i], function (dp) {
if(dp.state.c != scriptName) setState(Heater[i], dp.state.val);
return;
});
on(Heater[i], function (dp) {
if(dp.state.c != scriptName) setState(PLC[i], dp.state.val);
});
await wait(1000);
}
}
async function SyncBoostTime() {
var Heater = getObject("enum.functions.HeatingUp.boostTime").common.members;
var PLC = getObject("enum.functions.PlcHeatingUp.boostTime").common.members;
for(let i = 0; i < Heater.length; i++) {
on(PLC[i], function (dp) {
if(dp.state.c != scriptName) setState(Heater[i], dp.state.val);
return;
});
on(Heater[i], function (dp) {
if(dp.state.c != scriptName) setState(PLC[i], dp.state.val);
});
await wait(1000);
}
}
function SyncActualTemp() {
var Heater = getObject("enum.functions.HeatingUp.actual").common.members;
var PLC = getObject("enum.functions.PlcHeatingUp.actual").common.members;
for(let i = 0; i < Heater.length; i++) {
on(Heater[i], function (dp) {
if(dp.state.c != scriptName) setState(PLC[i], dp.state.val);
});
}
}
function SyncActualHum() {
var Heater = getObject("enum.functions.HeatingUp.hum").common.members;
var PLC = getObject("enum.functions.PlcHeatingUp.hum").common.members;
for(let i = 0; i < Heater.length; i++) {
on(Heater[i], function (dp) {
if(dp.state.c != scriptName) setState(PLC[i], dp.state.val);
});
}
}
function SyncWinStat() {
var connStatHeater = getObject("enum.functions.HeatingUp.connStatWin").common.members;
var connStatPLC = getObject("enum.functions.PlcHeatingUp.connStatWin").common.members;
var winStatHeater = getObject("enum.functions.HeatingUp.winStat").common.members;
var winStatPLC = getObject("enum.functions.PlcHeatingUp.winStat").common.members;
var batStatHeater = getObject("enum.functions.HeatingUp.batStatWin").common.members;
var batStatPLC = getObject("enum.functions.PlcHeatingUp.batStatWin").common.members;
for(let i = 0; i < connStatPLC.length; i++) {
on(connStatHeater[i], function (dp) {
if(dp.state.c != scriptName) setState(connStatPLC[i], dp.state.val);
});
if (getState(connStatHeater[i]).val != true) {
on(winStatHeater[i], function (dp) {
if(dp.state.c != scriptName) setState(winStatPLC[i], dp.state.val);
});
on(batStatHeater[i], function (dp) {
if(dp.state.c != scriptName) setState(batStatPLC[i], dp.state.val);
});
}
}
}
function SyncThermStat() {
var connStatHeater = getObject("enum.functions.HeatingUp.connStatTherm").common.members;
var connStatPLC = getObject("enum.functions.PlcHeatingUp.connStatTherm").common.members;
var batStatHeater = getObject("enum.functions.HeatingUp.batStatTherm").common.members;
var batStatPLC = getObject("enum.functions.PlcHeatingUp.batStatTherm").common.members;
for(let i = 0; i < connStatPLC.length; i++) {
on(connStatHeater[i], function (dp) {
if(dp.state.c != scriptName) setState(connStatPLC[i], dp.state.val);
});
if (getState(connStatHeater[i]).val != true) {
on(batStatHeater[i], function (dp) {
if(dp.state.c != scriptName) setState(batStatPLC[i], dp.state.val);
});
}
}
}
function SyncRadStat() {
var connStatHeater = getObject("enum.functions.HeatingUp.connStatRad").common.members;
var connStatPLC = getObject("enum.functions.PlcHeatingUp.connStatRad").common.members;
var batStatHeater = getObject("enum.functions.HeatingUp.batStatRad").common.members;
var batStatPLC = getObject("enum.functions.PlcHeatingUp.batStatRad").common.members;
for(let i = 0; i < connStatPLC.length; i++) {
on(connStatHeater[i], function (dp) {
if(dp.state.c != scriptName) setState(connStatPLC[i], dp.state.val);
});
if (getState(connStatHeater[i]).val != true) {
on(batStatHeater[i], function (dp) {
if(dp.state.c != scriptName) setState(batStatPLC[i], dp.state.val);
});
}
}
}
//function SyncOnStart() {
on({id: "s7.2.DBs.DB5.First_Run"/*First_Run*/, change: "ne"}, async function (obj) {
var SPHeater = getObject("enum.functions.HeatingUp.setpoint").common.members;
var SPPLC = getObject("enum.functions.PlcHeatingUp.setpoint").common.members;
var TempHeater = getObject("enum.functions.HeatingUp.actual").common.members;
var TempPLC = getObject("enum.functions.PlcHeatingUp.actual").common.members;
var HumHeater = getObject("enum.functions.HeatingUp.hum").common.members;
var HumPLC = getObject("enum.functions.PlcHeatingUp.hum").common.members;
var ProfileHeater = getObject("enum.functions.HeatingUp.profile").common.members;
var ProfilePLC = getObject("enum.functions.PlcHeatingUp.profile").common.members;
var BoostHeater = getObject("enum.functions.HeatingUp.boost").common.members;
var BoostPLC = getObject("enum.functions.PlcHeatingUp.boost").common.members;
var BoostTimeHeater = getObject("enum.functions.HeatingUp.boostTime").common.members;
var BoostTimePLC = getObject("enum.functions.PlcHeatingUp.boostTime").common.members;
var WinStatHeater = getObject("enum.functions.HeatingUp.winStat").common.members;
var WinStatPLC = getObject("enum.functions.PlcHeatingUp.winStat").common.members;
var batStatRadHeater = getObject("enum.functions.HeatingUp.batStatRad").common.members;
var batStatRadPLC = getObject("enum.functions.PlcHeatingUp.batStatRad").common.members;
var connStatRadHeater = getObject("enum.functions.HeatingUp.connStatRad").common.members;
var connStatRadPLC = getObject("enum.functions.PlcHeatingUp.connStatRad").common.members;
var batStatThermHeater = getObject("enum.functions.HeatingUp.batStatTherm").common.members;
var batStatThermPLC = getObject("enum.functions.PlcHeatingUp.batStatTherm").common.members;
var connStatThermHeater = getObject("enum.functions.HeatingUp.connStatTherm").common.members;
var connStatThermPLC = getObject("enum.functions.PlcHeatingUp.connStatTherm").common.members;
let value = obj.state.val;
let oldValue = obj.oldState.val;
if (getState("s7.2.DBs.DB5.First_Run").val == true) {
for(let i = 0; i < SPHeater.length; i++) {
setStateDelayed(SPPLC[i], getState(SPHeater[i]).val, false, parseInt(((0) || "").toString(), 10), false);
setStateDelayed(TempPLC[i], getState(TempHeater[i]).val, false, parseInt(((0) || "").toString(), 10), false);
setStateDelayed(HumPLC[i], getState(HumHeater[i]).val, false, parseInt(((0) || "").toString(), 10), false);
setStateDelayed(ProfilePLC[i], getState(ProfileHeater[i]).val, false, parseInt(((0) || "").toString(), 10), false);
setStateDelayed(BoostPLC[i], getState(BoostHeater[i]).val, false, parseInt(((0) || "").toString(), 10), false);
setStateDelayed(BoostTimePLC[i], getState(BoostTimeHeater[i]).val, false, parseInt(((0) || "").toString(), 10), false);
};
for(let i = 0; i < WinStatHeater.length; i++) {
setStateDelayed(WinStatPLC[i], getState(WinStatHeater[i]).val, false, parseInt(((0) || "").toString(), 10), false);
};
for(let i = 0; i < batStatRadHeater.length; i++) {
setStateDelayed(batStatRadPLC[i], getState(batStatRadHeater[i]).val, false, parseInt(((0) || "").toString(), 10), false);
setStateDelayed(connStatRadPLC[i], getState(connStatRadHeater[i]).val, false, parseInt(((0) || "").toString(), 10), false);
};
for(let i = 0; i < batStatThermHeater.length; i++) {
setStateDelayed(batStatThermPLC[i], getState(batStatThermHeater[i]).val, false, parseInt(((0) || "").toString(), 10), false);
setStateDelayed(connStatThermPLC[i], getState(connStatThermHeater[i]).val, false, parseInt(((0) || "").toString(), 10), false);
};
await wait(3000);
setStateDelayed("s7.2.DBs.DB5.First_Run", false, false, parseInt(((0) || "").toString(), 10), false);
}
});
SyncSetpoint();
SyncProfile();
SyncBoost();
SyncBoostTime();
SyncActualHum();
SyncWinStat();
SyncThermStat();
SyncRadStat();
So thanks @paul53 but I gave up and took the less beautiful way out 😉