Hi is it possible tu run a remote script like switch a remote realy?
http://10.0.1.63/relay/0?turn=on
http://10.0.1.63/Script/1?active (just my fantasy)
Thanks
Run a Sript to a remote Shelly
Die Verwendung von Skripten erfolgt ausdrücklich auf eigene Gefahr. Weder Shelly noch die jeweiligen Autoren oder Entwickler der Skripte übernehmen irgendeine Form der Haftung für mögliche Schäden, Fehlfunktionen, Datenverluste oder anderweitige Beeinträchtigungen, die durch die Nutzung dieser Skripte entstehen könnten. Bitte stellen Sie vor dem Einsatz sicher, dass Sie den Quellcode verstehen und sich der möglichen Auswirkungen bewusst sind. Die Skripte werden ohne Gewähr bereitgestellt und unterliegen keiner regelmäßigen Wartung oder offiziellen Unterstützung.
Hinweis für Entwickler
Wenn Sie eigene Skripte bereitstellen, achten Sie bitte darauf, eine klare Beschreibung, eventuelle Einschränkungen und Sicherheitsaspekte zu dokumentieren. Beachten Sie zudem, dass Nutzer Ihre Skripte grundsätzlich auf eigenes Risiko verwenden. Eine Haftung für Schäden ist ausgeschlossen, sofern diese nicht vorsätzlich oder grob fahrlässig verursacht wurden oder gesetzlich anderweitig geregelt ist.
-
-
Yah it is.
Example script that controls something remotely:
Code
Alles anzeigenfunction Event_Trigger(data){ let input0= Efilter(data,{device:['input:0'],filterValue:['single_push']}); let input1= Efilter(data,{device:['input:1'],filterValue:['single_push']}); if(input0) Switch_RGB('on'); if(input1) Switch_RGB('off'); } function Switch_RGB(turn){ callLimit= 1, cSp= 1; //active Call Limit and speed betwinn calls Call('HTTP.get',{url: 'http://192.168.178.51/white/1?turn='+turn, timeout: 1}); Call('HTTP.get',{url: 'http://192.168.178.51/white/0?turn='+turn, timeout: 1}); Call('HTTP.get',{url: 'http://192.168.178.11/white/3?turn='+turn, timeout: 1}); Call('HTTP.get',{url: 'http://192.168.178.11/white/2?turn='+turn, timeout: 1}); Call('HTTP.get',{url: 'http://192.168.178.11/white/1?turn='+turn, timeout: 1}); Call('HTTP.get',{url: 'http://192.168.178.11/white/0?turn='+turn, timeout: 1}); } function Main(){ Shelly.addEventHandler(Event_Trigger); } //Dekats Toolbox, a universal Toolbox for Shelly scripts function Blink(bc,dl,c,st){//Call Blink funktion, bc=blinkCount, dl=blinkDelay, c=call->as_arry->[methode,parameter], st=startCount try{ if(tH8) Timer.clear(tH8); tH8= 0; if(!Str(st)) st= 0; if(st < bc*2){st++;}else{st= 0; return;} if(!tH8) tH8= Timer.set(1000*dl,0,function(){Call(c[0],c[1],function(){tH8= 0; Blink(bc,dl,c,st);},c[3],c[4]);}); }catch(e){ErrorMsg(e,'Blink()');}} function SwitchM(cID,rM,iT,deBug){ //Change rM=RelayMode, iT=InputMode, cID=Relay_ID and/or Input_ID, try{ //More Info, rM='detached'->detached/flip/momentary/follow,iT='switch'->button/switch let r= 0; if(Config('switch',cID).initial_state === 'match_input') Call('Switch.SetConfig',{id:cID,config:{initial_state:'restore_last'}}); if(rM && Config('switch',cID).in_mode !== rM){Call('Switch.SetConfig',{id:cID,config:{in_mode: rM}});if(!r){r= '';} r+='rM, ';} if(iT && Config('input',cID).type !== iT){Call('Input.SetConfig',{id:cID,config:{type: iT}});if(!r){r= '';} r+='iT, ';} if(deBug){r='Debug: tryed to change-> '+(r||'nothing,')+' Oldconfig: rM-> '+Config('switch',cID).in_mode+', iT-> '+Config('input',cID).type; print(r);} return r;}catch(e){ErrorMsg(e,'SwitchM()');}} function Str(d){ //Upgrade JSON.stringify try{ if(d === null || d === undefined) return null; if(typeof d === 'string')return d; return JSON.stringify(d);}catch(e){ErrorMsg(e,'Str()');}} function Cut(f,k,o,i){ //Upgrade slice f=fullData, k=key-> where to cut, o=offset->offset behind key, i=invertCut try{ let s= f.indexOf(k); if(s === -1) return; if(o) s= s+o.length || s+o; if(i) return f.slice(0,s); return f.slice(s);}catch(e){ErrorMsg(e,'Cut()');}} function Efilter(d,p,deBug) { //Event Filter, d=eventdata, p={device:[], filterKey:[], filterValue:[], noInfo:true, inData:true}->optional_parameter try{ let fR= {}; if(p.noInfo){fR= d; d= {}; d.info= fR; fR= {};} if(p.inData && d.info.data){d.info= d.info.data; delete d.info.data;} if(!d.info) fR.useless= true; if(p.device.length > 0 && p.device.indexOf(d.info.component) === -1) fR.useless= true; if(p.filterKey && !fR.useless) for(f of p.filterKey) for(k in d.info) if(f === k) fR[k]= d.info[k]; if(p.filterValue && !fR.useless) for(f of p.filterValue) for(v of d.info) if(Str(v) && f === v) fR[Str(v)]= v; if(deBug) print('\nDebug: EventData-> ', d, '\n\nDebug: Result-> ', fR, '\n'); if(Str(fR) === '{}' || fR.useless){return;} return fR;}catch(e){ErrorMsg(e,'Efilter()');}} function ErrorChk(r,e,m,d){ //Shelly.call error check try{ aC--; if(aC<0) aC= 0; if(d.CB && d.uD) d.CB(r,d.uD); if(d.CB && !d.uD) d.CB(r); if(!d.CB && d.uD) print('Debug: ',d.uD); if(e) throw new Error(Str(m)); if(Str(r) && Str(r.code) && r.code !== 200) throw new Error(Str(r)); }catch(e){ErrorMsg(e,'ErrorChk(), call Answer');}} function Cqueue(){ //Shelly.call queue try{ if(!cCache[0] && !nCall[0]) return; if(!nCall[0]){nCall= cCache[0]; cCache.splice(0,1);} if(nCall[0] && aC < callLimit){Call(nCall[0],nCall[1],nCall[2],nCall[3],nCall[4]); nCall= [];} if((nCall[0] || cCache[0]) && !tH7) tH7= Timer.set(1000*cSp,0,function(){tH7= 0; Cqueue();});}catch(e){ErrorMsg(e,'Cqueue()');}} function Call(m,p,CB,uD,deBug){ //Upgrade Shelly.call try{ let d= {}; if(deBug) print('Debug: calling:',m,p); if(CB) d.CB= CB; if(Str(uD)) d.uD= uD; if(!m && CB){CB(uD); return;} if(aC < callLimit){aC++; Shelly.call(m,p,ErrorChk,d);}else if(cCache.length < cacheLimit){ cCache.push([m,p,CB,uD,deBug]); if(deBug) print('Debug: save call:',m,p,', call queue now:',cCache.length); Cqueue(); }else{throw new Error('to many Calls in use, droping call: '+Str(m)+', '+Str(p));}}catch(e){ErrorMsg(e,'Call()');}} function Setup(l){ //Wating 2sek, to avoid a Shelly FW Bug try{ if(Main && !tH9){ tH9= Timer.set(2000,l,function(){print('Status: started Script _[', scriptN,']_'); if(callLimit > 5){callLimit= 5;} try{Main();}catch(e){ErrorMsg(e,'Main()'); Setup();}});}}catch(e){ErrorMsg(e,'Setup()');}} function ErrorMsg(e,s){ //Toolbox formatted Error Msg try{ let i= 0; if(Cut(e.message, '-104: Timed out')) i= 'wrong URL or device may be offline'; if(s === 'Main()') i= e.stack; if(Cut(e.message, '"Main" is not')) i= 'define a Main() function before using Setup()'; print('Error:',s || "",'---> ',e.type,e.message); if(i) print('Info: maybe -->',i);}catch(e){print('Error: ErrorMsg() --->',e);}} var tH7= 0, tH8= 0, tH9= 0, aC= 0, cCache= [], nCall= [], callLimit= 5, cacheLimit= 40, cSp= 0.2; //Toolbox global variable var Status= Shelly.getComponentStatus, Config= Shelly.getComponentConfig; //Renamed native function var info= Shelly.getDeviceInfo(), scriptID= Shelly.getCurrentScriptId(), scriptN= Config('script',scriptID).name; //Pseudo const, variabel //Toolbox v2.0-Alpha(full), Shelly FW >1.0.2 Setup();
-
Hi thanks for the script.
I need to figure out at what point in the 86 lines of code is the start of the script remotely.
In the precision I want to do this:
Slelly_1PM Plus contains the script "scr power"
Shelly I4 Plus With a command starts the script "scr power" on Shelly_1PM
-
The part that is tuning on the RGB, so the function called: Switch_RGB
You can controle any Shelly over a URL, and inside Call() this code is calling your preset url, witch in this exampel would be http://192.168.178.51/white/0?turn=on or http://192.168.178.51/white/0?turn=off
The url to Start a Script could be: http://192.168.0.51/rpc/Script.Start?id=3
And to Stop it: http://192.168.0.51/rpc/Script.Stop?id=3
The ID, obviously, must be your script ID.
https://shelly-api-docs.shelly.cloud/gen2/ComponentsAndServices/Script
More Infos about Shelly URLs:
https://shelly-api-docs.shelly.cloud/gen2/Component…rvices/Webhook/
https://shelly-api-docs.shelly.cloud/gen2/Component…ndpoint-relayid
-
Thanks again
But my question is how to run a script to another device
Device 1 say to device 2 run your script named "scr power" -
Dieses Thema enthält 3 weitere Beiträge, die nur für registrierte Benutzer sichtbar sind.