NEWS
[gelöst] Zigbee Überwachung via Blockly
-
Hallo Gemeinde,
ich versuche hier seit 3 Tagen, eine Zigbee-Überwachung via Blockly hinzubekommen. Dabei möchte ich gern den "IDs vom selektor"-Block mit benutzen, um nicht alle Zigbee-Geräte einzeln anklicken/im Skript einfügen zu müssen. ABER, klappt nicht...ich bekomme keinen Output. Irgendwas übersehe ich entweder oder ist einfach falsch.So sieht mein Blockly aus (hab das Zeitelement auf 0 gesetzt; vorher 84600000 um Tage auf ms zu bringen):
In der JS-Funktion habe ich folgenden Code (den obersten hatte ich schon ausprobiert, un dachte, ich probiers anders:
//return getObject(id.substring(0, id.lastIndexOf('.'))).common.name; return getObject(id).common.name
und damit auch die erfahrenen Java-Skriptler das einfacher lesen können, den Output als Java-Skript:
var tage, id, Namen, differenz, i; // Beschreibe diese Funktion … async function getParentName(id) { //return getObject(id.substring(0, id.lastIndexOf('.'))).common.name; return getObject(id).common.name } tage = 1; schedule("*/5 * * * *", async function () { Namen = ''; differenz = tage * 0; if ((new Date().getTime()) - differenz > getState(i).ts) { var i_list = Array.prototype.slice.apply($("state[id=alias.0.*]")); for (var i_index in i_list) { i = i_list[i_index]; Namen = String(Namen) + String(await getParentName(i)); } } }); on({id: Namen, change: "ne"}, async function (obj) { var value = obj.state.val; var oldValue = obj.oldState.val; sendTo("telegram", "send", { text: (['1 Tag keine Änderung bei','\n',Namen].join('')) }); });
Das ist so wenig Code und ich komm damit nicht zurecht, sorry.
Danke euch und vG, Thorsten
-
@Kueppert
Die Abfrage auf die Zeitdifferenz muss in die Schleife. -
@paul53 meinst du so:
Hab jetzt ne Fehlermeldung bekommen:
warn javascript.0 (538) at Object.<anonymous> (script.js.common.Sonstiges.Status_letzte_Aktualisierung:15:44)
-
-
@paul53 hm, hab wieder neue Fehlermeldungen
18:35:11.704 error javascript.0 (538) script.js.common.Sonstiges.Status_letzte_Aktualisierung: TypeError: Cannot read property 'length' of undefined 18:35:11.704 error javascript.0 (538) at script.js.common.Sonstiges.Status_letzte_Aktualisierung:23:11 18:35:11.705 error javascript.0 (538) at script.js.common.Sonstiges.Status_letzte_Aktualisierung:30:3
-
@Kueppert sagte:
hab wieder neue Fehlermeldungen
Der falls-Block mit telegram gehört in den Zeitplan unter die Schleife (s. mein Bild).
-
@paul53 sorry, bin vor lauter Bearbeitung ganz blind geworden. Danke dir
Dann warte ich mal ab, ob es klappt. Ein Sensor ist definitiv seit 1 Monat offline ^^
-
*** GELÖST ***
So,
für alle die ggf. danach suchen anbei das fertige Blockly:Der Javaskript-Blockly beinhaltet folgenden Code:
return getObject(id.substring(0, id.lastIndexOf('.'))).common.name;
Blockly-Export:
<xml xmlns="https://developers.google.com/blockly/xml"> <variables> <variable id="Hxgr,3rW59z?c[p:m55!">id</variable> <variable id="J}Gnjc[$U]~GgxsXotr)">tage</variable> <variable id="GQCJ-ywGYI:D%^3R]1zy">Namen</variable> <variable id="jk_f9Bsj*{k?NKo`D5g(">differenz</variable> <variable id="^fQ?5!9i6[PA6I~$jq?*">i</variable> </variables> <block type="procedures_defcustomreturn" id="?)C+XJ:/T[|h7CJ#).Lc" x="337" y="63"> <mutation statements="false"> <arg name="id" varid="Hxgr,3rW59z?c[p:m55!"></arg> </mutation> <field name="NAME">getParentName</field> <field name="SCRIPT">cmV0dXJuIGdldE9iamVjdChpZC5zdWJzdHJpbmcoMCwgaWQubGFzdEluZGV4T2YoJy4nKSkpLmNvbW1vbi5uYW1lOw0KDQovL3JldHVybiBnZXRPYmplY3QoaWQpLmNvbW1vbi5uYW1l</field> <comment pinned="false" h="80" w="160">Beschreibe diese Funktion …</comment> </block> <block type="variables_set" id="{^-0S#IiV#S#+`s7t;j;" x="22" y="81"> <field name="VAR" id="J}Gnjc[$U]~GgxsXotr)">tage</field> <value name="VALUE"> <block type="math_number" id="NtZtYH@mPbRNCcm%.!O0"> <field name="NUM">2</field> </block> </value> <next> <block type="schedule" id="D3V$+;;O($)#o16sY9jL"> <field name="SCHEDULE">*/5 * * * *</field> <statement name="STATEMENT"> <block type="variables_set" id="VU4J0DT0q;}1,``D{dBE"> <field name="VAR" id="GQCJ-ywGYI:D%^3R]1zy">Namen</field> <value name="VALUE"> <block type="text" id="deb5rSpqc9d4C[E=K1`T"> <field name="TEXT"></field> </block> </value> <next> <block type="variables_set" id=":GT*_Z9OU[RtXTywPw*^"> <field name="VAR" id="jk_f9Bsj*{k?NKo`D5g(">differenz</field> <value name="VALUE"> <block type="math_arithmetic" id="[RU,:k0s]X2:w*((]2,?"> <field name="OP">MULTIPLY</field> <value name="A"> <shadow type="math_number" id="-;S7NqYJ;k!Y%zs;xO6D"> <field name="NUM">1</field> </shadow> <block type="variables_get" id="Nd-`50-Stf(ly^gV4!0H"> <field name="VAR" id="J}Gnjc[$U]~GgxsXotr)">tage</field> </block> </value> <value name="B"> <shadow type="math_number" id="N4{?!TT}Vl0nO_^xmbMB"> <field name="NUM">86400000</field> </shadow> </value> </block> </value> <next> <block type="controls_forEach" id="%ZUL,hL5JdgS*s;w1[Y4"> <field name="VAR" id="^fQ?5!9i6[PA6I~$jq?*">i</field> <value name="LIST"> <block type="selector" id="XG$Hl55rP5Q.wN(Y|-a_"> <field name="TEXT">state[id=zigbee.0.*.link_quality]</field> </block> </value> <statement name="DO"> <block type="controls_if" id="t+/u-1wx-dpU;79:ZI6!"> <value name="IF0"> <block type="logic_compare" id="lhj)!bvO}E:TNr*Szp@+" inline="false"> <field name="OP">GT</field> <value name="A"> <block type="math_arithmetic" id="I)ThU^Z_e{xml5;xZxj."> <field name="OP">MINUS</field> <value name="A"> <shadow type="math_number" id="L3XLA#qmwLTP4|c:UF^{"> <field name="NUM">1</field> </shadow> <block type="time_get" id="W1EXN}bTY=s/7n:.P^W`"> <mutation xmlns="http://www.w3.org/1999/xhtml" format="false" language="false"></mutation> <field name="OPTION">object</field> </block> </value> <value name="B"> <shadow type="math_number" id="_L{#0p5k5BXWf^Tij!zq"> <field name="NUM">1</field> </shadow> <block type="variables_get" id="OU:65s4*PC89O@Fu{4[U"> <field name="VAR" id="jk_f9Bsj*{k?NKo`D5g(">differenz</field> </block> </value> </block> </value> <value name="B"> <block type="get_value_var" id="Db0M1=*/jWOrdy1oqC@n"> <field name="ATTR">ts</field> <value name="OID"> <shadow type="text" id="!)hz[%)c:tf;pQW9-Z{C"> <field name="TEXT"></field> </shadow> <block type="variables_get" id="28]O6g7kc4E.!hNFx=*0"> <field name="VAR" id="^fQ?5!9i6[PA6I~$jq?*">i</field> </block> </value> </block> </value> </block> </value> <statement name="DO0"> <block type="variables_set" id="E+e|wvC1Di,taMrerrfs"> <field name="VAR" id="GQCJ-ywGYI:D%^3R]1zy">Namen</field> <value name="VALUE"> <block type="text_join" id=".jHkp#s7a+!79P]}siFt"> <mutation items="3"></mutation> <value name="ADD0"> <block type="variables_get" id="%UJ$nh%tH69sTzpQ=5X^"> <field name="VAR" id="GQCJ-ywGYI:D%^3R]1zy">Namen</field> </block> </value> <value name="ADD1"> <block type="procedures_callcustomreturn" id="*$ts29/9F}?n@hoGbmfS"> <mutation name="getParentName"> <arg name="id"></arg> </mutation> <value name="ARG0"> <block type="variables_get" id="u/QZXqTi_FT:6Z$)e[x)"> <field name="VAR" id="^fQ?5!9i6[PA6I~$jq?*">i</field> </block> </value> </block> </value> <value name="ADD2"> <block type="text_newline" id="TF{w[(Qt{PzLI2:RlX-H"> <field name="Type">\n</field> </block> </value> </block> </value> </block> </statement> </block> </statement> <next> <block type="debug" id="mv5[gr$eRnX%]9f{InZ."> <field name="Severity">log</field> <value name="TEXT"> <shadow type="text" id="`G:cXrbpWICu?.!0m/xl"> <field name="TEXT">test</field> </shadow> <block type="variables_get" id="QE~=rd{D_)VkU,~#g+zI"> <field name="VAR" id="GQCJ-ywGYI:D%^3R]1zy">Namen</field> </block> </value> <next> <block type="controls_if" id="IX}i.n9Z$8Oh7RnZ`_GS"> <value name="IF0"> <block type="logic_compare" id="y%mgm]jySOCJn5UJ?R]h"> <field name="OP">GT</field> <value name="A"> <block type="text_length" id="IQul02DUhqp:8vi^={XP"> <value name="VALUE"> <shadow type="text" id="Y3nXhm`ji,cLy*@!Amcq"> <field name="TEXT">abc</field> </shadow> <block type="variables_get" id="Ao_|9Whl}FgM:}@t:#h{"> <field name="VAR" id="GQCJ-ywGYI:D%^3R]1zy">Namen</field> </block> </value> </block> </value> <value name="B"> <block type="math_number" id="E+vohsdRwSwSZz8#ZBj9"> <field name="NUM">0</field> </block> </value> </block> </value> <statement name="DO0"> <block type="telegram" id="e/Yf#38+yVzNcIn?dUnK"> <field name="INSTANCE"></field> <field name="LOG"></field> <field name="SILENT">FALSE</field> <field name="PARSEMODE">default</field> <value name="MESSAGE"> <shadow type="text" id="xXm}h]MuLh=Nz4r7v3TN"> <field name="TEXT">text</field> </shadow> <block type="text_join" id="*+n0G`a,MXHl7|IQN1{j"> <mutation items="3"></mutation> <value name="ADD0"> <block type="text" id="D]+8_PT@|=D,!(7BMN$0"> <field name="TEXT">2 Tage keine Änderung bei</field> </block> </value> <value name="ADD1"> <block type="text_newline" id=":UcndGsUc~[AMw_%5,Y}"> <field name="Type">\n</field> </block> </value> <value name="ADD2"> <block type="variables_get" id="xq{`=O2WVDtd0p=FXR}X"> <field name="VAR" id="GQCJ-ywGYI:D%^3R]1zy">Namen</field> </block> </value> </block> </value> </block> </statement> </block> </next> </block> </next> </block> </next> </block> </next> </block> </statement> </block> </next> </block> </xml>
Danke @paul53 für die Hilfe. Thread schließe ich hiermit.
VG Thorsten
-
@kueppert
Vielen Dank für das Teilen des Skriptes.Meine Frage bezieht sich auf den Javaskript-Code.
Ich muss leider noch eine Ebene höher, um den richtigen Namen auszugeben und probiere hier schon den ganzen Tag rum und bekomme es nicht hin. Bei mir ist der Aufbau Gerätename/info/Datumsobjekt.Ohne dein Skript bekomme ich nur "Datumsobjekt" als Name ausgeworfen, mit Deinem "info" nur brauche ich den Gerätenamen, noch eins drüber.
Grüße
-
@skyx3 sagte: Gerätenamen, noch eins drüber.
Also den grandparentName?
id = id.substring(0, id.lastIndexOf('.')); return getObject(id.substring(0, id.lastIndexOf('.'))).common.name;
-
@paul53
WOW das ging fix und es funktioniert. Vielen Dank für Deine Hilfe