NEWS
Aqara Cube Skript Beispiel
-
Moin Moin!!
Ich hab gestern mal ein wenig mit meiner neusten Errungenschaft rumgespielt und folgendes Skript entworfen.
/* Aqara Cube Skript Events: 90 Grad 180 Grad schieben hochwerfen & auffangen schütteln Taptap drehen */ var CubeS = "deconz.0.Sensor_35.buttonevent", // Cube Switch CubeR = "deconz.0.Sensor_36.buttonevent", // Cube Rotate switchVal, degree, elements = [], elementsInt= [], debug; // Sleep Funktion Experimental function sleep(milliseconds) { var start = new Date().getTime(); for (var i = 0; i < 1e7; i++) { if ((new Date().getTime() - start) > milliseconds){ break; } } } debug = 0; // DEBUG MODE: 0 = Aus, 1 = Aktionen anzeigen, 2 = Alles anzeigen on({id: CubeS, change: "any"}, function (obj) { // Objekt in String wandeln, doppel Null entfernen und ergebnisse in Array elements schreiben. switchVal = JSON.stringify(getState(CubeS).val); elements = switchVal.split("00"); // Elemente des Arrays in Integerwerte konvertieren for(var i=0; i<elements.length;i++) elementsInt[i] = parseInt(elements[i], 10); if (debug >= 2) { console.log("Original: " + getState(CubeS).val + " Element 1: " + elements[0] + " Element 2: " + elements[1]); } var total = elementsInt[0] + elementsInt [1]; if (debug >= 2) { console.log("Total: " + total); } if (( elementsInt[0] + elementsInt [1] == 7 ) && ( elementsInt [1] !== 0 )) { if (debug == 1) { console.log("180 Grad" + " Seite: " + elementsInt[0] + " liegt oben."); } setState("denon.0.zoneMain.skipMinus"/*Previous*/, true); // sleep(550); setState("denon.0.zoneMain.skipMinus"/*Previous*/, true); } else if ( elementsInt[0] + elementsInt [1] == 14) { if (debug == 1) { console.log("Geschüttelt"); } setState("denon.0.zoneMain.skipMinus"/*Previous*/, true); } else if ( elementsInt[0] + elementsInt [1] == 15) { sleep(2000); if (debug == 1) { console.log("Geworfen"); } if (getState("denon.0.zoneMain.powerZone"/*Main Zone Power State*/).val === false) { setState("denon.0.zoneMain.powerZone"/*Main Zone Power State*/,true); } else { setState("denon.0.zoneMain.powerZone"/*Main Zone Power State*/,false); } } else if ( elementsInt[0] == elementsInt [1] ) { if (debug == 1) { console.log("TapTap" + " Seite: " + elementsInt[0] + " liegt oben."); } setState("denon.0.zoneMain.playPause"/*Play/Pause*/, true); } else if (( elementsInt [1] === 0 ) && ( elementsInt [0] <= 6 )) { if (debug == 1) { console.log("Schieben" + " Seite: " + elementsInt[0] + " liegt oben." ); } } else if (( elementsInt [1] === 0 ) && ( elementsInt [0] <= 7 )) { if (debug == 1) { console.log("Cube Wakeup!"); } } else if ( elementsInt [0] <= 6 ) { if (debug == 1) { console.log("90 Grad" + " Seite: " + elementsInt[0] + " liegt oben."); } setState("denon.0.zoneMain.skipPlus"/*Next*/, true); } }); on({id: CubeR, change: "ne"}, function (obj) { // nur bei änderung Triggern "ne" not equal var rotationVal = JSON.stringify(getState(CubeR).val); // Objekt in String konvertieren // Schauen ob rotationVal negativ/positiv ist und nur die ersten beiden bzw. drei ziffern verwenden. if ( rotationVal.substr(0,1) == "-" ) { if (rotationVal.length == 6 ) { degree = rotationVal.substr(0,4); } else { degree = rotationVal.substr(0,3); } } else { if (rotationVal.length == 5 ) { degree = rotationVal.substr(0,3); } else { degree = rotationVal.substr(0,2); } } if (debug == 1) { console.log("gedreht: " + degree); } // Volume des AVR auslesen var aMainVol = parseInt(getState("denon.0.zoneMain.volume"/*Main Volume*/).val); // Neues Volumen errechnen if (debug >= 2) { console.log("Ergebnis: " + parseInt(degree) / 5); } if (parseInt(degree) > 60) { if (debug >= 2) { console.log("Vol unterschied zu hoch, angepasst!"); } degree = 60; } var newMainVol = (degree / 5) + aMainVol; if (debug >= 2) { console.log("Vol unterschied: " + (parseInt(degree) / 5)); console.log("mainvol: " + aMainVol + " newMainVol: " + newMainVol); } // Neues Volumen an AVR senden setState("denon.0.zoneMain.volume", newMainVol); });
Ich steuere damit meinen Denon AVR. Vielleicht ist es für den ein oder anderen noch nützlich.
Bin gerne offen für Verbesserungen oder Anregungen!
Viele Grüße,
Chris
-
Hi, wie cool "fallen" kannte ich noch garnicht. Ich habe den zigbee2mqtt adapter bei mir sieht die Steuerung "einfacher" aus..
//Würfel on({id: 'mqtt.0.zigbee2mqtt.Wuerfel'}, function (obj) { var sschalter1 = getState("mqtt.0.zigbee2mqtt.Wuerfel").val; //shake if (sschalter1.indexOf('shake') > 0 ) { setState("sonoff.0.Lampe1.POWER1",false); setState("sonoff.0.Lampe2.POWER1",false); } //flip90 if (sschalter1.indexOf('flip90') > 0 ) { setStateDelayed("javascript.0.Netflix_scene",!getState("javascript.0.Netflix_scene").val,100); } //flip180 if (sschalter1.indexOf('flip180') > 0 ) { setStateDelayed("javascript.0.Playstation_scene",!getState("javascript.0.Playstation_scene").val,100); } //slide if (sschalter1.indexOf('slide') > 0 ) { setState("sonoff.0.Lampe1.POWER1",true); setState("sonoff.0.Lampe2.POWER1",true); } //tap if (sschalter1.indexOf('tap') > 0 ) { } //fall if (sschalter1.indexOf('fall') > 0 ) { } //rotate_left if (sschalter1.indexOf('rotate_left') > 0 ) { setStateDelayed("sonoff.0.Lampe1.POWER1",!getState("sonoff.0.Lampe1.POWER1").val,100); } //rotate_right if (sschalter1.indexOf('rotate_right') > 0 ) { setStateDelayed("sonoff.0.Lampe2.POWER1",!getState("sonoff.0.Lampe2.POWER1").val,100); } });
Hier im Forum / auf der Website fehlt wirklich ein Bereich in dem fertige Skriptvorlagen nach Gerät gepostet werden können. Grade als Anfänger fehlt einem sowas…
Gruß Martin
-
@Kugelkopf
Hallo Chris,
ich habe versucht Dein Script zu übernehmen, jedoch scheint beim Umzug auf das neue Forum die Syntax etwas durcheinander geraten zu sein. Es wäre super, wenn Du Dein Script nochmal posten könntest.Viele Grüße
Stefan -
@DNC74
Tatsächlich! Da fehlte die hälfte! Hab ihn noch einmal gepostet! -
als Blockly könnt ich was damit anfangen, aber so leider nicht!
-
<xml xmlns="http://www.w3.org/1999/xhtml"> <block type="on_ext" id="#dU%bHFVm/~[XFv;e5M5" x="-362" y="-412"> <mutation items="3"></mutation> <field name="CONDITION">ne</field> <field name="ACK_CONDITION"></field> <value name="OID0"> <shadow type="field_oid" id="luObs(yNi=oW98s~lUkF"> <field name="oid">mihome.0.devices.cube_158d0002486a98.tap_twice</field> </shadow> </value> <value name="OID1"> <shadow type="field_oid" id="|X5zwhq%~Zkbz~1R0r1^"> <field name="oid">mihome.0.devices.cube_158d0002486a98.rotate_left</field> </shadow> </value> <value name="OID2"> <shadow type="field_oid" id="Ig5d`gN3)^t%EXeY.S-Z"> <field name="oid">mihome.0.devices.cube_158d0002486a98.rotate_right</field> </shadow> </value> <statement name="STATEMENT"> <block type="controls_if" id="T%b0W^#l-ZWU%w^7]WQ/"> <mutation else="1"></mutation> <value name="IF0"> <block type="logic_compare" id=".`5XJGz4u6:p[#j+uoBh"> <field name="OP">EQ</field> <value name="A"> <block type="get_value" id="Tc#Gzin|@s,p7.86ILp/"> <field name="ATTR">val</field> <field name="OID">mihome.0.devices.cube_158d0002486a98.tap_twice</field> </block> </value> <value name="B"> <block type="logic_boolean" id="sH3Sm+bH^3l}+?.kIlZ*"> <field name="BOOL">TRUE</field> </block> </value> </block> </value> <statement name="DO0"> <block type="control" id="GMFizRUT:N0*[sm//5C7"> <mutation delay_input="false"></mutation> <field name="OID">milight-smart-light.0.sofa.fullColor-1.on</field> <field name="WITH_DELAY">FALSE</field> <value name="VALUE"> <block type="logic_boolean" id="uM4K3}(TzBBGgS:EBNJq"> <field name="BOOL">TRUE</field> </block> </value> </block> </statement> <statement name="ELSE"> <block type="control" id="]5d0uAxN+n.yg-_q*iB("> <mutation delay_input="false"></mutation> <field name="OID">milight-smart-light.0.sofa.fullColor-1.on</field> <field name="WITH_DELAY">FALSE</field> <value name="VALUE"> <block type="logic_boolean" id="vYk~DDSkAfHWd,-CdltZ"> <field name="BOOL">FALSE</field> </block> </value> </block> </statement> <next> <block type="controls_if" id="-~N|^SYc[!CTK[TPcQzH"> <value name="IF0"> <block type="logic_compare" id="H9+rQUM=TpWly3DBM_~A"> <field name="OP">EQ</field> <value name="A"> <block type="logic_operation" id="+SU99~P};R!O?s-(scra"> <field name="OP">OR</field> <value name="A"> <block type="get_value" id="^Rh:Rf7iTKm+b[[DYHdS"> <field name="ATTR">val</field> <field name="OID">mihome.0.devices.cube_158d0002486a98.rotate_left</field> </block> </value> <value name="B"> <block type="get_value" id="I5Q}-gdcBy5M)^%!Ndze"> <field name="ATTR">val</field> <field name="OID">mihome.0.devices.cube_158d0002486a98.rotate_right</field> </block> </value> </block> </value> <value name="B"> <block type="logic_boolean" id="BxN3`-GfmKb8{,UE=S_^"> <field name="BOOL">TRUE</field> </block> </value> </block> </value> <statement name="DO0"> <block type="control" id="j*0?O6@k8zXJWBhf,E{-"> <mutation delay_input="false"></mutation> <field name="OID">milight-smart-light.0.sofa.fullColor-1.brightness</field> <field name="WITH_DELAY">FALSE</field> <value name="VALUE"> <block type="get_value" id="ogc{OH[aGG9?M]Cz`A7W"> <field name="ATTR">val</field> <field name="OID">mihome.0.devices.cube_158d0002486a98.rotate</field> </block> </value> </block> </statement> </block> </next> </block> </statement> </block> <block type="controls_if" id="?jy5dedv*E!QXGSi|NNj" x="-263" y="-12"> <value name="IF0"> <block type="logic_compare" id=",%MaGZBY;oBO^b*3c`^W"> <field name="OP">EQ</field> <value name="A"> <block type="get_value" id="3iLCScaw~~5;AaE5*7}f"> <field name="ATTR">val</field> <field name="OID">mihome.0.devices.cube_158d000110819c.flip180</field> </block> </value> <value name="B"> <block type="logic_boolean" id=",BhqR-}WbG#ZGZ#Fs{1x"> <field name="BOOL">TRUE</field> </block> </value> </block> </value> <statement name="DO0"> <block type="control" id="?l@4Bn7S(^Ed^-loZuO^"> <mutation delay_input="false"></mutation> <field name="OID">yeelight.0.stripe_0x0000000004cdb91c.rgb</field> <field name="WITH_DELAY">FALSE</field> <value name="VALUE"> <block type="text" id="1MI}0}SU9P=%6Kb)b4[w"> <field name="TEXT">#ff0000</field> </block> </value> <next> <block type="control" id="r*axzx{?XXlo*DE)VVGo"> <mutation delay_input="false"></mutation> <field name="OID">yeelight.0.stripe_0x0000000004cdb91c.power</field> <field name="WITH_DELAY">FALSE</field> <value name="VALUE"> <block type="logic_boolean" id="|x(Rj|i/SziXlG:aGU[Q"> <field name="BOOL">TRUE</field> </block> </value> </block> </next> </block> </statement> </block> <block type="controls_if" id="W|nOmNk7Ri}Fs|:3bNvo" x="-263" y="163"> <value name="IF0"> <block type="logic_compare" id="Nq,pYQn=QZIL]h`|k!{R"> <field name="OP">EQ</field> <value name="A"> <block type="get_value" id="VfAn.8Ks0/7;o3resSQV"> <field name="ATTR">val</field> <field name="OID">mihome.0.devices.cube_158d000110819c.tap_twice</field> </block> </value> <value name="B"> <block type="logic_boolean" id="|36:z7/2Lb=#qES!gYLY"> <field name="BOOL">TRUE</field> </block> </value> </block> </value> <statement name="DO0"> <block type="control" id="|DLqeKZy?:%(GP+|R;CA"> <mutation delay_input="false"></mutation> <field name="OID">yeelight.0.stripe_0x0000000004cdb91c.rgb</field> <field name="WITH_DELAY">FALSE</field> <value name="VALUE"> <block type="text" id=",K`3%4I8x5:BN~@iTynJ"> <field name="TEXT">#26ff00</field> </block> </value> <next> <block type="control" id="m6.ck5b`ol;yUn9)hBs*"> <mutation delay_input="false"></mutation> <field name="OID">yeelight.0.stripe_0x0000000004cdb91c.power</field> <field name="WITH_DELAY">FALSE</field> <value name="VALUE"> <block type="logic_boolean" id="TV7.E*ef)pBpHf#s0`P."> <field name="BOOL">TRUE</field> </block> </value> </block> </next> </block> </statement> </block> <block type="controls_if" id=",9_Nr-P-{%Fd+Tc0-=Nu" x="-263" y="338"> <value name="IF0"> <block type="logic_compare" id="=(DbOS78=0MBQe=F%*.D"> <field name="OP">EQ</field> <value name="A"> <block type="get_value" id="DpgzqNoWjD?gGY|.nPM_"> <field name="ATTR">val</field> <field name="OID">mihome.0.devices.cube_158d000110819c.flip90</field> </block> </value> <value name="B"> <block type="logic_boolean" id="DkzF1(|Ey=3{V,DFkJfD"> <field name="BOOL">TRUE</field> </block> </value> </block> </value> <statement name="DO0"> <block type="control" id="R*!kKkNLS,,7%@yid/)["> <mutation delay_input="false"></mutation> <field name="OID">yeelight.0.stripe_0x0000000004cdb91c.rgb</field> <field name="WITH_DELAY">FALSE</field> <value name="VALUE"> <block type="text" id="4%AtCh@rJ(yc:t*(_~!r"> <field name="TEXT">#000cff</field> </block> </value> <next> <block type="control" id="7wOgFVW/5}RyS}Tsfr`G"> <mutation delay_input="false"></mutation> <field name="OID">yeelight.0.stripe_0x0000000004cdb91c.power</field> <field name="WITH_DELAY">FALSE</field> <value name="VALUE"> <block type="logic_boolean" id="#4C;ew#;!vgsy,B(P%Uz"> <field name="BOOL">TRUE</field> </block> </value> </block> </next> </block> </statement> </block> </xml>
-
<xml xmlns="http://www.w3.org/1999/xhtml"> <variables> <variable type="" id=":F/vvdQoDFuo*3MDomQ;">rotate_value</variable> </variables> <block type="on" id="hlAvojw#?(9*n9Z:9heF" x="-687" y="-87"> <field name="OID">zigbee.0.00158d00027910f4.rotate_right</field> <field name="CONDITION">false</field> <field name="ACK_CONDITION"></field> <statement name="STATEMENT"> <block type="debug" id="W{s{FLktw#a.N)m}_q@3"> <field name="Severity">log</field> <value name="TEXT"> <shadow type="text" id="4||V[Rl;wP]P?}SmcDx+"> <field name="TEXT">test</field> </shadow> <block type="get_value" id="aCm6L8m0Q}^WR{N2X7uC"> <field name="ATTR">val</field> <field name="OID">zigbee.0.00158d00027910f4.rotate_angle</field> </block> </value> <next> <block type="variables_set" id="K/JDq+GIyq2rJm3%OptP"> <field name="VAR" id=":F/vvdQoDFuo*3MDomQ;" variabletype="">rotate_value</field> <value name="VALUE"> <block type="get_value" id="EU*txqmQyBVt`dkMigF`"> <field name="ATTR">val</field> <field name="OID">zigbee.0.00158d00027910f4.rotate_angle</field> </block> </value> <next> <block type="variables_set" id="N0cg?t+du8zDHO%B*Y`["> <field name="VAR" id=":F/vvdQoDFuo*3MDomQ;" variabletype="">rotate_value</field> <value name="VALUE"> <block type="math_arithmetic" id="#%r4Dx`cY?TO,phm[WJO"> <field name="OP">DIVIDE</field> <value name="A"> <shadow type="math_number" id="ih/X!xZZnAYGdAP:FJ}t"> <field name="NUM">1</field> </shadow> <block type="variables_get" id="BCxQzb/yvsAHF3`QsBND"> <field name="VAR" id=":F/vvdQoDFuo*3MDomQ;" variabletype="">rotate_value</field> </block> </value> <value name="B"> <shadow type="math_number" id="tX?`;|NLHe%T-`4zzAKZ"> <field name="NUM">3</field> </shadow> </value> </block> </value> <next> <block type="debug" id="[HE*u*{4y]uc~myyIajt"> <field name="Severity">log</field> <value name="TEXT"> <shadow type="text" id="3+6)0NHNU.%_eM[`pN%1"> <field name="TEXT">test</field> </shadow> <block type="variables_get" id="F/.#8,CV|MDfngO8[_SF"> <field name="VAR" id=":F/vvdQoDFuo*3MDomQ;" variabletype="">rotate_value</field> </block> </value> </block> </next> </block> </next> </block> </next> </block> </statement> </block> </xml>
-
@Kugelkopf
Besten Dank! Funktioniert super!@crunchip
ist sicher gut gemeint, jedoch arbeitet Dein Blockly mit der Mi-Bridge, und die Lösung von @Kugelkopf basiert auf Deconz ohne die Mi-Bridge... genau das was ich gesucht habe. -
@crunchip Hey!° Finde es super, dass du dein Skript hinzugefügt hast! Nutze selbst. viele Foren als Wissensdatenbank.
Es wäre jedoch super, wenn du deine beiden Threads bearbeiten könntest und die code Tags richtig setzt =)!Viele Grüße!
-
@Kugelkopf
Hallo KugelkopfWürde auch gerne mal dein Cube Skript testen.
Kannst du bitte dein vollständiges Skript bitte noch einmal posten.
Das oben kann ich leider nicht importieren. Kommt eine Fehlermeldung beim Import.
Danke