Navigation

    Logo
    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unread
    • Categories
    • Unreplied
    • Popular
    • GitHub
    • Docu
    • Hilfe
    1. Home
    2. Deutsch
    3. Skripten / Logik
    4. verschiedene Datenpunkte in eine Tabelle schreiben

    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

    verschiedene Datenpunkte in eine Tabelle schreiben

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

      Wie kann ich von verschiedenen Zustände die Datenpunkte in einen Datenpunkt (Zeichenkette) für eine Json Tabelle schreiben. Wär hat für mich ein kleines Beispiel damit ich die Aufteilung verstehe.
      Zum Beispiel
      Wohnzimmer: 25°C
      Schlafzimmer:12°C
      usw.
      Danke

      Update
      großen Dank an @paul53 für deine Hilfe. 😊

      paul53 1 Reply Last reply Reply Quote 0
      • paul53
        paul53 @Basti97 last edited by

        @Basti97 sagte:

        eine Json Tabelle schreiben.
        Zum Beispiel
        Wohnzimmer: 25°C
        Schlafzimmer:12°C

        Vorschlag:

        const idTable = '...'; // ID JSON-Tabelle
        const idsTemp = ['...','...','...']; // Datenpunkt-IDs eintragen
        const rooms = ['Wohnen','Schlafen','Küche'];
        
        var table = [];
        for(let i = 0; i < rooms.length; i++) {
            table[i] = {};
            table[i].Raum = rooms[i];
            table[i].Temp = getState(idsTemp[i]).val;
        }
        setState(idTable, JSON.stringify(table), true);
        
        on(idsTemp, function(dp) {
            let idx = idsTemp.indexOf(dp.id);
            table[idx].Temp = dp.state.val;
            setState(idTable, JSON.stringify(table), true);
        });
        
        Basti97 1 Reply Last reply Reply Quote 0
        • Basti97
          Basti97 Most Active @paul53 last edited by Basti97

          @paul53 Danke für deine Hilfe werde es probieren. Wie kann ich in das Script noch die Grad nach den Zahlen einfügen.

          paul53 1 Reply Last reply Reply Quote 0
          • paul53
            paul53 @Basti97 last edited by

            @Basti97 sagte:

            noch die Grad nach den Zahlen einfügen.

                table[idx].Temp = dp.state.val + ' °C';
            
            Basti97 1 Reply Last reply Reply Quote 0
            • Basti97
              Basti97 Most Active @paul53 last edited by

              @paul53 Danke langsam verstehe ich das ganze Script. Hatte bis jetzt nur mi Blockly alles gemacht aber ich sehe mit Java kann man viel mehr machen. 🙂

              paul53 1 Reply Last reply Reply Quote 0
              • paul53
                paul53 @Basti97 last edited by

                @Basti97 sagte:

                aber ich sehe mit Java kann man viel mehr machen.

                Blockly enthält nur eine Teilmenge von Javascript.

                Basti97 1 Reply Last reply Reply Quote 0
                • Basti97
                  Basti97 Most Active @paul53 last edited by

                  @paul53 Ja das merke ich jetzt auch mit Blockly hätte man so etwas nicht hinbekommen. Wie oft wird eigentlich der Datenpunkt aktualisiert? Kann man das auch noch einstellen.

                  paul53 1 Reply Last reply Reply Quote 0
                  • paul53
                    paul53 @Basti97 last edited by paul53

                    @Basti97 sagte:

                    Wie oft wird eigentlich der Datenpunkt aktualisiert?

                    Bei jeder Änderung eines Temperaturwertes der im Array idsTemp angelegten Datenpunkte, also in Echtzeit.

                    Basti97 2 Replies Last reply Reply Quote 0
                    • Basti97
                      Basti97 Most Active @paul53 last edited by

                      @paul53 Ok Der Datenpunkt wird an sich aktualisiert aber die Werte irgendwie bleiben stehen. Die werden erst bei einem Neustart des Adapters aktualisiert.

                      1 Reply Last reply Reply Quote 0
                      • Basti97
                        Basti97 Most Active @paul53 last edited by

                        @paul53
                        Hier ist mein Script ich verstehe nicht warum der Status nicht aktualisiert wird. 😠
                        Ich hoffe ich habe es richtig eingefügt.


                        const idTable = 'javascript.0.virtuelle_Datenpunkte.Temperaturauswertung'; // ID JSON-Tabelle

                        //Temperatur
                        const idsTemp = [
                        'zigbee.0.00158d03035bf62e.temperature',
                        'zigbee.0.00158d03045bf62e.temperature',
                        'zigbee.0.00158d03065bf62e.temperature',
                        'zigbee.0.00158d03046bf62e.temperature',

                        ]; // Luftfeuchtigkeit

                        const idsLuftf = [
                        'zigbee.0.00158d03035bf62e.humidity',
                        'zigbee.0.00158d03045bf62e.humidity',
                        'zigbee.0.00158d03065bf62e.humidity',
                        'zigbee.0.00158d03046bf62e.humidity',

                        ];// Temperatur Status (true oder false)

                        const idsStatus = [
                        'zigbee.0.00158d03035bf62e.available',
                        'zigbee.0.00158d03045bf62e.available',
                        'zigbee.0.00158d03065bf62e.available',
                        'zigbee.0.00158d03046bf62e.available',

                        ]; // Datenpunkt-IDs von Adaptern

                        const rooms = [
                        'Wohnen','Schlafen','Küche',
                        'Bad','Kinderzimmer'
                        ];

                        var table = [];

                        for(let i = 0; i < rooms.length; i++) {

                        // Tabellen Spalten und Überschrift

                        table[i] = {};
                        
                        table[i].Raum = rooms[i];
                        
                        table[i].Temperatur = getState(idsTemp[i]).val + ' °C';
                        table[i].Luftfeuchtigkeit = getState(idsLuftf[i]).val;
                            table[i].Status = getState(idsStatus[i]).val;
                        

                        }

                        setState(idTable, JSON.stringify(table), true);

                        on(idsTemp, function(dp) {

                        let idx = idsTemp.indexOf(dp.id);
                        
                        table[idx].Temp = dp.state.val;
                        
                        setState(idTable, JSON.stringify(table), true);
                        
                        });
                        

                        paul53 1 Reply Last reply Reply Quote 0
                        • paul53
                          paul53 @Basti97 last edited by paul53

                          @Basti97
                          Du hast pro Messgröße 4 Datenpunkte, aber 5 Räume.
                          Für die Aktualisierung aller Messgrößen braucht es 3 Trigger.

                          on(idsTemp, function(dp) {
                             let idx = idsTemp.indexOf(dp.id);
                             table[idx].Temperatur = dp.state.val + ' °C';
                             setState(idTable, JSON.stringify(table), true);
                          });
                          on(idsLuftf, function(dp) {
                             let idx = idsLuftf.indexOf(dp.id);
                             table[idx].Luftfeuchtigkeit = dp.state.val + ' %';
                             setState(idTable, JSON.stringify(table), true);
                          });
                          on(idsStatus, function(dp) {
                             let idx = idsStatus.indexOf(dp.id);
                             table[idx].Status = dp.state.val;
                             setState(idTable, JSON.stringify(table), true);
                          });
                          

                          Bitte den gesamten Javascript-Code immer in Code tags </> posten.

                          Basti97 1 Reply Last reply Reply Quote 0
                          • Basti97
                            Basti97 Most Active @paul53 last edited by Basti97

                            Danke für deine Hilfe.

                            1 Reply Last reply Reply Quote 0
                            • Basti97
                              Basti97 Most Active last edited by

                              Ich habe in meiner Tabelle als Status einzelne False und True (siehe Bild).
                              Wie kann ich nun Definieren das bei True die Text Farbe Grün ist und bei False rot.
                              Der Status kommt von den einzelnen Datenpunkte.
                              Zweite Frage kann man Anstatt true bzw False auch jeweils ein Symbol in Javascript einfügen.

                              Unbenannt.JPG

                              Basti97 1 Reply Last reply Reply Quote 0
                              • Basti97
                                Basti97 Most Active @Basti97 last edited by

                                Hat jemand eine Lösung um die true und false "Datenpunkte" in grün und rot umzuwandeln. Was muss man im JavaScript dafür ändern.

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

                                Support us

                                ioBroker
                                Community Adapters
                                Donate

                                809
                                Online

                                31.8k
                                Users

                                80.0k
                                Topics

                                1.3m
                                Posts

                                blockly javascript monitoring
                                2
                                14
                                1894
                                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