Das ist ne kleine Script Funktion mit der man den Switch/Input Modus leicht ändern kann:
So nutzt man die Funktion SwitchM(0,'detached','switch');
//cID = 0 --> Shelly Channel ID/Relay/Input
//cM = 'detached' --> Shelly Channel/Relay Modus 'detached'/'flip'/'momentary'/'follow'
//cT = 'switch' --> Shelly Channel/Input Typ, 'button'/'switch'
Wenn man nur den Switch oder Input Mode einzeln ändern will, kann man einfach nen Wert auf Null setzen, z.B. folgendes ändert nur den Input Mode SwitchM(0,null,'button');.
Update(16.10.2023):
- debug Option hinzugefügt
Um eine Debug-Ausgabe zu erhalten, kann nun als 4. Parameter true übergeben werden.
Code
function Str(d) { //Upgrade JSON.stringify()
if (d === null || d === undefined) return null;
if (typeof d === 'string') return d;
return JSON.stringify(d);
}
function SwitchM(cID,cM,cT,debug){ //Change Switch/Input Mode, cID=0 -> Relay/Input ID, cM='detached'-> Relay Modus detached/flip/momentary/follow, cT='switch' --> Input Typ button/switch
let Config = Shelly.getComponentConfig, Call = Shelly.call, r = 0;
try{
if(Config('switch',cID).initial_state === 'match_input') Call('Switch.SetConfig',{id:cID,config:{initial_state:'restore_last'}});
if(cM && Config('switch',cID).in_mode !== cM){Call('Switch.SetConfig',{id:cID,config:{in_mode: cM}});if(!r){r='';} r+='cM, ';}
if(cT && Config('input',cID).type !== cT){Call('Input.SetConfig',{id:cID,config:{type: cT}});if(!r){r='';} r+='cT, ';}
if(debug){r='Debug: tryed to changed-> '+r+' Oldconfig: cM-> '+Config('switch',cID).in_mode+', cT-> '+Config('input',cID).type; print(r);}
return r;}catch(e){print(e);}
}
//How to use it
if(SwitchM(0,'detached','switch')) print('Status: Changed Switch/Input Mode');
Alles anzeigen