Mit der internen Automation hab ich es nicht geschafft, dass die Temperatur nicht den per Taster aktivierten 6h-on Status zurückgesetzt hätte. Ein mal über 5 Grad Celsius und die Dose war wieder ausgeschalten.
Für die interessierte Nachwelt: Ich habe das jetzt über ein Script gelöst.
Vorbedingungen: Der Taster ist im "detached" Modus konfiguriert & ein Temperatursensor ist über den Shelly Addon angeschlossen (bei mir ein DHT21).
Wenn man noch Szenen für An/Aus Benachrichtigungen anlegt dann tauchen die auch im Aktivitätslog auf .
/**
* Script 'Winter Safeguard'
* Author: Wolfgang Moestl 2024
* Copyright GNU General Public License 3 (https://www.gnu.org/licenses/gpl-3.0.html)
*
* 1) Activates switch if temperature is less than CONFIG.temp_threshold_on
* 2) Deactivates switch if temperature is greater than CONFIG.temp_threshold_off
* 3) Single-Push on input 0 activates the switch for 6 CONFIG.switchTimeout millisecs
* ("allways-on mode")
* 4) After CONFIG.switchTimeout millisecs the switch is activated/deactivated according
* to the next temperature reading (see 1) and 2) )
* 5) Single-Push on input 0 while already running resets the timer
* for another CONFIG.switchTimeout millisecs
* 6) While in always-on mode temperature changes are ignored
*
* Requirements:
* 1) Input is in "detached switch" mode
* 2) Temperature sensor is attached to the Shelly addon (here: DHT21 temperature & humidity)
*/
let CONFIG = {
switchTimeout: 6 * 60 * 60 * 1000, // 6h expressed in milliseconds
temp_threshold_on: 3.0, // Below this temperature (degree Celcius) the switch will activate
temp_threshold_off: 5.0 // Above this temperature (degree Celcius) the switch will deactivate
};
let alwaysOnTimer = null;
let alwaysOnTimerRunning = false;
let status = Shelly.getComponentStatus("switch", 0).output;
print("Start script 'Winter Safeguard'");
print("Actual temperature: " + Shelly.getComponentStatus("temperature", 100).tC + " degree Celcius");
print("Actual humidity: " + Shelly.getComponentStatus("humidity", 100).rh + "%");
print("Switch ist turned " + (status ? "on" : "off"));
/**
* Stores the actual switch state in the variable status.
*/
function isTurnedOn() {
// Note: synchronous call!
status = Shelly.getComponentStatus("switch", 0).output;
return status;
}
/**
* Starts a new or restarts an existing timer
*/
function startAlwaysOnTimer() {
if (null != alwaysOnTimer) {
Timer.clear(alwaysOnTimer);
print("Restarting timer");
}
alwaysOnTimer = Timer.set(CONFIG.switchTimeout,
false, // timer fires only once
function (ud) {
Timer.clear(alwaysOnTimer);
alwaysOnTimer = null;
alwaysOnTimerRunning = false;
print ("Output timer has stopped");
// the next temperature reading will switch the output on/off.
},
null
);
print("Output timer running for " + (CONFIG.switchTimeout / 1000) + "sec");
alwaysOnTimerRunning = true;
turnOn();
}
/**
* Turn the switch on (if not on yet).
*/
function turnOn() {
status = isTurnedOn();
// print ("turnOn called, status=" + status);
if (false == status) {
Shelly.call(
"switch.set",
{ id: 0, on: true},
function (result, error_code, error_message, ud) {
print('Switched on');
}
);
}
}
/**
* Turn the switch off (if not off yet).
*/
function turnOff() {
status = isTurnedOn();
// print ("turnOff called, status=" + status);
if (true == status) {
Shelly.call(
"switch.set",
{ id: 0, on: false},
function (result, error_code, error_message, ud) {
print('Switched off');
}
);
}
}
/**
* Registers the event handler dealing with temperature and input events
*/
Shelly.addEventHandler(
function (event, ud) {
// while we don't have better selectivity for event source
if (typeof event.info.event === "undefined") return;
if (event.component == 'temperature:100' && event.info.event == 'temperature_measurement') {
let temp = event.info.tC;
//print("Actual temperature: " + temp);
if (false == alwaysOnTimerRunning) {
if (temp < CONFIG.temp_threshold_on) {
turnOn();
} else if (temp > CONFIG.temp_threshold_off) {
turnOff();
}
} else {
// The alwaysOnTimer ist running, thus no temperature reading will change the state!
}
} else if (event.component == 'input:0' && event.info.event == 'single_push') {
// print ("input:0 event=" + JSON.stringify(event));
startAlwaysOnTimer();
}
},
null
);
Alles anzeigen