- Home
- Deutsch
- Skripten / Logik
- Frage zu Schleifen und Listen
Frage zu Schleifen und Listen
-
Hallo liebe Forengemeinde,
ich weiß, es gibt schon das eine oder andere Skript dafür, aber um mich ein wenig mit dem Skripten zu befassen, wollte ich ein Skript für den Batteriestatus (mit Blockly) erstellen.
Ich habe einen selbst erstellten Datenpunkt gegen den der Prozentwert der Batterie geprüft werden soll. Das Skrip funktioniert insofern, dass mit die Werte angezeigt werden, die unter dieser SChwelle liegen. Im Prinzip bräuchte ich anstatt der Ausgabe der Werte eine Ausgabe der Sonsoren (sollen per Telegram verschickt werden).
Die Funktion IDs vom Selektor funktioniert aber bei Listen nicht, habe ich gelesen.
Könntet ihr mir weiterhelfen, wie ich an die Namen komme?LG Stefan
BlocklyJavascriptTypeScriptRules Skript läuft nicht Protokoll id: any, Hinweis Ausgewählte Blöcke exportieren <xml xmlns="https://developers.google.com/blockly/xml"> <variables> <variable id="0iLzxl6zUmhXoRaBx{3r">Meldung</variable> <variable id="_j)6Z@}6(~kf)Ga.R^[o">Liste1</variable> <variable id="!qnLj.@Gz4{,jc:m8Ws/">i</variable> </variables> <block type="variables_set" id="PWLTX7!i8neRy5t[I2e1" x="213" y="-12"> <field name="VAR" id="0iLzxl6zUmhXoRaBx{3r">Meldung</field> <value name="VALUE"> <block type="text_join" id="WTm]h*):M)K/wbWDBLr|"> <mutation items="1"></mutation> <value name="ADD0"> <block type="text" id="2-aGntQW2u`R%9cjh{hD"> <field name="TEXT"></field> </block> </value> </block> </value> <next> <block type="variables_set" id=".FasuSGz.8BDPY+i^O8f"> <field name="VAR" id="_j)6Z@}6(~kf)Ga.R^[o">Liste1</field> <value name="VALUE"> <block type="lists_create_with" id="H]X_|yeY]3Rs;:Xiz`w+"> <mutation items="4"></mutation> <value name="ADD0"> <block type="get_value" id="]LuwrLI~O2i*WOf`@Q0X"> <field name="ATTR">val</field> <field name="OID">deconz.0.Sensors.10.battery</field> </block> </value> <value name="ADD1"> <block type="get_value" id="Q(|1W-`Ju[{.yk!FK_)p"> <field name="ATTR">val</field> <field name="OID">deconz.0.Sensors.11.battery</field> </block> </value> <value name="ADD2"> <block type="get_value" id="EF(?j,/lF0p$M?fi=d3J"> <field name="ATTR">val</field> <field name="OID">deconz.0.Sensors.2.battery</field> </block> </value> <value name="ADD3"> <block type="get_value" id="y%e.Fv)9^`fw;V$~:W~["> <field name="ATTR">val</field> <field name="OID">deconz.0.Sensors.14.battery</field> </block> </value> </block> </value> <next> <block type="controls_forEach" id="Ruy1LxZtr02;9HrPpNyg"> <field name="VAR" id="!qnLj.@Gz4{,jc:m8Ws/">i</field> <value name="LIST"> <block type="variables_get" id="ZXJoQ8NB`kmnH49-G|Yn"> <field name="VAR" id="_j)6Z@}6(~kf)Ga.R^[o">Liste1</field> </block> </value> <statement name="DO"> <block type="controls_if" id="3!]w:|Vu;[B_*_o]OJ]!"> <value name="IF0"> <block type="logic_compare" id="h_41e`RQ893V!_QB~!le"> <field name="OP">LT</field> <value name="A"> <block type="variables_get" id="TGySr%Y4?O6%Sc$Y*|*z"> <field name="VAR" id="!qnLj.@Gz4{,jc:m8Ws/">i</field> </block> </value> <value name="B"> <block type="get_value" id="AXwMwDEs4WjK?E*%MKBU"> <field name="ATTR">val</field> <field name="OID">0_userdata.0.uebergreifend.system.batterie_warnschwelle</field> </block> </value> </block> </value> <statement name="DO0"> <block type="controls_if" id="GIm(owb-,WKqtSn1rOKH"> <value name="IF0"> <block type="logic_operation" id="lF[n/wMsuGU68]uAgQ13"> <field name="OP">AND</field> <value name="A"> <block type="variables_get" id="Pbt:G2=%|9=ilgoLq+uF"> <field name="VAR" id="!qnLj.@Gz4{,jc:m8Ws/">i</field> </block> </value> <value name="B"> <block type="variables_get" id="qH6zT.-dw@xs8b^$G2!P"> <field name="VAR" id="0iLzxl6zUmhXoRaBx{3r">Meldung</field> </block> </value> </block> </value> <statement name="DO0"> <block type="variables_set" id=":@|u]CEsCj[:YV@vMT^("> <field name="VAR" id="0iLzxl6zUmhXoRaBx{3r">Meldung</field> <value name="VALUE"> <block type="text_join" id="ctwL~Y+vgsR=xog14L]r"> <mutation items="2"></mutation> <value name="ADD0"> <block type="variables_get" id="~r@1~?rk{xZET|Z;@9V("> <field name="VAR" id="0iLzxl6zUmhXoRaBx{3r">Meldung</field> </block> </value> <value name="ADD1"> <block type="text" id="=Xa|[n8SU4KRS`.,gi;["> <field name="TEXT">, </field> </block> </value> </block> </value> </block> </statement> <next> <block type="variables_set" id=")Di76}[uF6SuK(waVPEN"> <field name="VAR" id="0iLzxl6zUmhXoRaBx{3r">Meldung</field> <value name="VALUE"> <block type="text_join" id=";3zl3ZM`BpgW-?/,UBN;"> <mutation items="2"></mutation> <value name="ADD0"> <block type="variables_get" id="%Gnjs-8~kYxJa4J}6e]."> <field name="VAR" id="0iLzxl6zUmhXoRaBx{3r">Meldung</field> </block> </value> <value name="ADD1"> <block type="variables_get" id="k:y$McnTj_B;%%xNE4+l"> <field name="VAR" id="!qnLj.@Gz4{,jc:m8Ws/">i</field> </block> </value> </block> </value> </block> </next> </block> </statement> </block> </statement> <next> <block type="debug" id="Ki?H:OwmWwGXokw_o{q}"> <field name="Severity">log</field> <value name="TEXT"> <shadow type="text" id="^J.{ut|`tQqUaHd%P!+."> <field name="TEXT">test</field> </shadow> <block type="variables_get" id=":MtBWue|?c]t,N:a@,:i"> <field name="VAR" id="0iLzxl6zUmhXoRaBx{3r">Meldung</field> </block> </value> </block> </next> </block> </next> </block> </next> </block> </xml> <xml xmlns="https://developers.google.com/blockly/xml"> <variables> <variable id="0iLzxl6zUmhXoRaBx{3r">Meldung</variable> <variable id="_j)6Z@}6(~kf)Ga.R^[o">Liste1</variable> <variable id="!qnLj.@Gz4{,jc:m8Ws/">i</variable> </variables> <block type="variables_set" id="PWLTX7!i8neRy5t[I2e1" x="213" y="-12"> <field name="VAR" id="0iLzxl6zUmhXoRaBx{3r">Meldung</field> <value name="VALUE"> <block type="text_join" id="WTm]h*):M)K/wbWDBLr|"> <mutation items="1"></mutation> <value name="ADD0"> <block type="text" id="2-aGntQW2u`R%9cjh{hD"> <field name="TEXT"></field> </block> </value> </block> </value> <next> <block type="variables_set" id=".FasuSGz.8BDPY+i^O8f"> <field name="VAR" id="_j)6Z@}6(~kf)Ga.R^[o">Liste1</field> <value name="VALUE"> <block type="lists_create_with" id="H]X_|yeY]3Rs;:Xiz`w+"> <mutation items="4"></mutation> <value name="ADD0"> <block type="get_value" id="]LuwrLI~O2i*WOf`@Q0X"> <field name="ATTR">val</field> <field name="OID">deconz.0.Sensors.10.battery</field> </block> </value> <value name="ADD1"> <block type="get_value" id="Q(|1W-`Ju[{.yk!FK_)p"> <field name="ATTR">val</field> <field name="OID">deconz.0.Sensors.11.battery</field> </block> </value> <value name="ADD2"> <block type="get_value" id="EF(?j,/lF0p$M?fi=d3J"> <field name="ATTR">val</field> <field name="OID">deconz.0.Sensors.2.battery</field> </block> </value> <value name="ADD3"> <block type="get_value" id="y%e.Fv)9^`fw;V$~:W~["> <field name="ATTR">val</field> <field name="OID">deconz.0.Sensors.14.battery</field> </block> </value> </block> </value> <next> <block type="controls_forEach" id="Ruy1LxZtr02;9HrPpNyg"> <field name="VAR" id="!qnLj.@Gz4{,jc:m8Ws/">i</field> <value name="LIST"> <block type="variables_get" id="ZXJoQ8NB`kmnH49-G|Yn"> <field name="VAR" id="_j)6Z@}6(~kf)Ga.R^[o">Liste1</field> </block> </value> <statement name="DO"> <block type="controls_if" id="3!]w:|Vu;[B_*_o]OJ]!"> <value name="IF0"> <block type="logic_compare" id="h_41e`RQ893V!_QB~!le"> <field name="OP">LT</field> <value name="A"> <block type="variables_get" id="TGySr%Y4?O6%Sc$Y*|*z"> <field name="VAR" id="!qnLj.@Gz4{,jc:m8Ws/">i</field> </block> </value> <value name="B"> <block type="get_value" id="AXwMwDEs4WjK?E*%MKBU"> <field name="ATTR">val</field> <field name="OID">0_userdata.0.uebergreifend.system.batterie_warnschwelle</field> </block> </value> </block> </value> <statement name="DO0"> <block type="controls_if" id="GIm(owb-,WKqtSn1rOKH"> <value name="IF0"> <block type="logic_operation" id="lF[n/wMsuGU68]uAgQ13"> <field name="OP">AND</field> <value name="A"> <block type="variables_get" id="Pbt:G2=%|9=ilgoLq+uF"> <field name="VAR" id="!qnLj.@Gz4{,jc:m8Ws/">i</field> </block> </value> <value name="B"> <block type="variables_get" id="qH6zT.-dw@xs8b^$G2!P"> <field name="VAR" id="0iLzxl6zUmhXoRaBx{3r">Meldung</field> </block> </value> </block> </value> <statement name="DO0"> <block type="variables_set" id=":@|u]CEsCj[:YV@vMT^("> <field name="VAR" id="0iLzxl6zUmhXoRaBx{3r">Meldung</field> <value name="VALUE"> <block type="text_join" id="ctwL~Y+vgsR=xog14L]r"> <mutation items="2"></mutation> <value name="ADD0"> <block type="variables_get" id="~r@1~?rk{xZET|Z;@9V("> <field name="VAR" id="0iLzxl6zUmhXoRaBx{3r">Meldung</field> </block> </value> <value name="ADD1"> <block type="text" id="=Xa|[n8SU4KRS`.,gi;["> <field name="TEXT">, </field> </block> </value> </block> </value> </block> </statement> <next> <block type="variables_set" id=")Di76}[uF6SuK(waVPEN"> <field name="VAR" id="0iLzxl6zUmhXoRaBx{3r">Meldung</field> <value name="VALUE"> <block type="text_join" id=";3zl3ZM`BpgW-?/,UBN;"> <mutation items="2"></mutation> <value name="ADD0"> <block type="variables_get" id="%Gnjs-8~kYxJa4J}6e]."> <field name="VAR" id="0iLzxl6zUmhXoRaBx{3r">Meldung</field> </block> </value> <value name="ADD1"> <block type="variables_get" id="k:y$McnTj_B;%%xNE4+l"> <field name="VAR" id="!qnLj.@Gz4{,jc:m8Ws/">i</field> </block> </value> </block> </value> </block> </next> </block> </statement> </block> </statement> <next> <block type="debug" id="Ki?H:OwmWwGXokw_o{q}"> <field name="Severity">log</field> <value name="TEXT"> <shadow type="text" id="^J.{ut|`tQqUaHd%P!+."> <field name="TEXT">test</field> </shadow> <block type="variables_get" id=":MtBWue|?c]t,N:a@,:i"> <field name="VAR" id="0iLzxl6zUmhXoRaBx{3r">Meldung</field> </block> </value> </block> </next> </block> </next> </block> </next> </block> </xml>
-
@stefan1234
Anstelle der Werte-Liste verwende eine ID-Liste, die auch für den notwendigen Trigger geeignet ist.
<xml xmlns="https://developers.google.com/blockly/xml"> <variables> <variable id="_j)6Z@}6(~kf)Ga.R^[o">Liste1</variable> <variable id="!qnLj.@Gz4{,jc:m8Ws/">id</variable> <variable id="0iLzxl6zUmhXoRaBx{3r">Meldung</variable> </variables> <block type="variables_set" id=".FasuSGz.8BDPY+i^O8f" x="213" y="62"> <field name="VAR" id="_j)6Z@}6(~kf)Ga.R^[o">Liste1</field> <value name="VALUE"> <block type="lists_create_with" id="H]X_|yeY]3Rs;:Xiz`w+"> <mutation items="4"></mutation> <value name="ADD0"> <block type="text" id="85P3);Fo0{N?z@|GQp+,"> <field name="TEXT">deconz.0.Sensors.10.battery</field> </block> </value> <value name="ADD1"> <block type="text" id="{Z9tD5DEW3fbMHHgEzBs"> <field name="TEXT">deconz.0.Sensors.11.battery</field> </block> </value> <value name="ADD2"> <block type="text" id="2nK0kn,5^koe;)1jL3ku"> <field name="TEXT">deconz.0.Sensors.2.battery</field> </block> </value> <value name="ADD3"> <block type="text" id="r0krUUFmh`]}2i3La@TP"> <field name="TEXT">deconz.0.Sensors.14.battery</field> </block> </value> </block> </value> <next> <block type="on_ext" id="o:*^/77(9tzWF7.q$.6;"> <mutation xmlns="http://www.w3.org/1999/xhtml" items="1"></mutation> <field name="CONDITION">ne</field> <field name="ACK_CONDITION"></field> <value name="OID0"> <shadow type="field_oid" id="p;cETzj2B#pca#ByscIX"> <field name="oid">default</field> </shadow> <block type="variables_get" id="`Lz~|X+Iot=FO~.gMZKJ"> <field name="VAR" id="_j)6Z@}6(~kf)Ga.R^[o">Liste1</field> </block> </value> <statement name="STATEMENT"> <block type="variables_set" id="PWLTX7!i8neRy5t[I2e1"> <field name="VAR" id="0iLzxl6zUmhXoRaBx{3r">Meldung</field> <value name="VALUE"> <block type="text_join" id="WTm]h*):M)K/wbWDBLr|"> <mutation items="1"></mutation> <value name="ADD0"> <block type="text" id="2-aGntQW2u`R%9cjh{hD"> <field name="TEXT"></field> </block> </value> </block> </value> <next> <block type="controls_forEach" id="Ruy1LxZtr02;9HrPpNyg"> <field name="VAR" id="!qnLj.@Gz4{,jc:m8Ws/">id</field> <value name="LIST"> <block type="variables_get" id="ZXJoQ8NB`kmnH49-G|Yn"> <field name="VAR" id="_j)6Z@}6(~kf)Ga.R^[o">Liste1</field> </block> </value> <statement name="DO"> <block type="controls_if" id="3!]w:|Vu;[B_*_o]OJ]!"> <value name="IF0"> <block type="logic_compare" id="h_41e`RQ893V!_QB~!le"> <field name="OP">LT</field> <value name="A"> <block type="get_value_var" id="[S*:5$uA]a#0eU0!zuzE"> <field name="ATTR">val</field> <value name="OID"> <shadow type="text" id="6Cola!Z+7.Y7=(7l:_lg"> <field name="TEXT"></field> </shadow> <block type="variables_get" id="TGySr%Y4?O6%Sc$Y*|*z"> <field name="VAR" id="!qnLj.@Gz4{,jc:m8Ws/">id</field> </block> </value> </block> </value> <value name="B"> <block type="get_value" id="AXwMwDEs4WjK?E*%MKBU"> <field name="ATTR">val</field> <field name="OID">0_userdata.0.uebergreifend.system.batterie_warnschwelle</field> </block> </value> </block> </value> <statement name="DO0"> <block type="controls_if" id="GIm(owb-,WKqtSn1rOKH"> <value name="IF0"> <block type="variables_get" id="qH6zT.-dw@xs8b^$G2!P"> <field name="VAR" id="0iLzxl6zUmhXoRaBx{3r">Meldung</field> </block> </value> <statement name="DO0"> <block type="variables_set" id=":@|u]CEsCj[:YV@vMT^("> <field name="VAR" id="0iLzxl6zUmhXoRaBx{3r">Meldung</field> <value name="VALUE"> <block type="text_join" id="ctwL~Y+vgsR=xog14L]r"> <mutation items="2"></mutation> <value name="ADD0"> <block type="variables_get" id="~r@1~?rk{xZET|Z;@9V("> <field name="VAR" id="0iLzxl6zUmhXoRaBx{3r">Meldung</field> </block> </value> <value name="ADD1"> <block type="text" id="=Xa|[n8SU4KRS`.,gi;["> <field name="TEXT">, </field> </block> </value> </block> </value> </block> </statement> <next> <block type="variables_set" id=")Di76}[uF6SuK(waVPEN"> <field name="VAR" id="0iLzxl6zUmhXoRaBx{3r">Meldung</field> <value name="VALUE"> <block type="text_join" id=";3zl3ZM`BpgW-?/,UBN;"> <mutation items="2"></mutation> <value name="ADD0"> <block type="variables_get" id="%Gnjs-8~kYxJa4J}6e]."> <field name="VAR" id="0iLzxl6zUmhXoRaBx{3r">Meldung</field> </block> </value> <value name="ADD1"> <block type="procedures_callcustomreturn" id="/r)OJry7IW$i#lz[N8o}" inline="true"> <mutation name="getName"> <arg name="id"></arg> </mutation> <value name="ARG0"> <block type="variables_get" id="k:y$McnTj_B;%%xNE4+l"> <field name="VAR" id="!qnLj.@Gz4{,jc:m8Ws/">id</field> </block> </value> </block> </value> </block> </value> </block> </next> </block> </statement> </block> </statement> <next> <block type="debug" id="Ki?H:OwmWwGXokw_o{q}"> <field name="Severity">log</field> <value name="TEXT"> <shadow type="text" id="^J.{ut|`tQqUaHd%P!+."> <field name="TEXT">test</field> </shadow> <block type="variables_get" id=":MtBWue|?c]t,N:a@,:i"> <field name="VAR" id="0iLzxl6zUmhXoRaBx{3r">Meldung</field> </block> </value> </block> </next> </block> </next> </block> </statement> </block> </next> </block> <block type="procedures_defcustomreturn" id="2_w:BK~~+qwBw[E@$etF" x="537" y="213"> <mutation statements="false"> <arg name="id" varid="!qnLj.@Gz4{,jc:m8Ws/"></arg> </mutation> <field name="NAME">getName</field> <field name="SCRIPT">cmV0dXJuIGdldE9iamVjdChpZCkuY29tbW9uLm5hbWU7</field> <comment pinned="false" h="80" w="160">Beschreibe diese Funktion …</comment> </block> </xml>
-
@paul53
wow, cool... funktioniert. VIELEN DANK!!!Als Trigger möchte ich einen Crono verwenden, sodass ich nur zu bestimmten Zeiten benachrichtigt werde.
-
@stefan1234 sagte in Frage zu Schleifen und Listen:
Die Funktion IDs vom Selektor funktioniert aber bei Listen nicht, habe ich gelesen.
Da hast du falsch gelesen.
Der Baustein
IDs vom Selektor $(...)
gibt eine Liste zurück, wie man mit einem einfachen Skript verifizieren kann (Vorsicht - ich hab das bei einem 'leeren' Testsystem gemacht. der Selektor in dem Beispiel liefert Dir jeden Datenpunkt.):
Das Problem des Namens hat @paul53 in seinem Skript bereits schön gelöst (über die
JS Funktion mit Ergebnis getName
) Du kannst also in seinem Beispiel einfach den Trigger auf Werteänderung umstellen auf einen CRON Trigger.A.