Files
ShellyX/HelloWorld.js
Norbert c64ca20b06 init
2024-08-22 08:13:35 +02:00

143 lines
4.2 KiB
JavaScript

//GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007
//More information: https://www.gnu.org/licenses/gpl-3.0.txt
//ABSOLUTELY NO WARRANTY!!!
//Made by Ostfriese
//############################## Config ############################
let Config = {
temp_diff: 2,
temp_min: 12,
id_inside: 100,
hum_target: 55,
interval: 10, // 2 seconds is the minimum interval
Tank_Sensor: 0, //Sensor Wasserstand
comp: 0, // Kompressor
FanH: 1, // Luefter Schnell
FanL: 2, // Luefter langsam
LedG: 3,
LedR: 4,
LedB: 5
}
//############################## Config end ############################
function LedsOff() {
Shelly.call("http.get", {
url: 'http://127.0.0.1/relay/' + JSON.stringify(Config.LedR) + '?turn=on'
});
Shelly.call("http.get", {
url: 'http://127.0.0.1/relay/' + JSON.stringify(Config.LedG) + '?turn=on'
});
Shelly.call("http.get", {
url: 'http://127.0.0.1/relay/' + JSON.stringify(Config.LedB) + '?turn=on'
});
}
function Gruen() {
LedsOff();
Shelly.call("http.get", {
url: 'http://127.0.0.1/relay/' + JSON.stringify(Config.LedG) + '?turn=off'
});
}
function Rot() {
LedsOff();
Shelly.call("http.get", {
url: 'http://127.0.0.1/relay/' + JSON.stringify(Config.LedR) + '?turn=off'
});
}
function Blau() {
LedsOff();
Shelly.call("http.get", {
url: 'http://127.0.0.1/relay/' + JSON.stringify(Config.LedB) + '?turn=off'
});
}
function allesAus() {
Shelly.call("http.get", {
url: 'http://127.0.0.1/relay/' + JSON.stringify(Config.comp) + '?turn=off'
});
Shelly.call("http.get", {
url: 'http://127.0.0.1/relay/' + JSON.stringify(Config.FanH) + '?turn=off'
});
Shelly.call("http.get", {
url: 'http://127.0.0.1/relay/' + JSON.stringify(Config.FanL) + '?turn=off'
});
LedsOff();
}
function niedrigeStufe() {
Shelly.call("http.get", {
url: 'http://127.0.0.1/relay/' + JSON.stringify(Config.comp) + '?turn=on'
});
Shelly.call("http.get", {
url: 'http://127.0.0.1/relay/' + JSON.stringify(Config.FanH) + '?turn=off'
});
Shelly.call("http.get", {
url: 'http://127.0.0.1/relay/' + JSON.stringify(Config.FanL) + '?turn=on'
});
Blau();
}
function hoheStufe() {
Shelly.call("http.get", {
url: 'http://127.0.0.1/relay/' + JSON.stringify(Config.comp) + '?turn=on'
});
Shelly.call("http.get", {
url: 'http://127.0.0.1/relay/' + JSON.stringify(Config.FanH) + '?turn=on'
});
Shelly.call("http.get", {
url: 'http://127.0.0.1/relay/' + JSON.stringify(Config.FanL) + '?turn=off'
});
Blau();
}
function watch() {
try {
temperature = Shelly.getComponentStatus('Temperature', Config.id_inside).tC;
humidity = Shelly.getComponentStatus('Humidity', Config.id_inside).rh;
tank = Shelly.getComponentStatus('Input', Config.Tank_Sensor).state;
//print('Temp. inside =',temp_inside);
print('Hum. Inside =', humidity);
print('tank= ', tank);
//inside <= minimum
if (humidity <= Config.hum_target) {
//allesAus();
Gruen();
print('Relay(', Config.comp, ') off. Inside hum <= ', Config.hum_target);
} else {
delta = humidity - Config.hum_target;
//delta more than or equal Config.temp_diff
//if (!tank && delta >= Config.temp_diff) {
//niedrigeStufe();
Blau();
// print('Relay(', Config.comp, ') on. Delta >= ', Config.hum_target);
}
//delta less than Config.temp_diff
//else {
//allesAus();
// Gruen();
// print('Relay(', Config.comp, ') off. Delta < ', Config.hum_target);
//}
//}
print('\n')
} catch (err) {
//allesAus();
//Rot();
print(err);
}
}
function start() {
LedsOff();
//allesAus();
// do a first shot
print('Starting....');
watch();
// set watch timer to configured value
Timer.set(Config.interval * 1000, true, watch);
}
// schedule script start for 1 second
Timer.set(1000, false, start);