Top, das klappt - danke!
//Titel: Pool automation logik to heat the pool
/*
Externer Trigger:
- Die Temperatur auf dem Dach wurde neu erfasst und ist ist > 0°C
- Es ist zwischen Sonnenauf- und Sonnenuntergang
Ablauf
1. Alle noetinge Variablen auslesen
2. Automationslogik nur durchlaufen, wenn diese auch aktiviert!
2.1 Sofern Pumpe laeuft, pruefen ob abgeschaltet werden muss
2.1.1 => Abschaltung bei:
1. Wassertemperatur muss vorliegen (Variabel != "---")
2. Wassertemperatur >= Zieltemepratur oder Wassertemepratur => Dachtemperatur
2.2 Pumpe laeuft nicht, pruefen ob diese angeschaltet werden soll
2.2.1 => Einschalten bei:
1. Wassertemp. wurde noch nicht festgestellt (Variable = "---"), definitiv erstmal die Wassertemp ermitteln!
2. Oder Wassertemp < Targettemp und Wassertemp < Dachtemp
3. Sofern Pumpenstatus sich aendern soll, diesen neu setzten
*/
var enableLogging = false;
var DiffOffsetTemp = 5;
//### >> Read functions >> ###
var f_poolAutoHeating = function(pAutoHeating)
{
logMsg("Start f_poolAutoHeating()",false);
getDeviceStatus(
"Schuppen",
"Pool_AutoHeating",
{"value":"state","options":["off","on"]},
function(err, status) {
if(err)
{
logMsg("Can not read value 'Pool_AutoHeating'!", true);
logMsg(err.message, true);
return;
}
pAutoHeating(status);
}
);
};
var f_poolTargetTemp = function(pTargetTemp)
{
logMsg("Start f_poolTargetTemp()",false);
getDeviceStatus(
"Schuppen",
"Pool_TargetTemp",
{"value":"state","extMeta":"-21474836.48-21474836.47","scale":"0.01"},
function(err, status) {
if(err)
{
logMsg("Can not read value 'Pool_TargetTemp'!", true);
logMsg(err.message, true);
return;
}
pTargetTemp(status);
}
);
};
var f_poolWaterTemp = function(pWaterTemp)
{
logMsg("Start f_poolWaterTemp()",false);
getDeviceStatus(
"Schuppen",
"Pool_WaterTemp",
{"value":"state"},
function(err, status) {
if(err)
{
logMsg("Can not read value 'Pool_WaterTemp'!", true);
logMsg(err.message, true);
return;
}
pWaterTemp(status);
}
);
};
var f_poolRoofTemp = function(pRoofTemp)
{
logMsg("Start f_poolRoofTemp()",false);
getDeviceStatus(
"Schuppen",
"PoolTemperatur",
{"value":"tempSensor2","extMeta":"-3276.8-3276.7","scale":"0.1"},
function(err, status) {
if(err)
{
logMsg("Can not read value 'PoolRoofTemp'!", true);
logMsg(err.message, true);
return;
}
pRoofTemp(status);
}
);
};
var f_PumpState = function(pPumpState) //variable has values -> ["off","on"]
{
logMsg("Start f_PumpState()",false);
getDeviceStatus(
"Schuppen",
"Multischalter-IP-14",
{"value":"switchState","options":["off","on"]},
function(err, status) {
if(err)
{
logMsg("Can not read value 'pPumpState'!", true);
logMsg(err.message, true);
return;
}
pPumpState(status);
}
);
};
//### << Read functions << ###
//### >> Main logic implementation >> ###
function Main()
{
logMsg("Start Main()",false);
//1. Alle noetinge Variablen auslesen
f_poolAutoHeating(function(paraAutoHeat) //Async fucntions calls!
{
logMsg("paraAutoHeat=" + paraAutoHeat,false);
//2.
if(paraAutoHeat==="on")
{
f_poolTargetTemp(function(paratTargetTemp)
{
f_poolWaterTemp(function(paraWaterTemp)
{
f_poolRoofTemp(function(paraRoofTemp)
{
f_PumpState(function(paraPumpState)
{
logMsg("paratTargetTemp=" + paratTargetTemp,false);
logMsg("paraWaterTemp=" + paraWaterTemp,false);
logMsg("paraRoofTemp=" + paraRoofTemp,false);
logMsg("paraPumpState=" + paraPumpState,false);
var NewPumpState="off";
//conver string values to floats
var fTargetTemp = convert_to_float(paratTargetTemp);
var fRoofTemp = convert_to_float(paraRoofTemp);
var fWaterTemp = 0;
if(paraPumpState==="on")
{ //2.1 - Pump is running
NewPumpState = "on"; //Basic logic -> keep state!
if(paraWaterTemp!=="---")
{
fWaterTemp = convert_to_float(paraWaterTemp);
if ( (fWaterTemp>=fTargetTemp) || (fWaterTemp>=fRoofTemp) )
{
NewPumpState = "off";
}
}
}
else
{ //2.2 - Pump is switch off
NewPumpState = "off"; //Basic logic -> keep state!
if(paraWaterTemp==="---")
{
NewPumpState = "on";
}
else
{
fWaterTemp = convert_to_float(paraWaterTemp);
if ( (fWaterTemp {
NewPumpState = "on";
}
}
}
//3.
if( NewPumpState.toLowerCase()===paraPumpState.toLowerCase() )
{
logMsg("Keep pump state! ", false);
}
else
{
logMsg("Set new Pumpstate --> " + NewPumpState,false);
//Set switch
executeDeviceCommand(
"Schuppen",
"Multischalter-IP-14",
{"value":NewPumpState},
function(err)
{
if(error)
{
logMsg("Set new Pumpstate --> " + NewPumpState,false);
logMsg(err.message, true);
return;
}
}
);
}
});
});
});
});
}
});
logMsg("End Main()",false);
}
//Start main logic!
Main();
//### << Main() << ###
//### >> Help functions >> ###
function convert_to_float(b)
{
// Using parseFloat() method
var floatValue = parseFloat(b);
// Return float value
return floatValue;
}
function logMsg(msg, isError)
{
if(isError)
{
console.error(msg);
}
else
{
if(enableLogging)
{
console.log(msg);
}
}
}
//### << Help functions << ###
Neuen Kommentar hinzufügen