Navigation

    Logo
    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unread
    • Categories
    • Unreplied
    • Popular
    • GitHub
    • Docu
    • Hilfe
    1. Home
    2. Deutsch
    3. Skripten / Logik
    4. Blockly
    5. Blockly - Sub-Objekt Wert ändern

    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

    Blockly - Sub-Objekt Wert ändern

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

      Ich habe gestern meinen ersten Shelly Pro 3 erhalten und - ähnlich wie @Walter-O - baue ich mir gerade ein Skript für die Auswertung und das Schalten (über MQTT / RPC).

      Zum Schalten muss ich einen JSON wie diesen senden:

      {"id":0,"src":"shellies/ShellyPro3-Buero-59/rpc-response","method":"Switch.Set","params":{"id":0,"on":false}}
      

      unter params muss ich die id 0,1 oder 2 wählen, dazu dann on auf true oder false
      src gibt an, an welchem Topic das Ergebnis aka Result vom Shelly gesendet wird.

      Nun dacht ich, ich mache es mir einfach und wandle das JSON in ein Objekt, ändere die Werte und sende es wiederum in ein JSON konvertiert an den entsprechenden MQTT-Datenpunkt.
      Nun ist param ja ein - ich nennen das jetzt mal so - Subobjekt / Unterobjekt.
      Wie mache ich das mit den vorgegebenen Bausteinen?

      6d8e62a7-9293-46c4-99d4-d8384f9eaf01-image.png
      und der Export:

      <xml xmlns="https://developers.google.com/blockly/xml">
        <variables>
          <variable id="1SE|mW%0mMn7R3:V^R1}">MyJSON</variable>
          <variable id="zZO9u;/n=^Ub?PoYZDJf">MyObjekt</variable>
        </variables>
        <block type="variables_set" id="/!PewV:=To515X^%8,YG" x="62" y="62">
          <field name="VAR" id="1SE|mW%0mMn7R3:V^R1}">MyJSON</field>
          <value name="VALUE">
            <block type="text" id="9!l2fKzf=aH521#|S+)1">
              <field name="TEXT">{"id":0,"src":"shellies/ShellyPro3-Buero-59/rpc-response","method":"Switch.Set","params":{"id":0,"on":false}}</field>
            </block>
          </value>
          <next>
            <block type="variables_set" id="9ms?NL|0B21P}(C/Jib7">
              <field name="VAR" id="zZO9u;/n=^Ub?PoYZDJf">MyObjekt</field>
              <value name="VALUE">
                <block type="convert_json2object" id="@qulm)U2$ZJ8Y(G}8]Tq">
                  <value name="VALUE">
                    <block type="text" id="X.#/3yNBs+lkp3AOW$}4">
                      <field name="TEXT">{"id":0,"src":"shellies/ShellyPro3-Buero-59/rpc-response","method":"Switch.Set","params":{"id":0,"on":false}}</field>
                    </block>
                  </value>
                </block>
              </value>
              <next>
                <block type="object_set_attr" id="UZrMs;N{pyDzb[WeRlSO">
                  <field name="ATTR">src</field>
                  <value name="OBJECT">
                    <block type="variables_get" id="CW-dvJi#_{BTr=yiGmBk">
                      <field name="VAR" id="zZO9u;/n=^Ub?PoYZDJf">MyObjekt</field>
                    </block>
                  </value>
                  <value name="VALUE">
                    <shadow type="text" id="L]|A]:gAiw/rf1wnHu8p">
                      <field name="TEXT">NurEinTest</field>
                    </shadow>
                  </value>
                  <next>
                    <block type="debug" id="1V?[]u6!bb*2`S#?Hc,m">
                      <field name="Severity">log</field>
                      <value name="TEXT">
                        <shadow type="text" id="g*4-QP/wF}}.GC:FBPi%">
                          <field name="TEXT">test</field>
                        </shadow>
                        <block type="variables_get" id="$nl[s0Oa!wrbvS-^#o!`">
                          <field name="VAR" id="zZO9u;/n=^Ub?PoYZDJf">MyObjekt</field>
                        </block>
                      </value>
                      <next>
                        <block type="object_set_attr" id="[GTA1boehshefRT}e1S+">
                          <field name="ATTR">params.on</field>
                          <value name="OBJECT">
                            <block type="variables_get" id="f3KMRHJtyE47+*]!P=i!">
                              <field name="VAR" id="zZO9u;/n=^Ub?PoYZDJf">MyObjekt</field>
                            </block>
                          </value>
                          <value name="VALUE">
                            <shadow type="text" id="7[VE~al7}LB8bT%Q2svp">
                              <field name="TEXT">NurEinTest</field>
                            </shadow>
                            <block type="logic_boolean" id="T,~~IRUwio_%:/,p4hx^">
                              <field name="BOOL">TRUE</field>
                            </block>
                          </value>
                          <next>
                            <block type="debug" id="0T3zfR%q3[~VL/)U:E*}">
                              <field name="Severity">log</field>
                              <value name="TEXT">
                                <shadow type="text" id="g*4-QP/wF}}.GC:FBPi%">
                                  <field name="TEXT">test</field>
                                </shadow>
                                <block type="variables_get" id="7l;x({FJuM?_Nw)!]k5b">
                                  <field name="VAR" id="zZO9u;/n=^Ub?PoYZDJf">MyObjekt</field>
                                </block>
                              </value>
                            </block>
                          </next>
                        </block>
                      </next>
                    </block>
                  </next>
                </block>
              </next>
            </block>
          </next>
        </block>
      </xml>
      

      Wie wäre die richtige Schreibweise in dem "Setze Attribut" Block um auf das Sub-Item zuzugreifen? er hängt das nur an:

      2024-03-15 10:21:00.756  - info: javascript.0 (2441614) script.js.Tests.Forum_Test_JSON: {
        id: 0,
        src: 'NurEinTest',
        method: 'Switch.Set',
        params: { id: 0, on: false },
        'params.on': true
      }
      
      
      haus-automatisierung 1 Reply Last reply Reply Quote 0
      • haus-automatisierung
        haus-automatisierung Developer Most Active @BananaJoe last edited by haus-automatisierung

        @bananajoe Screenshot 2024-03-15 at 10.25.08.png

        Der Block ist aktuell nicht so konzipiert, dass man damit beliebige Pfade angeben kann. Alternativ müsstest Du das Objekt erst holen (Attribut params von Objekt), dann ändern und dann wieder setzen.

        BananaJoe 1 Reply Last reply Reply Quote 1
        • BananaJoe
          BananaJoe Most Active @haus-automatisierung last edited by

          @haus-automatisierung Danke, hat sofort geklappt!

          haus-automatisierung 1 Reply Last reply Reply Quote 0
          • haus-automatisierung
            haus-automatisierung Developer Most Active @BananaJoe last edited by

            @bananajoe Warum nutzt Du nicht einfach den Shelly-Adapter? Dort habe ich mir die Gedanken zu den JSON-Payloads ja bereits für Dich gemacht.

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

            Support us

            ioBroker
            Community Adapters
            Donate

            524
            Online

            31.9k
            Users

            80.2k
            Topics

            1.3m
            Posts

            2
            4
            154
            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