Skip to content
  • Home
  • Aktuell
  • Tags
  • 0 Ungelesen 0
  • Kategorien
  • Unreplied
  • Beliebt
  • GitHub
  • Docu
  • Hilfe
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Standard: (Kein Skin)
  • Kein Skin
Einklappen
ioBroker Logo

Community Forum

donate donate
  1. ioBroker Community Home
  2. Deutsch
  3. Skripten / Logik
  4. JavaScript
  5. [Vorlage] Hilfreiche JavaScript-Funktionen

NEWS

  • UPDATE 31.10.: Amazon Alexa - ioBroker Skill läuft aus ?
    apollon77A
    apollon77
    48
    3
    8.7k

  • Monatsrückblick – September 2025
    BluefoxB
    Bluefox
    13
    1
    2.2k

  • Neues Video "KI im Smart Home" - ioBroker plus n8n
    BluefoxB
    Bluefox
    16
    1
    3.1k

[Vorlage] Hilfreiche JavaScript-Funktionen

Geplant Angeheftet Gesperrt Verschoben JavaScript
javascript
23 Beiträge 10 Kommentatoren 12.8k Aufrufe 43 Watching
  • Älteste zuerst
  • Neuste zuerst
  • Meiste Stimmen
Antworten
  • In einem neuen Thema antworten
Anmelden zum Antworten
Dieses Thema wurde gelöscht. Nur Nutzer mit entsprechenden Rechten können es sehen.
  • MicM Offline
    MicM Offline
    Mic
    Developer
    schrieb am zuletzt editiert von
    #11

    createUserStates() ergänzt:

    Mit diesem Script bzw. dieser Funktion können States (Datenpunkte) unter 0_userdata.0 oder unter javascript.x angelegt werden. Dabei können mehrere States gleichzeitig angelegt werden. Sobald alle erfolgreich angelegt wurden, kann danach (per callback) ein beliebiger Code ausgeführt werden, also beispielsweise die Haupt-Funktion des Scripts.

    1 Antwort Letzte Antwort
    0
    • MicM Offline
      MicM Offline
      Mic
      Developer
      schrieb am zuletzt editiert von
      #12

      isTimeInAstro() und fileExistsSync() ergänzt.

      1 Antwort Letzte Antwort
      0
      • MicM Offline
        MicM Offline
        Mic
        Developer
        schrieb am zuletzt editiert von
        #13

        Notiz an mich selbst:
        json2table() hinzufügen, also Umwandlung JSON in HTML-Tabelle.
        https://forum.iobroker.net/topic/32540/json-zu-html-und-in-datei-schreiben-ablegen

        1 Antwort Letzte Antwort
        0
        • Matthias StübnerM Offline
          Matthias StübnerM Offline
          Matthias Stübner
          schrieb am zuletzt editiert von
          #14

          Ich möchte dateToString(), selbiges wird aber als unbekannt markiert. Muss ich, und wenn ja was, irgendein zusätzliches Modul/Adapter laden?

          MicM htreckslerH 2 Antworten Letzte Antwort
          0
          • Matthias StübnerM Matthias Stübner

            Ich möchte dateToString(), selbiges wird aber als unbekannt markiert. Muss ich, und wenn ja was, irgendein zusätzliches Modul/Adapter laden?

            MicM Offline
            MicM Offline
            Mic
            Developer
            schrieb am zuletzt editiert von Mic
            #15

            @Matthias-Stübner
            Was meinst du genau mit "als unbekannt markiert"? Am besten bitte Logausgabe hier posten.
            Du brauchst keine weiteren Adapter ö.ä. hierfür.

            1 Antwort Letzte Antwort
            0
            • Matthias StübnerM Matthias Stübner

              Ich möchte dateToString(), selbiges wird aber als unbekannt markiert. Muss ich, und wenn ja was, irgendein zusätzliches Modul/Adapter laden?

              htreckslerH Offline
              htreckslerH Offline
              htrecksler
              Forum Testing
              schrieb am zuletzt editiert von
              #16

              @Matthias-Stübner das im Editor unterstrichen wird, kannst DU an der Stelle ignorieren.
              Es sollte dennoch wie erwartet funktionieren.

              Gruss Hermann

              ioBroker auf Proxmox (Debian) auf IntelNuc als Produktivsystem

              moelskiM 1 Antwort Letzte Antwort
              0
              • htreckslerH htrecksler

                @Matthias-Stübner das im Editor unterstrichen wird, kannst DU an der Stelle ignorieren.
                Es sollte dennoch wie erwartet funktionieren.

                moelskiM Offline
                moelskiM Offline
                moelski
                schrieb am zuletzt editiert von
                #17

                Danke für die Funktionen !

                Grüße Dominik

                1 Antwort Letzte Antwort
                0
                • AlCalzoneA Offline
                  AlCalzoneA Offline
                  AlCalzone
                  Developer
                  schrieb am zuletzt editiert von
                  #18

                  clearStr stimmt nicht mit seiner Beschreibung überein:

                  > String(null)
                  'null'
                  

                  Warum `sudo` böse ist: https://forum.iobroker.net/post/17109

                  MicM 1 Antwort Letzte Antwort
                  0
                  • AlCalzoneA AlCalzone

                    clearStr stimmt nicht mit seiner Beschreibung überein:

                    > String(null)
                    'null'
                    
                    MicM Offline
                    MicM Offline
                    Mic
                    Developer
                    schrieb am zuletzt editiert von Mic
                    #19

                    @AlCalzone
                    Danke für den Hinweis, hab die Funktion jetzt ersatzlos entfernt :grinning:
                    Ist so "generisch" eher nicht zu gebrauchen, weil z.B. andere Datentypen (wie number) auch nicht behandelt werden und je nach Einsatzzweck was unterschiedliches zu prüfen ist.

                    Christoph1337C 1 Antwort Letzte Antwort
                    0
                    • MicM Mic

                      @AlCalzone
                      Danke für den Hinweis, hab die Funktion jetzt ersatzlos entfernt :grinning:
                      Ist so "generisch" eher nicht zu gebrauchen, weil z.B. andere Datentypen (wie number) auch nicht behandelt werden und je nach Einsatzzweck was unterschiedliches zu prüfen ist.

                      Christoph1337C Offline
                      Christoph1337C Offline
                      Christoph1337
                      schrieb am zuletzt editiert von
                      #20

                      Moin zusammen,

                      ich habe mal versucht ein paar der Funktionen bei mir einzufügen.

                      Allerdings bekomme ich immer folgende Meldung:

                      script.js.common.Array compile failed: at script.js.common.Array:256

                      das komische. Das Script geht garnicht bis Zeile 256...

                      Auch wenn ich dann alle Zeilen aus kommentiere habe ich dieses Problem.

                      /**
                       * Remove Duplicates from Array
                       * Source - https://stackoverflow.com/questions/23237704/nodejs-how-to-remove-duplicates-from-array
                       * @param {array} inputArray       Array to process
                       * @return {array}  Array without duplicates.
                       */
                      
                      function GlobalarrayRemoveDublicates(inputArray) {
                          let uniqueArray;
                          uniqueArray = inputArray.filter(function(elem, pos) {
                              return inputArray.indexOf(elem) == pos;
                          });
                          return uniqueArray;
                      }
                      
                      /**
                       * Clean Array: Removes all falsy values: undefined, null, 0, false, NaN and "" (empty string)
                       * Source: https://stackoverflow.com/questions/281264/remove-empty-elements-from-an-array-in-javascript
                       * @param {array} inputArray       Array to process
                       * @return {array}  Cleaned array
                       */
                      /*
                      function GlobalcleanArray(inputArray) {
                        var newArray = [];
                        for (let i = 0; i < inputArray.length; i++) {
                          if (inputArray[i]) {
                            newArray.push(inputArray[i]);
                          }
                        }
                        return newArray;
                      }
                      */
                      /**
                       * Removing Array element(s) by input value. 
                       * @param {array}   arr             the input array
                       * @param {string}  valRemove       the value to be removed
                       * @param {boolean} [exact=true]    OPTIONAL: default is true. if true, it must fully match. if false, it matches also if valRemove is part of element string
                       * @return {array}  the array without the element(s)
                       */
                      /*
                      function GlobalarrayRemoveElementsByValue(arr, valRemove, exact) {
                       
                          if (exact === undefined) exact = true;
                       
                          for ( let i = 0; i < arr.length; i++){ 
                              if (exact) {
                                  if ( arr[i] === valRemove) {
                                      arr.splice(i, 1);
                                      i--; // required, see https://love2dev.com/blog/javascript-remove-from-array/
                                  }
                              } else {
                                  if (arr[i].indexOf(valRemove) != -1) {
                                      arr.splice(i, 1);
                                      i--; // see above
                                  }
                              }
                          }
                          return arr;
                      }
                      */
                      /**
                       * Checks if Array or String is not undefined, null or empty.
                       * 08-Sep-2019: added check for [ and ] to also catch arrays with empty strings.
                       * @param inputVar - Input Array or String, Number, etc.
                       * @return true if it is undefined/null/empty, false if it contains value(s)
                       * Array or String containing just whitespaces or >'< or >"< or >[< or >]< is considered empty
                       */
                      /*
                      function GlobalisLikeEmpty(inputVar) {
                          if (typeof inputVar !== 'undefined' && inputVar !== null) {
                              let strTemp = JSON.stringify(inputVar);
                              strTemp = strTemp.replace(/\s+/g, ''); // remove all whitespaces
                              strTemp = strTemp.replace(/\"+/g, "");  // remove all >"<
                              strTemp = strTemp.replace(/\'+/g, "");  // remove all >'<
                              strTemp = strTemp.replace(/[+/g, "");  // remove all >[<
                              strTemp = strTemp.replace(/]+/g, "");  // remove all >]<
                              if (strTemp !== '') {
                                  return false;
                              } else {
                                  return true;
                              }
                          } else {
                              return true;
                          }
                      }
                      */
                      
                      Christoph1337C liv-in-skyL AlCalzoneA 3 Antworten Letzte Antwort
                      0
                      • Christoph1337C Christoph1337

                        Moin zusammen,

                        ich habe mal versucht ein paar der Funktionen bei mir einzufügen.

                        Allerdings bekomme ich immer folgende Meldung:

                        script.js.common.Array compile failed: at script.js.common.Array:256

                        das komische. Das Script geht garnicht bis Zeile 256...

                        Auch wenn ich dann alle Zeilen aus kommentiere habe ich dieses Problem.

                        /**
                         * Remove Duplicates from Array
                         * Source - https://stackoverflow.com/questions/23237704/nodejs-how-to-remove-duplicates-from-array
                         * @param {array} inputArray       Array to process
                         * @return {array}  Array without duplicates.
                         */
                        
                        function GlobalarrayRemoveDublicates(inputArray) {
                            let uniqueArray;
                            uniqueArray = inputArray.filter(function(elem, pos) {
                                return inputArray.indexOf(elem) == pos;
                            });
                            return uniqueArray;
                        }
                        
                        /**
                         * Clean Array: Removes all falsy values: undefined, null, 0, false, NaN and "" (empty string)
                         * Source: https://stackoverflow.com/questions/281264/remove-empty-elements-from-an-array-in-javascript
                         * @param {array} inputArray       Array to process
                         * @return {array}  Cleaned array
                         */
                        /*
                        function GlobalcleanArray(inputArray) {
                          var newArray = [];
                          for (let i = 0; i < inputArray.length; i++) {
                            if (inputArray[i]) {
                              newArray.push(inputArray[i]);
                            }
                          }
                          return newArray;
                        }
                        */
                        /**
                         * Removing Array element(s) by input value. 
                         * @param {array}   arr             the input array
                         * @param {string}  valRemove       the value to be removed
                         * @param {boolean} [exact=true]    OPTIONAL: default is true. if true, it must fully match. if false, it matches also if valRemove is part of element string
                         * @return {array}  the array without the element(s)
                         */
                        /*
                        function GlobalarrayRemoveElementsByValue(arr, valRemove, exact) {
                         
                            if (exact === undefined) exact = true;
                         
                            for ( let i = 0; i < arr.length; i++){ 
                                if (exact) {
                                    if ( arr[i] === valRemove) {
                                        arr.splice(i, 1);
                                        i--; // required, see https://love2dev.com/blog/javascript-remove-from-array/
                                    }
                                } else {
                                    if (arr[i].indexOf(valRemove) != -1) {
                                        arr.splice(i, 1);
                                        i--; // see above
                                    }
                                }
                            }
                            return arr;
                        }
                        */
                        /**
                         * Checks if Array or String is not undefined, null or empty.
                         * 08-Sep-2019: added check for [ and ] to also catch arrays with empty strings.
                         * @param inputVar - Input Array or String, Number, etc.
                         * @return true if it is undefined/null/empty, false if it contains value(s)
                         * Array or String containing just whitespaces or >'< or >"< or >[< or >]< is considered empty
                         */
                        /*
                        function GlobalisLikeEmpty(inputVar) {
                            if (typeof inputVar !== 'undefined' && inputVar !== null) {
                                let strTemp = JSON.stringify(inputVar);
                                strTemp = strTemp.replace(/\s+/g, ''); // remove all whitespaces
                                strTemp = strTemp.replace(/\"+/g, "");  // remove all >"<
                                strTemp = strTemp.replace(/\'+/g, "");  // remove all >'<
                                strTemp = strTemp.replace(/[+/g, "");  // remove all >[<
                                strTemp = strTemp.replace(/]+/g, "");  // remove all >]<
                                if (strTemp !== '') {
                                    return false;
                                } else {
                                    return true;
                                }
                            } else {
                                return true;
                            }
                        }
                        */
                        
                        Christoph1337C Offline
                        Christoph1337C Offline
                        Christoph1337
                        schrieb am zuletzt editiert von
                        #21

                        Hab es selber gelöst:

                        /** 
                         * Checks if Array or String is not undefined, null or empty.
                         * 08-Sep-2019: added check for [ and ] to also catch arrays with empty strings.
                         * @param inputVar - Input Array or String, Number, etc.
                         * @return true if it is undefined/null/empty, false if it contains value(s)
                         * Array or String containing just whitespaces or >'< or >"< or >[< or >]< is considered empty
                        */
                        
                        function GlobalIsLikeEmpty(inputVar) 
                        {
                            if (typeof inputVar !== 'undefined' && inputVar !== null) {
                                let strTemp = JSON.stringify(inputVar);
                                strTemp = strTemp.replace(/\s+/g, ''); // remove all whitespaces
                                strTemp = strTemp.replace(/\"+/g, "");  // remove all >"<
                                strTemp = strTemp.replace(/\'+/g, "");  // remove all >'<
                                strTemp = strTemp.replace(/\[+/g, "");  // remove all >[<
                                strTemp = strTemp.replace(/]+/g, "");  // remove all >]<
                        
                                if (strTemp !== '') {
                                    return false;
                                } else {
                                    return true;
                                }
                            } else {
                                return true;
                            }
                        }
                        
                        1 Antwort Letzte Antwort
                        0
                        • Christoph1337C Christoph1337

                          Moin zusammen,

                          ich habe mal versucht ein paar der Funktionen bei mir einzufügen.

                          Allerdings bekomme ich immer folgende Meldung:

                          script.js.common.Array compile failed: at script.js.common.Array:256

                          das komische. Das Script geht garnicht bis Zeile 256...

                          Auch wenn ich dann alle Zeilen aus kommentiere habe ich dieses Problem.

                          /**
                           * Remove Duplicates from Array
                           * Source - https://stackoverflow.com/questions/23237704/nodejs-how-to-remove-duplicates-from-array
                           * @param {array} inputArray       Array to process
                           * @return {array}  Array without duplicates.
                           */
                          
                          function GlobalarrayRemoveDublicates(inputArray) {
                              let uniqueArray;
                              uniqueArray = inputArray.filter(function(elem, pos) {
                                  return inputArray.indexOf(elem) == pos;
                              });
                              return uniqueArray;
                          }
                          
                          /**
                           * Clean Array: Removes all falsy values: undefined, null, 0, false, NaN and "" (empty string)
                           * Source: https://stackoverflow.com/questions/281264/remove-empty-elements-from-an-array-in-javascript
                           * @param {array} inputArray       Array to process
                           * @return {array}  Cleaned array
                           */
                          /*
                          function GlobalcleanArray(inputArray) {
                            var newArray = [];
                            for (let i = 0; i < inputArray.length; i++) {
                              if (inputArray[i]) {
                                newArray.push(inputArray[i]);
                              }
                            }
                            return newArray;
                          }
                          */
                          /**
                           * Removing Array element(s) by input value. 
                           * @param {array}   arr             the input array
                           * @param {string}  valRemove       the value to be removed
                           * @param {boolean} [exact=true]    OPTIONAL: default is true. if true, it must fully match. if false, it matches also if valRemove is part of element string
                           * @return {array}  the array without the element(s)
                           */
                          /*
                          function GlobalarrayRemoveElementsByValue(arr, valRemove, exact) {
                           
                              if (exact === undefined) exact = true;
                           
                              for ( let i = 0; i < arr.length; i++){ 
                                  if (exact) {
                                      if ( arr[i] === valRemove) {
                                          arr.splice(i, 1);
                                          i--; // required, see https://love2dev.com/blog/javascript-remove-from-array/
                                      }
                                  } else {
                                      if (arr[i].indexOf(valRemove) != -1) {
                                          arr.splice(i, 1);
                                          i--; // see above
                                      }
                                  }
                              }
                              return arr;
                          }
                          */
                          /**
                           * Checks if Array or String is not undefined, null or empty.
                           * 08-Sep-2019: added check for [ and ] to also catch arrays with empty strings.
                           * @param inputVar - Input Array or String, Number, etc.
                           * @return true if it is undefined/null/empty, false if it contains value(s)
                           * Array or String containing just whitespaces or >'< or >"< or >[< or >]< is considered empty
                           */
                          /*
                          function GlobalisLikeEmpty(inputVar) {
                              if (typeof inputVar !== 'undefined' && inputVar !== null) {
                                  let strTemp = JSON.stringify(inputVar);
                                  strTemp = strTemp.replace(/\s+/g, ''); // remove all whitespaces
                                  strTemp = strTemp.replace(/\"+/g, "");  // remove all >"<
                                  strTemp = strTemp.replace(/\'+/g, "");  // remove all >'<
                                  strTemp = strTemp.replace(/[+/g, "");  // remove all >[<
                                  strTemp = strTemp.replace(/]+/g, "");  // remove all >]<
                                  if (strTemp !== '') {
                                      return false;
                                  } else {
                                      return true;
                                  }
                              } else {
                                  return true;
                              }
                          }
                          */
                          
                          liv-in-skyL Offline
                          liv-in-skyL Offline
                          liv-in-sky
                          schrieb am zuletzt editiert von liv-in-sky
                          #22

                          @christoph1337 sagte in [Vorlage] Hilfreiche JavaScript-Funktionen:

                          {1}

                          da sind diese {1}
                          drin - da ist evtl was beim kopieren schiefgegangen

                          lösche die mal raus

                          nach einem gelösten Thread wäre es sinnvoll dies in der Überschrift des ersten Posts einzutragen [gelöst]-... Bitte benutzt das Voting rechts unten im Beitrag wenn er euch geholfen hat. Forum-Tools: PicPick https://picpick.app/en/download/ und ScreenToGif https://www.screentogif.com/downloads.html

                          1 Antwort Letzte Antwort
                          0
                          • Christoph1337C Christoph1337

                            Moin zusammen,

                            ich habe mal versucht ein paar der Funktionen bei mir einzufügen.

                            Allerdings bekomme ich immer folgende Meldung:

                            script.js.common.Array compile failed: at script.js.common.Array:256

                            das komische. Das Script geht garnicht bis Zeile 256...

                            Auch wenn ich dann alle Zeilen aus kommentiere habe ich dieses Problem.

                            /**
                             * Remove Duplicates from Array
                             * Source - https://stackoverflow.com/questions/23237704/nodejs-how-to-remove-duplicates-from-array
                             * @param {array} inputArray       Array to process
                             * @return {array}  Array without duplicates.
                             */
                            
                            function GlobalarrayRemoveDublicates(inputArray) {
                                let uniqueArray;
                                uniqueArray = inputArray.filter(function(elem, pos) {
                                    return inputArray.indexOf(elem) == pos;
                                });
                                return uniqueArray;
                            }
                            
                            /**
                             * Clean Array: Removes all falsy values: undefined, null, 0, false, NaN and "" (empty string)
                             * Source: https://stackoverflow.com/questions/281264/remove-empty-elements-from-an-array-in-javascript
                             * @param {array} inputArray       Array to process
                             * @return {array}  Cleaned array
                             */
                            /*
                            function GlobalcleanArray(inputArray) {
                              var newArray = [];
                              for (let i = 0; i < inputArray.length; i++) {
                                if (inputArray[i]) {
                                  newArray.push(inputArray[i]);
                                }
                              }
                              return newArray;
                            }
                            */
                            /**
                             * Removing Array element(s) by input value. 
                             * @param {array}   arr             the input array
                             * @param {string}  valRemove       the value to be removed
                             * @param {boolean} [exact=true]    OPTIONAL: default is true. if true, it must fully match. if false, it matches also if valRemove is part of element string
                             * @return {array}  the array without the element(s)
                             */
                            /*
                            function GlobalarrayRemoveElementsByValue(arr, valRemove, exact) {
                             
                                if (exact === undefined) exact = true;
                             
                                for ( let i = 0; i < arr.length; i++){ 
                                    if (exact) {
                                        if ( arr[i] === valRemove) {
                                            arr.splice(i, 1);
                                            i--; // required, see https://love2dev.com/blog/javascript-remove-from-array/
                                        }
                                    } else {
                                        if (arr[i].indexOf(valRemove) != -1) {
                                            arr.splice(i, 1);
                                            i--; // see above
                                        }
                                    }
                                }
                                return arr;
                            }
                            */
                            /**
                             * Checks if Array or String is not undefined, null or empty.
                             * 08-Sep-2019: added check for [ and ] to also catch arrays with empty strings.
                             * @param inputVar - Input Array or String, Number, etc.
                             * @return true if it is undefined/null/empty, false if it contains value(s)
                             * Array or String containing just whitespaces or >'< or >"< or >[< or >]< is considered empty
                             */
                            /*
                            function GlobalisLikeEmpty(inputVar) {
                                if (typeof inputVar !== 'undefined' && inputVar !== null) {
                                    let strTemp = JSON.stringify(inputVar);
                                    strTemp = strTemp.replace(/\s+/g, ''); // remove all whitespaces
                                    strTemp = strTemp.replace(/\"+/g, "");  // remove all >"<
                                    strTemp = strTemp.replace(/\'+/g, "");  // remove all >'<
                                    strTemp = strTemp.replace(/[+/g, "");  // remove all >[<
                                    strTemp = strTemp.replace(/]+/g, "");  // remove all >]<
                                    if (strTemp !== '') {
                                        return false;
                                    } else {
                                        return true;
                                    }
                                } else {
                                    return true;
                                }
                            }
                            */
                            
                            AlCalzoneA Offline
                            AlCalzoneA Offline
                            AlCalzone
                            Developer
                            schrieb am zuletzt editiert von
                            #23

                            @christoph1337 sagte in [Vorlage] Hilfreiche JavaScript-Funktionen:

                            Das Script geht garnicht bis Zeile 256...

                            Hast du globale Skripte?

                            Warum `sudo` böse ist: https://forum.iobroker.net/post/17109

                            1 Antwort Letzte Antwort
                            0
                            Antworten
                            • In einem neuen Thema antworten
                            Anmelden zum Antworten
                            • Älteste zuerst
                            • Neuste zuerst
                            • Meiste Stimmen


                            Support us

                            ioBroker
                            Community Adapters
                            Donate

                            503

                            Online

                            32.4k

                            Benutzer

                            81.5k

                            Themen

                            1.3m

                            Beiträge
                            Community
                            Impressum | Datenschutz-Bestimmungen | Nutzungsbedingungen | Einwilligungseinstellungen
                            ioBroker Community 2014-2025
                            logo
                            • Anmelden

                            • Du hast noch kein Konto? Registrieren

                            • Anmelden oder registrieren, um zu suchen
                            • Erster Beitrag
                              Letzter Beitrag
                            0
                            • Home
                            • Aktuell
                            • Tags
                            • Ungelesen 0
                            • Kategorien
                            • Unreplied
                            • Beliebt
                            • GitHub
                            • Docu
                            • Hilfe