[Blockly] Licht via Timer oder Dauer ON

  • Beschreibung:

    • Zielsetzung:
      da des Öfteren vergessen wird das Licht in den Keller abzudrehen, habe ich das über ein kleines Script erledigt. Allerdings soll es weiterhin die Möglichkeit geben es auf Dauer zu schalten (3 malige Stellungsänderung von der Wippe), was unter anderem noch ein visuelles Feedback liefert, indem Licht nochmal kurz aus und an geht zur Bestätigung.
    • verwendete Adapter:
      shelly
    • Objekte:
      • Input
      • Switch

    Bildschirmfoto:

    Unbenannt.PNG

    Publizierung:

    Blockly Export

    <xml xmlns="https://developers.google.com/blockly/xml">

    <variables>

    <variable id="p*-$t3f@~7*C#1ac#@]O">cnt</variable>

    <variable type="timeout" id="timeout">timeout</variable>

    <variable type="timeout" id="timeout3">timeout3</variable>

    <variable type="timeout" id="timeout2">timeout2</variable>

    </variables>

    <block type="on_ext" id=",|?d=e^/)aLNka/4i~.C" x="1067" y="1110">

    <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 xmlns="http://www.w3.org/1999/xhtml" type="field_oid" id="$pb_Q;EQV#xYAfrzLZ17">

    <field name="oid">default</field>

    </shadow>

    <block type="field_oid" id=")P52FE0%`HJTm$s8j*.I">

    <field name="oid">shelly.0.SHSW-1#C49979#1.Relay0.Input</field>

    </block>

    </value>

    <statement name="STATEMENT">

    <block type="math_change" id="t@ESvQCb5{q/Xf_d@.?(">

    <field name="VAR" id="p*-$t3f@~7*C#1ac#@]O">cnt</field>

    <value name="DELTA">

    <shadow type="math_number" id="Iz|a(Nh5Ii+.,]lngmqK">

    <field name="NUM">1</field>

    </shadow>

    </value>

    <next>

    <block type="debug" id="~1Q)H1m1jeS@|;Z#V$DX">

    <field name="Severity">warn</field>

    <value name="TEXT">

    <shadow xmlns="http://www.w3.org/1999/xhtml" type="text" id="dQ|eubZfsTKTiBuJB*jg">

    <field name="TEXT">test</field>

    </shadow>

    <block type="variables_get" id="YS}o{(WHLj;3mY~!1sk:">

    <field name="VAR" id="p*-$t3f@~7*C#1ac#@]O">cnt</field>

    </block>

    </value>

    <next>

    <block type="controls_if" id="PJ./cB1b(nfuZmWwb0;a">

    <mutation elseif="2"></mutation>

    <value name="IF0">

    <block type="logic_compare" id="5*|Hq.3Vgq_[rSWET54b" inline="false">

    <field name="OP">EQ</field>

    <value name="A">

    <block type="variables_get" id="[@G-w$u5EdWV-Y_p2:7d">

    <field name="VAR" id="p*-$t3f@~7*C#1ac#@]O">cnt</field>

    </block>

    </value>

    <value name="B">

    <block type="math_number" id="+F1LB[}2!WSoIEb^uSVs">

    <field name="NUM">1</field>

    </block>

    </value>

    </block>

    </value>

    <statement name="DO0">

    <block type="timeouts_settimeout" id="qU3E+m0`crr2|#P_tZBm">

    <field name="NAME">timeout</field>

    <field name="DELAY">2000</field>

    <field name="UNIT">ms</field>

    <statement name="STATEMENT">

    <block type="variables_set" id="i,x^WBgz[2]%Lwe~2(,m">

    <field name="VAR" id="p*-$t3f@~7*C#1ac#@]O">cnt</field>

    <value name="VALUE">

    <block type="math_number" id="h^up02eM7sYFFRfrS`F4">

    <field name="NUM">0</field>

    </block>

    </value>

    <next>

    <block type="timeouts_settimeout" id="9=52h){v~7nkDUQHx`x#">

    <field name="NAME">timeout3</field>

    <field name="DELAY">3</field>

    <field name="UNIT">min</field>

    <statement name="STATEMENT">

    <block type="control" id="8b_2m-Ik3fA7x:D92%sg">

    <mutation xmlns="http://www.w3.org/1999/xhtml" delay_input="false"></mutation>

    <field name="OID">shelly.0.SHSW-1#C49979#1.Relay0.Switch</field>

    <field name="WITH_DELAY">FALSE</field>

    <value name="VALUE">

    <block type="logic_boolean" id="}2(|jPq:rgt#}u)3?Cnb">

    <field name="BOOL">FALSE</field>

    </block>

    </value>

    </block>

    </statement>

    </block>

    </next>

    </block>

    </statement>

    </block>

    </statement>

    <value name="IF1">

    <block type="logic_compare" id="7J[jeZYGjM0J~4`ccN2~" inline="false">

    <field name="OP">EQ</field>

    <value name="A">

    <block type="variables_get" id="Tu+|jI{4WUZMS:*L4Yi5">

    <field name="VAR" id="p*-$t3f@~7*C#1ac#@]O">cnt</field>

    </block>

    </value>

    <value name="B">

    <block type="math_number" id="rw/vk#jLI-M:_1`U[^t!">

    <field name="NUM">2</field>

    </block>

    </value>

    </block>

    </value>

    <statement name="DO1">

    <block type="timeouts_cleartimeout" id="T%$FEfY;5x-Z~KkG?PP$">

    <field name="NAME">timeout</field>

    <next>

    <block type="timeouts_cleartimeout" id="lhN`[RpCFYfn%bmWDn-v">

    <field name="NAME">timeout3</field>

    <next>

    <block type="timeouts_settimeout" id=",QGPb*]a6K5I./@R6me?">

    <field name="NAME">timeout2</field>

    <field name="DELAY">2000</field>

    <field name="UNIT">ms</field>

    <statement name="STATEMENT">

    <block type="variables_set" id="?da}6tT(N/xuf8b^JQqc">

    <field name="VAR" id="p*-$t3f@~7*C#1ac#@]O">cnt</field>

    <value name="VALUE">

    <block type="math_number" id="No,3*B1[}n)i8tYG6S9L">

    <field name="NUM">0</field>

    </block>

    </value>

    </block>

    </statement>

    </block>

    </next>

    </block>

    </next>

    </block>

    </statement>

    <value name="IF2">

    <block type="logic_compare" id="AE~sgDY.7+7*NH|7;):}" inline="false">

    <field name="OP">GTE</field>

    <value name="A">

    <block type="variables_get" id="40WITygti?qi*oQ;Lwu.">

    <field name="VAR" id="p*-$t3f@~7*C#1ac#@]O">cnt</field>

    </block>

    </value>

    <value name="B">

    <block type="math_number" id="c!C#,!:(0#t[g)##X^Cv">

    <field name="NUM">3</field>

    </block>

    </value>

    </block>

    </value>

    <statement name="DO2">

    <block type="timeouts_cleartimeout" id="Fb1Vi-Yt%`0z6Urmt*!A">

    <field name="NAME">timeout</field>

    <next>

    <block type="timeouts_cleartimeout" id="Y~_Z7SI32t{.+CA@|FcL">

    <field name="NAME">timeout2</field>

    <next>

    <block type="timeouts_cleartimeout" id="Ge%Q(T6.]OIIE8aqGwrn">

    <field name="NAME">timeout3</field>

    <next>

    <block type="variables_set" id=")*,W%[5R.;]B133AVyJx">

    <field name="VAR" id="p*-$t3f@~7*C#1ac#@]O">cnt</field>

    <value name="VALUE">

    <block type="math_number" id="yve|*/[x-E7tF{;5-qZf">

    <field name="NUM">0</field>

    </block>

    </value>

    <next>

    <block type="timeouts_wait" id="-sI,8hF~Mf4~8@B/Qi/l">

    <field name="DELAY">500</field>

    <field name="UNIT">ms</field>

    <next>

    <block type="control" id="vr(?IruY2J[EimO]$h%K">

    <mutation xmlns="http://www.w3.org/1999/xhtml" delay_input="false"></mutation>

    <field name="OID">shelly.0.SHSW-1#C49979#1.Relay0.Switch</field>

    <field name="WITH_DELAY">FALSE</field>

    <value name="VALUE">

    <block type="logic_boolean" id="xC5[{M,@[}Sq~?.*Kzst">

    <field name="BOOL">FALSE</field>

    </block>

    </value>

    <next>

    <block type="timeouts_wait" id="8VZ08e_9X{q7$wnav1uC">

    <field name="DELAY">500</field>

    <field name="UNIT">ms</field>

    <next>

    <block type="control" id="oR:,q`tei,G*ws*E7_ha">

    <mutation xmlns="http://www.w3.org/1999/xhtml" delay_input="false"></mutation>

    <field name="OID">shelly.0.SHSW-1#C49979#1.Relay0.Switch</field>

    <field name="WITH_DELAY">FALSE</field>

    <value name="VALUE">

    <block type="logic_boolean" id="DOzEe~k08;X;gKRfgZ}?">

    <field name="BOOL">TRUE</field>

    </block>

    </value>

    </block>

    </next>

    </block>

    </next>

    </block>

    </next>

    </block>

    </next>

    </block>

    </next>

    </block>

    </next>

    </block>

    </next>

    </block>

    </statement>

    </block>

    </next>

    </block>

    </next>

    </block>

    </statement>

    </block>

    </xml>

    JavaScript Export

    var cnt, timeout, timeout3, timeout2;

    on({id: 'shelly.0.SHSW-1#C49979#1.Relay0.Input', change: "ne"}, async function (obj) {
      var value = obj.state.val;
      var oldValue = obj.oldState.val;
    cnt = (typeof cnt == 'number' ? cnt : 0) + 1;
    console.warn(cnt);
      if (cnt == 1) {
    timeout = setTimeout(async function () {
    cnt = 0;
    timeout3 = setTimeout(async function () {
    setState("shelly.0.SHSW-1#C49979#1.Relay0.Switch"/*Halbkeller-Licht_Switch*/, false);
    }, 180000);
    }, 2000);
    } else if (cnt == 2) {
    (function () {if (timeout) {clearTimeout(timeout); timeout = null;}})();
    (function () {if (timeout3) {clearTimeout(timeout3); timeout3 = null;}})();
    timeout2 = setTimeout(async function () {
    cnt = 0;
    }, 2000);
    } else if (cnt >= 3) {
    (function () {if (timeout) {clearTimeout(timeout); timeout = null;}})();
    (function () {if (timeout2) {clearTimeout(timeout2); timeout2 = null;}})();
    (function () {if (timeout3) {clearTimeout(timeout3); timeout3 = null;}})();
    cnt = 0;
        await wait(500);
    setState("shelly.0.SHSW-1#C49979#1.Relay0.Switch"/*Halbkeller-Licht_Switch*/, false);
        await wait(500);
    setState("shelly.0.SHSW-1#C49979#1.Relay0.Switch"/*Halbkeller-Licht_Switch*/, true);
    }
    });