Navigation

    Logo
    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unread
    • Categories
    • Unreplied
    • Popular
    • GitHub
    • Docu
    • Hilfe
    1. Home
    2. Deutsch
    3. Skripten / Logik
    4. Blockly
    5. [gelöst] Used invalid characters über Blockly

    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] Used invalid characters über Blockly

    This topic has been deleted. Only users with topic management privileges can see it.
    • haus-automatisierung
      haus-automatisierung Developer Most Active @Codierknecht last edited by haus-automatisierung

      @codierknecht sagte in Used invalid characters über Blockly:

      Vielleicht können die JS-Experten das noch kurz anpassen

      Einfach das global Flag anhängen

      return text.replace(/[^a-zA-Z0-9\.\-\_]+/g, '');
      

      Oder (in deiner Schreibweise)

      const regex = RegExp('[^a-zA-Z0-9\.\-\_]+', 'g');
      

      Generell sollte das aber mit in die Funktion welche die States anlegt. Separat kann man damit ja nicht viel anfangen in diesem Beispiel.

      Codierknecht 2 Replies Last reply Reply Quote 0
      • Codierknecht
        Codierknecht Developer Most Active @haus-automatisierung last edited by

        @haus-automatisierung sagte in Used invalid characters über Blockly:

        Einfach das global Flag anhängen

        Tut's leider nicht - schon probiert 😉

        Holzhammermethode: Schleife 😁

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

          @codierknecht sagte in Used invalid characters über Blockly:

          Tut's leider nicht

          Doch, läuft:

          "a!b§c$d&".replace(/[^a-zA-Z0-9._-]+/g, '')
          

          Wird aber Offtopic langsam 🙂

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

            @haus-automatisierung sagte in Used invalid characters über Blockly:

            Oder (in deiner Schreibweise)

            Jepp - damit geht's.

            @Steffe-S
            Sähe dann so aus:

            let regex = RegExp('[^a-zA-Z0-9\.\-\_]+', 'g');
            return text.replace(regex, '');
            

            8e425cbc-420f-4a32-bcc3-4a772a306b09-image.png
            Wo das am besten reinpasst, überlasse ich Dir 😉

            1 Reply Last reply Reply Quote 0
            • Homoran
              Homoran Global Moderator Administrators @haus-automatisierung last edited by Homoran

              @haus-automatisierung sagte in Used invalid characters über Blockly:

              Wird aber Offtopic langsam

              nicht wirklich!

              Wenn ich das richtig verstanden habe holt das Skript von @Steffe-S das JSON vom Wechselrichter, zerlegt das JSON und baut daraus die Datenpunkte unter 0_userdata.0.
              Jetzt ist da ein 'illegal character' drin.
              Den holt der admin(??) da raus und ersetzt ihn durch _ was zu der Meldung führt.
              In der nächsten Runde ist der vom Skript geplante DP verschwunden und wird wieder angelegt, was jetzt zum Teufelskreis führt.

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

                @homoran sagte in Used invalid characters über Blockly:

                nicht wirklich!

                Ich meinte nur die Kleinigkeiten was die Schreibweise des regulären Ausdrucks angeht. Am Ende musst jetzt nur diese eine Zeile in die Funktion gepackt werden, welche es eh schon in Blockly gibt.

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

                  Quick and dirty (nicht getestet):

                  for (const i in obj) {
                      const value = obj[i];
                      const attr = i.replace(/[^a-zA-Z0-9._-]+/g, '');
                  
                      if (typeof value == 'object') {
                          IObSetState(id + '.' + attr, value);
                      } else {
                          if (existsState(id + '.' + attr)) { // Existing object/ Update
                              if (typeof value === 'string' || value instanceof String) { // String
                                  setState(id + '.' + attr, value, true);
                              } else { // It is a number or date
                                  if ((new Date(value)).getTime() > 0 && Number(value) > 1685000000 && Number(value) < 4100000000) { // Date
                                     setState(id + '.' + attr, value, true);
                                     setState(id + '.' + attr + '_str', formatDate(value, 'TT.MM.JJJJ SS:mm:ss'), true);
                                  } else { // Number
                                     setState(id + '.' + attr, Number(value), true);
                                  }
                              }
                          } else { // New object / Create
                              if (typeof value === 'string' || value instanceof String) { // String
                                  createState(id + '.' + attr, value, false, { type: 'string', read: true, write: true });
                              } else { // It is a number or date
                                  if ((new Date(value)).getTime() > 0 && Number(value) > 1685000000 && Number(value) < 4100000000) { // Date
                                     createState(id + '.' + attr, value, false, { type: 'number', read: true, write: true });
                                     createState(id + '.' + attr + '_str', formatDate(value, 'TT.MM.JJJJ SS:mm:ss'), false, { type: 'string', read: true, write: true }); 
                                  } else { // Number
                                     createState(id + '.' + attr, value, false, { type: 'number', read: true, write: true }); // or type: "mixed"?
                                  }
                              }
                          }
                      }
                  }
                  
                  Steffe.S. 2 Replies Last reply Reply Quote 0
                  • Steffe.S.
                    Steffe.S. last edited by

                    @haus-automatisierung sagte in Used invalid characters über Blockly:

                    Quick and dirty (nicht getestet):

                    for (const i in obj) {
                        const value = obj[i];
                        const attr = i.replace(/[^a-zA-Z0-9._-]+/g, '');
                    
                        if (typeof value == 'object') {
                            IObSetState(id + '.' + attr, value);
                        } else {
                            if (existsState(id + '.' + attr)) { // Existing object/ Update
                                if (typeof value === 'string' || value instanceof String) { // String
                                    setState(id + '.' + attr, value, true);
                                } else { // It is a number or date
                                    if ((new Date(value)).getTime() > 0 && Number(value) > 1685000000 && Number(value) < 4100000000) { // Date
                                       setState(id + '.' + attr, value, true);
                                       setState(id + '.' + attr + '_str', formatDate(value, 'TT.MM.JJJJ SS:mm:ss'), true);
                                    } else { // Number
                                       setState(id + '.' + attr, Number(value), true);
                                    }
                                }
                            } else { // New object / Create
                                if (typeof value === 'string' || value instanceof String) { // String
                                    createState(id + '.' + attr, value, false, { type: 'string', read: true, write: true });
                                } else { // It is a number or date
                                    if ((new Date(value)).getTime() > 0 && Number(value) > 1685000000 && Number(value) < 4100000000) { // Date
                                       createState(id + '.' + attr, value, false, { type: 'number', read: true, write: true });
                                       createState(id + '.' + attr + '_str', formatDate(value, 'TT.MM.JJJJ SS:mm:ss'), false, { type: 'string', read: true, write: true }); 
                                    } else { // Number
                                       createState(id + '.' + attr, value, false, { type: 'number', read: true, write: true }); // or type: "mixed"?
                                    }
                                }
                            }
                        }
                    }
                    

                    wo bzw. wie wird denn das Skript eingebunden?

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

                      @steffe-s sagte in Used invalid characters über Blockly:

                      wo bzw. wie wird denn das Skript eingebunden?

                      Du musst die Funktion IObSetState in deinem Blockly ersetzen.

                      Steffe.S. 1 Reply Last reply Reply Quote 1
                      • Steffe.S.
                        Steffe.S. @haus-automatisierung last edited by

                        @haus-automatisierung sagte in Used invalid characters über Blockly:

                        @steffe-s sagte in Used invalid characters über Blockly:

                        wo bzw. wie wird denn das Skript eingebunden?

                        Du musst die Funktion IObSetState in deinem Blockly ersetzen.

                        ah alles klar, verstehe,

                        ich teste das mal und gebe Euch dann eine Rückmeldung

                        1 Reply Last reply Reply Quote 0
                        • Steffe.S.
                          Steffe.S. @haus-automatisierung last edited by Steffe.S.

                          @haus-automatisierung sagte in Used invalid characters über Blockly:

                          Quick and dirty (nicht getestet):

                          for (const i in obj) {
                              const value = obj[i];
                              const attr = i.replace(/[^a-zA-Z0-9._-]+/g, '');
                          
                              if (typeof value == 'object') {
                                  IObSetState(id + '.' + attr, value);
                              } else {
                                  if (existsState(id + '.' + attr)) { // Existing object/ Update
                                      if (typeof value === 'string' || value instanceof String) { // String
                                          setState(id + '.' + attr, value, true);
                                      } else { // It is a number or date
                                          if ((new Date(value)).getTime() > 0 && Number(value) > 1685000000 && Number(value) < 4100000000) { // Date
                                             setState(id + '.' + attr, value, true);
                                             setState(id + '.' + attr + '_str', formatDate(value, 'TT.MM.JJJJ SS:mm:ss'), true);
                                          } else { // Number
                                             setState(id + '.' + attr, Number(value), true);
                                          }
                                      }
                                  } else { // New object / Create
                                      if (typeof value === 'string' || value instanceof String) { // String
                                          createState(id + '.' + attr, value, false, { type: 'string', read: true, write: true });
                                      } else { // It is a number or date
                                          if ((new Date(value)).getTime() > 0 && Number(value) > 1685000000 && Number(value) < 4100000000) { // Date
                                             createState(id + '.' + attr, value, false, { type: 'number', read: true, write: true });
                                             createState(id + '.' + attr + '_str', formatDate(value, 'TT.MM.JJJJ SS:mm:ss'), false, { type: 'string', read: true, write: true }); 
                                          } else { // Number
                                             createState(id + '.' + attr, value, false, { type: 'number', read: true, write: true }); // or type: "mixed"?
                                          }
                                      }
                                  }
                              }
                          }
                          

                          Würde es funktionieren, wenn ich diese 3 Zeilen in meinem Skript einfach dazuschreibe?

                          for (const i in obj) {
                              const value = obj[i];
                              const attr = i.replace(/[^a-zA-Z0-9._-]+/g, '');
                          

                          Ich kann das Skript nicht kopieren, daher hier das Bild:

                          Screenshot_20240813_141609.jpg

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

                            @steffe-s sagte in Used invalid characters über Blockly:

                            Würde es funktionieren, wenn ich diese 3 Zeilen in meinem Skript einfach dazuschreibe?

                            Nein, natürlich nicht. Weil die dann im Script nicht verwendet werden....

                            1 Reply Last reply Reply Quote 0
                            • Steffe.S.
                              Steffe.S. last edited by

                              Hallo,
                              ich habe mich jetzt für eine, für mich verständliche, "Stupfimethode" entschieden.

                              {
                                  "connection": {
                                      "mqtt_state": "connected",
                                      "prov_state": "configured",
                                      "auth_state": "ok",
                                      "sc_stream": "enabled",
                                      "sc_debug": "disabled"
                                  },
                                  "meters": {
                                      "last_update": 1723541146,
                                      "soc": 100,
                                      "main_relay_state": 1,
                                      "gen_relay_state": 5,
                                      "backup_bat_mode": 1,
                                      "backup_soc": 0,
                                      "is_split_phase": 0,
                                      "phase_count": 3,
                                      "enc_agg_soc": 100,
                                      "enc_agg_energy": 7000,
                                      "acb_agg_soc": 0,
                                      "acb_agg_energy": 0,
                                      "pv": {
                                          "agg_p_mw": 4491343,
                                          "agg_s_mva": 4513215,
                                          "agg_p_ph_a_mw": 1619229,
                                          "agg_p_ph_b_mw": 1460835,
                                          "agg_p_ph_c_mw": 1411277,
                                          "agg_s_ph_a_mva": 1626523,
                                          "agg_s_ph_b_mva": 1468139,
                                          "agg_s_ph_c_mva": 1418551
                                      },
                                      "storage": {
                                          "agg_p_mw": 0,
                                          "agg_s_mva": 0,
                                          "agg_p_ph_a_mw": 0,
                                          "agg_p_ph_b_mw": 0,
                                          "agg_p_ph_c_mw": 0,
                                          "agg_s_ph_a_mva": 0,
                                          "agg_s_ph_b_mva": 0,
                                          "agg_s_ph_c_mva": 0
                                      },
                                      "grid": {
                                          "agg_p_mw": -544891,
                                          "agg_s_mva": -676715,
                                          "agg_p_ph_a_mw": -418249,
                                          "agg_p_ph_b_mw": -886373,
                                          "agg_p_ph_c_mw": 759729,
                                          "agg_s_ph_a_mva": -579678,
                                          "agg_s_ph_b_mva": -901023,
                                          "agg_s_ph_c_mva": 803985
                                      },
                                      "load": {
                                          "agg_p_mw": 3946452,
                                          "agg_s_mva": 3836500,
                                          "agg_p_ph_a_mw": 1200980,
                                          "agg_p_ph_b_mw": 574462,
                                          "agg_p_ph_c_mw": 2171006,
                                          "agg_s_ph_a_mva": 1046845,
                                          "agg_s_ph_b_mva": 567116,
                                          "agg_s_ph_c_mva": 2222536
                                      },
                                      "generator": {
                                          "agg_p_mw": 0,
                                          "agg_s_mva": 0,
                                          "agg_p_ph_a_mw": 0,
                                          "agg_p_ph_b_mw": 0,
                                          "agg_p_ph_c_mw": 0,
                                          "agg_s_ph_a_mva": 0,
                                          "agg_s_ph_b_mva": 0,
                                          "agg_s_ph_c_mva": 0
                                      }
                                  },
                                  "tasks": {
                                      "task_id": 1380042959,
                                      "timestamp": 1723490114
                                  },
                                  "counters": {
                                      "main_CfgLoad": 1,
                                      "main_CfgChanged": 1,
                                      "main_taskUpdate": 152,
                                      "MqttClient_publish": 5441,
                                      "MqttClient_live_debug": 215,
                                      "MqttClient_respond": 338,
                                      "MqttClient_msgarrvd": 169,
                                      "MqttClient_create": 4164,
                                      "MqttClient_setCallbacks": 4164,
                                      "MqttClient_connect": 4164,
                                      "MqttClient_connect_err": 4118,
                                      "MqttClient_connect_Err": 4118,
                                      "MqttClient_subscribe": 46,
                                      "SSL_Keys_Create": 4164,
                                      "sc_hdlDataPub": 2289063,
                                      "sc_SendStreamCtrl": 31,
                                      "sc_SendDemandRspCtrl": 1,
                                      "rest_Status": 253676
                                  },
                                  "dry_contacts": {
                                      "": {
                                          "dry_contact_id": "",
                                          "dry_contact_type": "",
                                          "dry_contact_load_name": "\u0006",
                                          "dry_contact_status": 3051860
                                      },
                                      "": {
                                          "dry_contact_id": "",
                                          "dry_contact_type": "",
                                          "dry_contact_load_name": "",
                                          "dry_contact_status": 3051860
                                      },
                                      "": {
                                          "dry_contact_id": "",
                                          "dry_contact_type": "",
                                          "dry_contact_load_name": "",
                                          "dry_contact_status": 3051860
                                      },
                                      "": {
                                          "dry_contact_id": "",
                                          "dry_contact_type": "",
                                          "dry_contact_load_name": "",
                                          "dry_contact_status": 3051860
                                      }
                                  }
                              }
                               
                              
                              

                              Ich hole mir einfach nur die Daten aus der JSON die ich benötige,
                              was in meinem Fall sich auf "connection" und "meters" ist. Es funktioniert sehr gut.

                              Screenshot_20240814_092937_com.android.chrome_edit_108655502952170.jpg

                              Leider bin ich zu unwissend, wie die anderen beschriebenen Methoden funktionen. Bitte nicht steinigen.
                              Danke für Eure Hilfe und Anregungen

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

                                @steffe-s Wieder eine Bestätigung, dass ich mir die Zeit hier nicht nehmen muss...

                                Einfach nur copy/paste meiner angepassten Funktion war zu schwierig?!

                                Steffe.S. W 2 Replies Last reply Reply Quote 0
                                • Steffe.S.
                                  Steffe.S. @haus-automatisierung last edited by Steffe.S.

                                  @haus-automatisierung sagte in Used invalid characters über Blockly:

                                  @steffe-s Wieder eine Bestätigung, dass ich mir die Zeit hier nicht nehmen muss...

                                  Einfach nur copy/paste meiner angepassten Funktion war zu schwierig?!

                                  ein copy/paste war möglich, jedoch konnte ich leider nicht speichern. Ich habe gestern Abend ca 3 h versucht es mit Deiner Lösung hinzubekommen.

                                  Homoran 1 Reply Last reply Reply Quote 0
                                  • Homoran
                                    Homoran Global Moderator Administrators @Steffe.S. last edited by

                                    @steffe-s sagte in Used invalid characters über Blockly:

                                    jedoch konnte ich leider nicht speichern

                                    ???
                                    was konntest du nicht speichern?

                                    Steffe.S. 1 Reply Last reply Reply Quote 0
                                    • Steffe.S.
                                      Steffe.S. @Homoran last edited by Steffe.S.

                                      @homoran sagte in Used invalid characters über Blockly:

                                      @steffe-s sagte in Used invalid characters über Blockly:

                                      jedoch konnte ich leider nicht speichern

                                      ???
                                      was konntest du nicht speichern?

                                      Ich habe versucht das Skript

                                      
                                      for (const i in obj) {
                                          const value = obj[i];
                                          const attr = i.replace(/[^a-zA-Z0-9._-]+/g, '');
                                       
                                          if (typeof value == 'object') {
                                              IObSetState(id + '.' + attr, value);
                                          } else {
                                              if (existsState(id + '.' + attr)) { // Existing object/ Update
                                                  if (typeof value === 'string' || value instanceof String) { // String
                                                      setState(id + '.' + attr, value, true);
                                                  } else { // It is a number or date
                                                      if ((new Date(value)).getTime() > 0 && Number(value) > 1685000000 && Number(value) < 4100000000) { // Date
                                                         setState(id + '.' + attr, value, true);
                                                         setState(id + '.' + attr + '_str', formatDate(value, 'TT.MM.JJJJ SS:mm:ss'), true);
                                                      } else { // Number
                                                         setState(id + '.' + attr, Number(value), true);
                                                      }
                                                  }
                                              } else { // New object / Create
                                                  if (typeof value === 'string' || value instanceof String) { // String
                                                      createState(id + '.' + attr, value, false, { type: 'string', read: true, write: true });
                                                  } else { // It is a number or date
                                                      if ((new Date(value)).getTime() > 0 && Number(value) > 1685000000 && Number(value) < 4100000000) { // Date
                                                         createState(id + '.' + attr, value, false, { type: 'number', read: true, write: true });
                                                         createState(id + '.' + attr + '_str', formatDate(value, 'TT.MM.JJJJ SS:mm:ss'), false, { type: 'string', read: true, write: true }); 
                                                      } else { // Number
                                                         createState(id + '.' + attr, value, false, { type: 'number', read: true, write: true }); // or type: "mixed"?
                                                      }
                                                  }
                                              }
                                          }
                                      }
                                      
                                      

                                      von @haus-automatisierung in die Funktion einzufügen (siehe roter Kreis im Bild)

                                      Inked1723546570230-8e425cbc-420f-4a32-bcc3-4a772a306b09-image_LI.jpg

                                      wenn dich dann auf Speichern geklickt habe ist nix passiert

                                      Homoran 1 Reply Last reply Reply Quote 0
                                      • Homoran
                                        Homoran Global Moderator Administrators @Steffe.S. last edited by Homoran

                                        @steffe-s hast du vorher den Funktionseditor über die 3 Punkte geöffnet?

                                        Steffe.S. 1 Reply Last reply Reply Quote 0
                                        • Steffe.S.
                                          Steffe.S. @Homoran last edited by

                                          @homoran sagte in Used invalid characters über Blockly:

                                          @steffe-s hast du vorher den Funktionseditor über die 3 Punkte geöffnet?

                                          ja habe ich. Ich habe auch verucht ein vorhandenes Skript einzufügen, da hat dann auch "speichern" funktioniert

                                          1 Reply Last reply Reply Quote 0
                                          • W
                                            Wildbill @haus-automatisierung last edited by

                                            @haus-automatisierung sagte in Used invalid characters über Blockly:

                                            @steffe-s Wieder eine Bestätigung, dass ich mir die Zeit hier nicht nehmen muss...

                                            Einfach nur copy/paste meiner angepassten Funktion war zu schwierig?!

                                            Kurz OT: Ich fände es schade, wenn Du Dir diese Zeit nicht mehr nehmen wolltest. Es gibt vermutlich genug Mitlesende (wie mich) die von dem Problem gar nicht betroffen sind und nur verstehen versuchen, was da passiert und was man wie besser macht.

                                            Auch wenn ich seltenst auf einen Deiner oder auch die anderer Vorschläge antworte, bei denen ich direkt gar nicht betroffen bin, so kannst Du Dir sicher sein, dass die mich schon einiges mal weiter gebracht haben. Also, lass Dich nicht entmutigen und ein dickes DANKE von mir für Deine generelle Unterstützung! Wäre schade, wenn Du Deine Hilfsbereitschaft zurückschraubst, weil sie vom vermeintlichen Adressaten nicht so umgesetzt wird. Es gibt noch genug Andere… 😊

                                            Mit freundlichen Grüßen,

                                            Jürgen

                                            haus-automatisierung 1 Reply Last reply Reply Quote 2
                                            • First post
                                              Last post

                                            Support us

                                            ioBroker
                                            Community Adapters
                                            Donate

                                            461
                                            Online

                                            31.9k
                                            Users

                                            80.1k
                                            Topics

                                            1.3m
                                            Posts

                                            6
                                            62
                                            5163
                                            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