Navigation

    Logo
    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unread
    • Categories
    • Unreplied
    • Popular
    • GitHub
    • Docu
    • Hilfe
    1. Home
    2. Deutsch
    3. Skripten / Logik
    4. [Gelöst] Unifi Voucher

    NEWS

    • Neuer Blog: Fotos und Eindrücke aus Solingen

    • ioBroker@Smart Living Forum Solingen, 14.06. - Agenda added

    • ioBroker goes Matter ... Matter Adapter in Stable

    [Gelöst] Unifi Voucher

    This topic has been deleted. Only users with topic management privileges can see it.
    • draexler
      draexler last edited by draexler

      Re: [Gelöst] Unifi Voucher Anzeige

      Hi Zusammen,

      Zur Anzeige in der VIS und versenden des AKTUELLSTEN Unifi Vouchers habe ich folgendes Blockly verwendet:

      <xml xmlns="https://developers.google.com/blockly/xml">
        <block type="comment" id="DqY~)p;?/lTtyq@v+}kY" x="-88" y="113">
          <field name="COMMENT">Voucher anfordern</field>
          <next>
            <block type="on" id="y._b:1L`L;%n0GpjZH%f">
              <field name="OID">0_userdata.0.VIS_Datenpunkte.UNIFI.Gaeste_Voucher_Anfordern</field>
              <field name="CONDITION">any</field>
              <field name="ACK_CONDITION"></field>
              <statement name="STATEMENT">
                <block type="controls_if" id="V5?I$/4`KyxX_^n;Ehvg">
                  <value name="IF0">
                    <block type="logic_compare" id="wiU5a8Zyy!xIDLC_x],y">
                      <field name="OP">EQ</field>
                      <value name="A">
                        <block type="get_value" id="76]etI(v^d*S1A{;Ku.N">
                          <field name="ATTR">val</field>
                          <field name="OID">0_userdata.0.Anwesenheitssteuerung.Gästeanwesenheit</field>
                        </block>
                      </value>
                      <value name="B">
                        <block type="logic_boolean" id="(b,dHWvKn8@@DgHwny;J">
                          <field name="BOOL">TRUE</field>
                        </block>
                      </value>
                    </block>
                  </value>
                  <statement name="DO0">
                    <block type="control" id="h]Jg*jhbn[/S!-:RN$;a">
                      <mutation xmlns="http://www.w3.org/1999/xhtml" delay_input="false"></mutation>
                      <field name="OID">unifi.0.default.vouchers.create_vouchers</field>
                      <field name="WITH_DELAY">FALSE</field>
                      <value name="VALUE">
                        <block type="logic_boolean" id="BtQU^(D36:+K?2Nmld2$">
                          <field name="BOOL">TRUE</field>
                        </block>
                      </value>
                    </block>
                  </statement>
                </block>
              </statement>
              <next>
                <block type="comment" id="`-2di|F^yFj.n.2j]Q0X">
                  <field name="COMMENT">Voucher Prüfung</field>
                  <next>
                    <block type="schedule" id="]HqNEVPrp%eBbM@k~r+H">
                      <field name="SCHEDULE">*/5 * * * * *</field>
                      <statement name="STATEMENT">
                        <block type="controls_if" id="45ZX~f{_+)P?^)HGBY4P">
                          <mutation elseif="2"></mutation>
                          <value name="IF0">
                            <block type="logic_compare" id="H;R-/TMw(VsUwF3[Op;b">
                              <field name="OP">NEQ</field>
                              <value name="A">
                                <block type="procedures_callcustomreturn" id="IX(jO~K+]D$n`0=vp*fh">
                                  <mutation name="abfrage"></mutation>
                                </block>
                              </value>
                              <value name="B">
                                <block type="math_number" id="7J@U+96^d~`Wi`;Xz5bE">
                                  <field name="NUM">0</field>
                                </block>
                              </value>
                            </block>
                          </value>
                          <statement name="DO0">
                            <block type="update" id="n=5#RjYy}Uf;n:]jxr;J">
                              <mutation xmlns="http://www.w3.org/1999/xhtml" delay_input="false"></mutation>
                              <field name="OID">0_userdata.0.VIS_Datenpunkte.UNIFI.Gaeste_Voucher_Rohdaten</field>
                              <field name="WITH_DELAY">FALSE</field>
                              <value name="VALUE">
                                <block type="procedures_callcustomreturn" id="Z.[)9rooL~4cj!mE4$/%">
                                  <mutation name="abfrage"></mutation>
                                </block>
                              </value>
                            </block>
                          </statement>
                          <value name="IF1">
                            <block type="logic_compare" id="ag2O4zm?cgakM3H7D(5j">
                              <field name="OP">EQ</field>
                              <value name="A">
                                <block type="get_value" id="ep~72X|r+PU^WzN|hH`9">
                                  <field name="ATTR">val</field>
                                  <field name="OID">0_userdata.0.VIS_Datenpunkte.UNIFI.Voucherueberwachung</field>
                                </block>
                              </value>
                              <value name="B">
                                <block type="math_number" id="z?;RFe(t;7sz0P|L8z=?">
                                  <field name="NUM">0</field>
                                </block>
                              </value>
                            </block>
                          </value>
                          <statement name="DO1">
                            <block type="update" id="WWfap=#y{5@omA2cM,eU">
                              <mutation xmlns="http://www.w3.org/1999/xhtml" delay_input="false"></mutation>
                              <field name="OID">0_userdata.0.VIS_Datenpunkte.UNIFI.Gaeste_Voucher_Rohdaten</field>
                              <field name="WITH_DELAY">FALSE</field>
                              <value name="VALUE">
                                <block type="text" id="`[VhTIV7K#:{l??Y0*.v">
                                  <field name="TEXT">NULL</field>
                                </block>
                              </value>
                            </block>
                          </statement>
                          <value name="IF2">
                            <block type="logic_compare" id="T=3aA;s0BhL|8JsQWHqW">
                              <field name="OP">EQ</field>
                              <value name="A">
                                <block type="procedures_callcustomreturn" id="#H(0~_/+A^(T!zs(AA:Q">
                                  <mutation name="abfrage"></mutation>
                                </block>
                              </value>
                              <value name="B">
                                <block type="math_number" id="h)mKLwP#tdJV/mF4Fnt=">
                                  <field name="NUM">0</field>
                                </block>
                              </value>
                            </block>
                          </value>
                        </block>
                      </statement>
                      <next>
                        <block type="comment" id="hfVvq]5R2GO#tD%]Pt|G">
                          <field name="COMMENT">Voucher Aufbereitung</field>
                          <next>
                            <block type="on" id="uA-2ocH$(-~}|#9))(gL">
                              <field name="OID">0_userdata.0.VIS_Datenpunkte.UNIFI.Gaeste_Voucher_Rohdaten</field>
                              <field name="CONDITION">any</field>
                              <field name="ACK_CONDITION"></field>
                              <statement name="STATEMENT">
                                <block type="controls_if" id="tt5(7E7PfGS$ex=Vx}0j">
                                  <mutation elseif="2"></mutation>
                                  <value name="IF0">
                                    <block type="logic_operation" id="KAgLEFW9n@1jh7(WTlMK">
                                      <field name="OP">AND</field>
                                      <value name="A">
                                        <block type="logic_compare" id="-`m)UT0I{oS$6Aqq.ne}">
                                          <field name="OP">EQ</field>
                                          <value name="A">
                                            <block type="get_value" id="8)]s?,zSbCeKEmNJZ[c,">
                                              <field name="ATTR">val</field>
                                              <field name="OID">0_userdata.0.VIS_Datenpunkte.UNIFI.Gaeste_Voucher_Rohdaten</field>
                                            </block>
                                          </value>
                                          <value name="B">
                                            <block type="text" id="V6MD!+iEP/-y5xveOu5W">
                                              <field name="TEXT">NULL</field>
                                            </block>
                                          </value>
                                        </block>
                                      </value>
                                      <value name="B">
                                        <block type="logic_compare" id="tteCk=h,RUBc]~:{3bXz">
                                          <field name="OP">EQ</field>
                                          <value name="A">
                                            <block type="get_value" id="*hu@WN=)7IT$,;?]:rRh">
                                              <field name="ATTR">val</field>
                                              <field name="OID">alias.0.Netzwerk.WLAN.Gaeste-WLAN.GästeWLAN</field>
                                            </block>
                                          </value>
                                          <value name="B">
                                            <block type="logic_boolean" id="g!hl$+wk(tn[J`G56REo">
                                              <field name="BOOL">TRUE</field>
                                            </block>
                                          </value>
                                        </block>
                                      </value>
                                    </block>
                                  </value>
                                  <statement name="DO0">
                                    <block type="update" id="^|qf0Xjj.3m:h4(2@Eh+">
                                      <mutation xmlns="http://www.w3.org/1999/xhtml" delay_input="false"></mutation>
                                      <field name="OID">0_userdata.0.VIS_Datenpunkte.UNIFI.Gaeste_Voucher_Text</field>
                                      <field name="WITH_DELAY">FALSE</field>
                                      <value name="VALUE">
                                        <block type="text" id="l$ObO~*RpUGH/T|:(Z;1">
                                          <field name="TEXT">PUSH</field>
                                        </block>
                                      </value>
                                    </block>
                                  </statement>
                                  <value name="IF1">
                                    <block type="logic_operation" id="/ZL8)VH~oI]pP+B~4y:2">
                                      <field name="OP">AND</field>
                                      <value name="A">
                                        <block type="logic_compare" id="j1~C6W$M!a0cjo1m#sXt">
                                          <field name="OP">EQ</field>
                                          <value name="A">
                                            <block type="get_value" id="e(K^KhcDs:^MkQunpzu$">
                                              <field name="ATTR">val</field>
                                              <field name="OID">0_userdata.0.VIS_Datenpunkte.UNIFI.Gaeste_Voucher_Rohdaten</field>
                                            </block>
                                          </value>
                                          <value name="B">
                                            <block type="text" id="3RQQ^6lv4%`0^Or*/bFm">
                                              <field name="TEXT">NULL</field>
                                            </block>
                                          </value>
                                        </block>
                                      </value>
                                      <value name="B">
                                        <block type="logic_compare" id="FHPJ-G_lUa^ckaw=Yz2[">
                                          <field name="OP">EQ</field>
                                          <value name="A">
                                            <block type="get_value" id="^uoqNGJ^)ZC{Hz0Bvta=">
                                              <field name="ATTR">val</field>
                                              <field name="OID">alias.0.Netzwerk.WLAN.Gaeste-WLAN.GästeWLAN</field>
                                            </block>
                                          </value>
                                          <value name="B">
                                            <block type="logic_boolean" id="wsV6#K;Ft^D(fbQq8uUG">
                                              <field name="BOOL">FALSE</field>
                                            </block>
                                          </value>
                                        </block>
                                      </value>
                                    </block>
                                  </value>
                                  <statement name="DO1">
                                    <block type="update" id="}#B/FA^rJMeM(JJJsQ*H">
                                      <mutation xmlns="http://www.w3.org/1999/xhtml" delay_input="false"></mutation>
                                      <field name="OID">0_userdata.0.VIS_Datenpunkte.UNIFI.Gaeste_Voucher_Text</field>
                                      <field name="WITH_DELAY">FALSE</field>
                                      <value name="VALUE">
                                        <block type="text" id="$HiBZ/R*Bnue}8TkmNtp">
                                          <field name="TEXT">DEAKTIVIERT</field>
                                        </block>
                                      </value>
                                    </block>
                                  </statement>
                                  <value name="IF2">
                                    <block type="logic_compare" id="+8Hqd;6T`9:^8BF($t|@">
                                      <field name="OP">NEQ</field>
                                      <value name="A">
                                        <block type="get_value" id="K:I`Y7+?cQZe7!^)/Ap?">
                                          <field name="ATTR">val</field>
                                          <field name="OID">0_userdata.0.VIS_Datenpunkte.UNIFI.Gaeste_Voucher_Rohdaten</field>
                                        </block>
                                      </value>
                                      <value name="B">
                                        <block type="text" id=":k7U5A%96#CG6Dul7o/=">
                                          <field name="TEXT">NULL</field>
                                        </block>
                                      </value>
                                    </block>
                                  </value>
                                  <statement name="DO2">
                                    <block type="update" id=":.1Y-ldY.Bw%=xOWpUw`">
                                      <mutation xmlns="http://www.w3.org/1999/xhtml" delay_input="false"></mutation>
                                      <field name="OID">0_userdata.0.VIS_Datenpunkte.UNIFI.Gaeste_Voucher_Text</field>
                                      <field name="WITH_DELAY">FALSE</field>
                                      <value name="VALUE">
                                        <block type="text_join" id="Wmylzz,WMg(+|Th#?*Zn">
                                          <mutation items="3"></mutation>
                                          <value name="ADD0">
                                            <block type="text_getSubstring" id=")SbpJ=ZC]`YRBPqL0q0@">
                                              <mutation at1="true" at2="true"></mutation>
                                              <field name="WHERE1">FROM_START</field>
                                              <field name="WHERE2">FROM_START</field>
                                              <value name="STRING">
                                                <block type="get_value" id="VM91^k42+O^J+adOhI~~">
                                                  <field name="ATTR">val</field>
                                                  <field name="OID">0_userdata.0.VIS_Datenpunkte.UNIFI.Gaeste_Voucher_Rohdaten</field>
                                                </block>
                                              </value>
                                              <value name="AT1">
                                                <block type="math_number" id="g@tay]OdUj7o`%.L{8qO">
                                                  <field name="NUM">34</field>
                                                </block>
                                              </value>
                                              <value name="AT2">
                                                <block type="math_number" id="]:Ikjm*^I[*+K#}C|eGG">
                                                  <field name="NUM">38</field>
                                                </block>
                                              </value>
                                            </block>
                                          </value>
                                          <value name="ADD1">
                                            <block type="text" id="Qiy`.R-V:^FJ/XBIy:nQ">
                                              <field name="TEXT">-</field>
                                            </block>
                                          </value>
                                          <value name="ADD2">
                                            <block type="text_getSubstring" id="@VsZ.M8V`(V%(WU-2f4G">
                                              <mutation at1="true" at2="true"></mutation>
                                              <field name="WHERE1">FROM_START</field>
                                              <field name="WHERE2">FROM_START</field>
                                              <value name="STRING">
                                                <block type="get_value" id="z]$1mj[%fXFYLHzG:!HY">
                                                  <field name="ATTR">val</field>
                                                  <field name="OID">0_userdata.0.VIS_Datenpunkte.UNIFI.Gaeste_Voucher_Rohdaten</field>
                                                </block>
                                              </value>
                                              <value name="AT1">
                                                <block type="math_number" id="qg!$WvwLcH@H;Vo|nAP}">
                                                  <field name="NUM">39</field>
                                                </block>
                                              </value>
                                              <value name="AT2">
                                                <block type="math_number" id="$W9{Km-|#LLRd$/gdSUU">
                                                  <field name="NUM">43</field>
                                                </block>
                                              </value>
                                            </block>
                                          </value>
                                        </block>
                                      </value>
                                      <next>
                                        <block type="pushover" id="g81z{n`Ax;`]D#/T8fNr">
                                          <field name="INSTANCE">.1</field>
                                          <field name="SOUND"></field>
                                          <field name="PRIORITY">0</field>
                                          <field name="LOG"></field>
                                          <value name="MESSAGE">
                                            <shadow type="text" id=")uMyM`cIJw@Lg]qDP`^d">
                                              <field name="TEXT">text</field>
                                            </shadow>
                                            <block type="text_join" id="(i]2z~o~jp|C!kck4)z+">
                                              <mutation items="9"></mutation>
                                              <value name="ADD0">
                                                <block type="text" id="g+i0M|hx6]`u^s+~nl{`">
                                                  <field name="TEXT">Der Gäste WLAN Voucher lautet:</field>
                                                </block>
                                              </value>
                                              <value name="ADD1">
                                                <block type="text_newline" id="HUFK%`Z9k/B!F]N1=Zzk">
                                                  <field name="Type">\n</field>
                                                </block>
                                              </value>
                                              <value name="ADD2">
                                                <block type="text_newline" id="da_VBU6+I9~7mR]IY*k@">
                                                  <field name="Type">\n</field>
                                                </block>
                                              </value>
                                              <value name="ADD3">
                                                <block type="text_getSubstring" id="qqt])D}z=KmUInmg[@kv">
                                                  <mutation at1="true" at2="true"></mutation>
                                                  <field name="WHERE1">FROM_START</field>
                                                  <field name="WHERE2">FROM_START</field>
                                                  <value name="STRING">
                                                    <block type="get_value" id="@WGOh:+~FW1j5)z!z)F-">
                                                      <field name="ATTR">val</field>
                                                      <field name="OID">0_userdata.0.VIS_Datenpunkte.UNIFI.Gaeste_Voucher_Rohdaten</field>
                                                    </block>
                                                  </value>
                                                  <value name="AT1">
                                                    <block type="math_number" id="^.#qfn/P_!,C*Xq043]*">
                                                      <field name="NUM">34</field>
                                                    </block>
                                                  </value>
                                                  <value name="AT2">
                                                    <block type="math_number" id="NxW(/#g:$vf,CwhogA#|">
                                                      <field name="NUM">38</field>
                                                    </block>
                                                  </value>
                                                </block>
                                              </value>
                                              <value name="ADD4">
                                                <block type="text" id="f0f?%E-jU~,q])UozY8i">
                                                  <field name="TEXT">-</field>
                                                </block>
                                              </value>
                                              <value name="ADD5">
                                                <block type="text_getSubstring" id="d%L@9U0q-DUo(%zy(F1S">
                                                  <mutation at1="true" at2="true"></mutation>
                                                  <field name="WHERE1">FROM_START</field>
                                                  <field name="WHERE2">FROM_START</field>
                                                  <value name="STRING">
                                                    <block type="get_value" id="1sOqumB[NtUTBwbhb*t9">
                                                      <field name="ATTR">val</field>
                                                      <field name="OID">0_userdata.0.VIS_Datenpunkte.UNIFI.Gaeste_Voucher_Rohdaten</field>
                                                    </block>
                                                  </value>
                                                  <value name="AT1">
                                                    <block type="math_number" id="GA[OYxzL%-bzZ1U[1.YL">
                                                      <field name="NUM">39</field>
                                                    </block>
                                                  </value>
                                                  <value name="AT2">
                                                    <block type="math_number" id="}0,?Z[*Yy`#*OVPt%_8}">
                                                      <field name="NUM">43</field>
                                                    </block>
                                                  </value>
                                                </block>
                                              </value>
                                              <value name="ADD6">
                                                <block type="text_newline" id="c5)LG%{#_-E#[p_a9N]d">
                                                  <field name="Type">\n</field>
                                                </block>
                                              </value>
                                              <value name="ADD7">
                                                <block type="text_newline" id="QW6.6ARc?n8;Xo41dM:T">
                                                  <field name="Type">\n</field>
                                                </block>
                                              </value>
                                              <value name="ADD8">
                                                <block type="text" id="TWU~NYQQa!.Yds}5(WQV">
                                                  <field name="TEXT">Viel Spaß 🖥️</field>
                                                </block>
                                              </value>
                                            </block>
                                          </value>
                                          <value name="TITLE">
                                            <block type="text" id="8/?`8dgUzc`}fwf[h.-x">
                                              <field name="TEXT">Gäste WLAN Voucher</field>
                                            </block>
                                          </value>
                                        </block>
                                      </next>
                                    </block>
                                  </statement>
                                </block>
                              </statement>
                            </block>
                          </next>
                        </block>
                      </next>
                    </block>
                  </next>
                </block>
              </next>
            </block>
          </next>
        </block>
        <block type="procedures_defcustomreturn" id="5n~Iiupl2*1_L7rk?4xW" x="288" y="413">
          <mutation statements="false"></mutation>
          <field name="NAME">abfrage</field>
          <field name="SCRIPT">ICBjb25zdCBkcFByZWZpeCA9ICIwX3VzZXJkYXRhLjAuVklTX0RhdGVucHVua3RlLiI7DQogIGxldCBhcnJUcmlnZ2VyPVtdOw0KICBsZXQgY291bnQ9MA0KDQogbGV0IGFsdGVyV2VydD1nZXRTdGF0ZShkcFByZWZpeCsiVU5JRkkuVm91Y2hlcnVlYmVyd2FjaHVuZyIpLnZhbA0KICAkKCd1bmlmaS4wLmRlZmF1bHQudm91Y2hlcnMuKi5jcmVhdGVfdGltZScpLmVhY2goZnVuY3Rpb24oaWQsIGkpIHsNCiAgICAgIGlmKCFpZC5pbmNsdWRlcygidm91Y2hlcl8uY3JlYXRlIikpeyAgDQogICAgICAgIGNvdW50KysgIA0KDQogICAgICBsZXQgZXJzdGVsbHQ9Z2V0U3RhdGUoaWQpLnZhbA0KICAgICBhcnJUcmlnZ2VyLnB1c2goW25ldyBEYXRlKGVyc3RlbGx0KS5nZXRUaW1lKCksaWRdKQ0KDQogIH0NCiAgICAgICAgfSk7DQogICAgDQogICAgICAgIHNldFN0YXRlKGRwUHJlZml4KyJVTklGSS5Wb3VjaGVydWViZXJ3YWNodW5nIixjb3VudCkNCg0KDQphcnJUcmlnZ2VyLnNvcnQoZnVuY3Rpb24gKGFscGhhLCBiZXRhKSB7DQogICAgICAgICAgICAgDQogICAgICAgICAgICAgIHJldHVybiAgYmV0YVswXS0gYWxwaGFbMF07DQogICAgICAgICAgICAgfSk7DQogICAgICAgICAgICAgDQogICAgaWYgKCBhbHRlcldlcnQ8Y291bnQpICB7cmV0dXJuIGFyclRyaWdnZXJbMF1bMV07ICAgfSBlbHNlICB7IHJldHVybiAiMCI7fSAgIA0KICAgIGFsdGVyV2VydD1jb3VudCAgDQogICAgICAgICAgICAgDQo=</field>
          <comment pinned="false" h="80" w="160">Beschreibe diese Funktion …</comment>
        </block>
      </xml>
      

      Die JS Funktion sieht wie folgt aus:

        const dpPrefix = "0_userdata.0.VIS_Datenpunkte.";
        let arrTrigger=[];
        let count=0
      
       let alterWert=getState(dpPrefix+"UNIFI.Voucherueberwachung").val
        $('unifi.0.default.vouchers.*.create_time').each(function(id, i) {
            if(!id.includes("voucher_.create")){  
              count++  
      
            let erstellt=getState(id).val
           arrTrigger.push([new Date(erstellt).getTime(),id])
      
        }
              });
          
              setState(dpPrefix+"UNIFI.Voucherueberwachung",count)
      
      
      arrTrigger.sort(function (alpha, beta) {
                   
                    return  beta[0]- alpha[0];
                   });
                   
          if ( alterWert<count)  {return arrTrigger[0][1];   } else  { return "0";}   
          alterWert=count  
                   
      
      

      Die Struktur des gelieferten Vouchers sieht so aus:

      Bildschirmfoto 2022-08-10 um 15.55.41.png

      Ich habe jetzt das Problem das mir in den Datenpunkt "Gaeste_Voucher_Rohdaten" nur noch die "0" geliefert wird.

      Bildschirmfoto 2022-08-10 um 17.20.20.png

      Hat von euch jemand eine Idee woran das liegen kann?

      draexler 1 Reply Last reply Reply Quote 0
      • draexler
        draexler @draexler last edited by draexler

        Kann es eventuell daran liegen das der Datenpunkt "Create Time" eine Zeichenkette ist?

        @liv-in-sky Kannst du mal schauen? Die Abfrage war mal von dir. Wäre super nett 😊

        liv-in-sky 1 Reply Last reply Reply Quote 0
        • liv-in-sky
          liv-in-sky @draexler last edited by

          @draexler

          kann es sein, dass du alle vouchers gelöscht hast und neue angelegt hast - dann könnte evtl der selektor keine dp finden - wenn du die javascript instanz neu startest, würde das wieder funktionieren - probier mal

          der selektor zählt die dp - dem ist es egal, ob es ein string oder boolean oder sonstiger dp ist

          ich habe mal nur die function getestet - die macht ihren job - dazu überschreibe ich in der function den "alterWert" in zeile 5 mit einem wert, der kleiner als die aktuelle anzahl der vouchers ist - oder ich nehme die gleiche anzahl (ergebnis = 0) - siehe bild

          Image 012.png

          zum testen könntest du mal den dp voucherueberwachung auf 0 setzen

          draexler 1 Reply Last reply Reply Quote 1
          • draexler
            draexler @liv-in-sky last edited by

            @liv-in-sky Schon mal Danke für deine Hilfe 😊

            Also der Counter funktioniert wunderbar. Keine Voucher = 0; 1 Voucher = 1; usw.
            Der zählt wunderbar rauf und runter.
            Was nicht geht is das wenn ein Voucher vorhanden ist der Datenpunkt Name mit dem Vouchercode in den Datenpunkt Rohdaten geschrieben wird.

            Ich habe bereits die Instanz neu gestartet, das Script gelöscht, den Raspi samz ioBroker neugestartet. Funzt aber nicht mehr 😥

            liv-in-sky 1 Reply Last reply Reply Quote 0
            • liv-in-sky
              liv-in-sky @draexler last edited by

              @draexler

              siehe mal im chat

              ansonsten: in der function wird der voucher code selbst nicht abgefragt - nur die id des datenpunktes und das erstelldatum - könnte man aber dazufügen

              soweit ich das erkenne, wird im unterem blockly der dp rohdaten zerlegt - darin ist aber, wie erwähnt, der vouchercode nicht enthalten - den müßtest du extra ergänzen in der function

              Image 014.png

              beim zerlegen des return-wertes, also den rohdaten würde ich dann eine liste erzeugen und darin das 2te element nehmen - ungfähr so:

              Image 015.png

              das sollte dann der voucher code sein !!!

              das erste element ist die id (namen) des vouchers

              draexler 1 Reply Last reply Reply Quote 1
              • draexler
                draexler @liv-in-sky last edited by draexler

                @liv-in-sky Wegen Chat...Komme ich gerne darauf zurück, bin nur die ganze Zeit sehr sporadisch vor dem Bildschirm.

                Ich bin jetzt auf jeden Fall einen Schritt weiter.
                Aber... Lasse ich ein einfaches Debug Log laufen sehe ich in dem Logs wunderbar das die Voucherdaten geliefert werden.
                Bildschirmfoto 2022-08-13 um 15.06.48.png
                Bildschirmfoto 2022-08-13 um 15.08.36.png
                Wobei ich mich frage sollte dann eigentlich dann nicht mehr die "0" geliefert werden solange ein Voucher existiert?

                Wenn ich jetzt aber diesen Wert mit diesen Blockly weiterverarbeiten will:
                Bildschirmfoto 2022-08-13 um 15.12.32.png
                wird in den „Rohdaten“ Datenpunkt immer nur die "0" geschrieben (sollte es tatsächlich die 0 sein, schreibt es wie gewünscht "NULL"

                Bildschirmfoto 2022-08-13 um 15.09.34.png

                liv-in-sky 1 Reply Last reply Reply Quote 0
                • liv-in-sky
                  liv-in-sky @draexler last edited by

                  @draexler weiß nicht, ob ich das alles richtig verstehe

                  entweder stimmt die falls abfrage nicht und es kommt immer "0" zurück

                  falls wert von UNIFI.Voucherueberwachung = 0 kannste mal auf = "0" - also einen string vergleichen, nicht eine zahl - evtl ist da was falsch

                  draexler 1 Reply Last reply Reply Quote 1
                  • draexler
                    draexler @liv-in-sky last edited by

                    @liv-in-sky sorry wenn es kompliziert ist.

                    Also ich will das in den „Rohdaten“ Datenpunkt der Return Wert deines „Abfrage“
                    scripts eingetragen wird.
                    Aber mein Blockly trägt immer „0“ ein. Außer der Return Wert deines „Abfrage“
                    Scripts ist „0“ dann schreibt er „NULL“ gemäß des Blocklys.

                    Ich hoffe das war verständlicher 😊

                    liv-in-sky 1 Reply Last reply Reply Quote 0
                    • liv-in-sky
                      liv-in-sky @draexler last edited by

                      @draexler ich glaube, das habe ich soweit verstanden - daher die falls abfrage ändern. die function gibt immer einen string zurück, du fragst aber eine zahl in der 2ten if abfrage ab- daher meine idee, dass mal zu ändern

                      draexler 1 Reply Last reply Reply Quote 1
                      • draexler
                        draexler @liv-in-sky last edited by

                        @liv-in-sky Sicher das immer ein String zurückgeliefert wird?
                        Ich habe den Datenpunkt mal auf Zahl geändert und habe nun das im Log:

                        State value to set for "0_userdata.0.VIS_Datenpunkte.UNIFI.Voucherueberwachung" has to be type "string" but received type "number"
                        
                        liv-in-sky 1 Reply Last reply Reply Quote 0
                        • liv-in-sky
                          liv-in-sky @draexler last edited by

                          @draexler ok - das sollte dann schon stimmen - habe ich mich geirrt

                          draexler 1 Reply Last reply Reply Quote 1
                          • draexler
                            draexler @liv-in-sky last edited by draexler

                            @liv-in-sky Habe jetzt mal wieder ein bisschen getestet. Aber keine Chance. Er schreibt mir immer wieder nur die "0" als Return Wert.

                            Ich habe jetzt mal unter dem Blockly ein Debug Output eingebaut:
                            Bildschirmfoto 2022-08-14 um 00.47.00.png

                            Man sieht also das das wenn der Return Wert der "Abfrage" ungleich "0" er die korrekte if Abfrage nimmt. Er schreibt aber trotzdem nur eine "0" ins Log.

                            Bildschirmfoto 2022-08-14 um 00.52.01.png

                            Lasse ich wie schon mal geschrieben vollkommen losgelöst einen Debug Output Trigger lassen schreibt er den gewünschten Wert
                            Bildschirmfoto 2022-08-14 um 00.58.15.png Bildschirmfoto 2022-08-14 um 00.57.22.png

                            Ich bin ratlos....

                            Hier nochmal das Abfrage Skript:

                              const dpPrefix = "0_userdata.0.VIS_Datenpunkte.";
                              let arrTrigger=[];
                              let count=0
                            
                             let alterWert=getState(dpPrefix+"UNIFI.Voucherueberwachung").val
                              $('unifi.0.default.vouchers.*.create_time').each(function(id, i) {
                                  if(!id.includes("voucher_.create")){  
                                    count++  
                            
                                  let erstellt=getState(id).val
                                 arrTrigger.push([new Date(erstellt).getTime(),id,getState(id.replace("create_time","code")).val])
                            
                              }
                                    });
                                
                                    setState(dpPrefix+"UNIFI.Voucherueberwachung",count)
                            
                            
                            arrTrigger.sort(function (alpha, beta) {
                                         
                                          return  beta[0]- alpha[0];
                                         });
                                         
                                if  (alterWert<count) {return arrTrigger[0][1]+","+arrTrigger[0][2]; } else { return "0";} 
                                alterWert=count  
                            

                            Vielleicht ist hier ja doch ein Fehler drin 😞

                            liv-in-sky 1 Reply Last reply Reply Quote 0
                            • liv-in-sky
                              liv-in-sky @draexler last edited by liv-in-sky

                              @draexler
                              du rufst die function öfter mal in einem if block auf - versuche mal eine neue variable zu erstellen und rufe dort die function auf - im if-block nutzt du dann die neue variable, anstatt immer wieder die function aufzurufen.

                              die function setzt bei einmaligen durchlaufen einen wert und merkt sich den für den nächstan aufruf - das könnte evtl das seltsame verhalten zeigen

                              hier ein beispiel:
                              Image 018.png

                              draexler 1 Reply Last reply Reply Quote 1
                              • draexler
                                draexler @liv-in-sky last edited by

                                @liv-in-sky Das war es! Super Danke dir 🙂

                                Jetzt bastel ich mal weiter.

                                liv-in-sky 1 Reply Last reply Reply Quote 0
                                • liv-in-sky
                                  liv-in-sky @draexler last edited by

                                  @draexler dann noch viel spaß beim "coden"

                                  1 Reply Last reply Reply Quote 1
                                  • First post
                                    Last post

                                  Support us

                                  ioBroker
                                  Community Adapters
                                  Donate

                                  961
                                  Online

                                  31.9k
                                  Users

                                  80.1k
                                  Topics

                                  1.3m
                                  Posts

                                  2
                                  15
                                  463
                                  Loading More Posts
                                  • Oldest to Newest
                                  • Newest to Oldest
                                  • Most Votes
                                  Reply
                                  • Reply as topic
                                  Log in to reply
                                  Community
                                  Impressum | Datenschutz-Bestimmungen | Nutzungsbedingungen
                                  The ioBroker Community 2014-2023
                                  logo