Hallo zusammen,
nachdem die Funktion der Lüftersteuerung per Szene -aufgrund fehlender Internetverbindung- verständlicherweise nicht funktioniert,
habe ich mein Projekt <Bad Licht-/Lüftersteuerung>
dahingehend geändert, dass ich den Shelly 2.5 durch einen Shelly Plus 2PM inkl. Skript ausgetauscht habe.
Die Szene ist nun durch unten angehängtes Skript ersetzt.
Ausgangssituation:
1x Schalter
1x Lampe, 1x Lüfter gesteuert über den Schalter (gemeinsam an/aus)
Nun:
1x Taster
1x Lampe gesteuert durch den Taster
1x Lüfter gesteuert über das Skript in Abhängigkeit der Schaltzustände (Taster, Lampe)
Fallunterscheidung im Skript beschrieben.
Vielen Dank an 	Devil für seine Antworten in meinen anderen Beiträgen. 
Diese waren mir hierfür sehr hilfreich  
 .
Patrick
Code
		
					
				// ControlBathLampFan v2.1 
// by PatrickR 
// 22.10.2022
// 
// This script is activating the fan on output2 depending action on input button 1 
// 
// 
// Input  1: button, output 1 on/off 
// Input  2: ---
// Output 1: Lamp, timer switch off after 30 minutes
// Output 2: Fan,  timer switch off after 30 minutes 
// 
// 
// Case 1: Lamp OFF, Fan OFF 
//    Button short keypress: Lamp ON, delayTimer stopped, Fan OFF 
//    Button long  keypress: Lamp ON, delayTimer started, after delayTimer expired -> Fan ON 
// Case 2: Lamp ON, Fan OFF 
//    Button short keypress: Lamp OFF, delayTimer stopped, Fan OFF 
//    Button long  keypress: Lamp OFF, Fan ON 
// Case 3: Lamp OFF, Fan ON 
//    Button short keypress: Lamp ON, delayTimer stopped, Fan OFF 
//    Button long  keypress: Lamp ON, delayTimer started, after delayTimer expired -> timer switch off retriggered 
// Case 2: Lamp ON, Fan ON 
//    Button short keypress: Lamp OFF, delayTimer stopped, Fan OFF 
//    Button long  keypress: Lamp OFF, Fan ON, timer switch off retriggered  
// 
//
// Configuration script: 
// - delayTms: delay time till output 2 is activated
//
//
let CONFIG = {
    inputId_0: 0,
    switchIdLamp: 0,             
    switchIdFan: 1,              
    delayTimerHandler: null,          
    LampON: true,
    LampOFF: false,
    FanON: true,
    FanOFF: false,
    delayTms: 2 * 60 * 1000   //millisecond (=2 Minuten)
};
Shelly.addEventHandler(function (e) {
    if (e.component === ("input:" + JSON.stringify(CONFIG.inputId_0))) {
        if (e.info.event === "single_push") {
            fkt_single_pushed();
        }
        else if (e.info.event === "long_push") {
            fkt_long_pushed();
        }
    }
});
function fkt_delayTimerEND() {
    // delay Timer expire => switch fan on (switchId_1)
    fkt_switchFan(CONFIG.FanON);
    print("fkt_delayTimerEND");
}
function fkt_single_pushed() {
    //clear delay Timer
    Timer.clear(CONFIG.delayTimerHandler);
    // switch fan off
    fkt_switchFan(CONFIG.FanOFF);
    print("Button was single pushed");
}
function fkt_long_pushed() {
    //if lamp (switchId_0) is on,  delay Timer will     be started 
    //if lamp (switchId_0) is off, delay Timer will not be started, fan will be started directly 
    Shelly.call("switch.getstatus", { id: CONFIG.switchIdLamp },
       function (result, error_code, error_message) {
           print("Result: ", JSON.stringify(result));
           if (result.output === CONFIG.LampON) {
               CONFIG.delayTimerHandler = Timer.set(CONFIG.delayTms, false, fkt_delayTimerEND);
               print("Lamp is on");
           }
           else {
               fkt_switchFan(CONFIG.FanON);
               print("Lamp is off");
           }
       }
    );
    print("Button was long pushed");
}
function fkt_switchFan(bl_OnOff) {
    let swFan = {
        id: CONFIG.switchIdFan,
        on: bl_OnOff
    };
    Shelly.call("Switch.Set", swFan);
    print("fkt_switchFan: ", bl_OnOff);
}
	
			Alles anzeigen