Navigation

    Logo
    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unread
    • Categories
    • Unreplied
    • Popular
    • GitHub
    • Docu
    • Hilfe
    1. Home
    2. Deutsch
    3. Skripten / Logik
    4. JavaScript
    5. Wert wird nicht aktualisiert

    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

    Wert wird nicht aktualisiert

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

      Was mache ich falsch?
      Ich will eine kleine CO2 Ampel realisieren.
      Dazu lasse ich das Script hier laufen:

      const CO2 = "sonoff.0.TempTheke.CCS811_eCO2"/*Luftguete*/;
      
      function setAmpel(x) { 
        var y = 0;
        if(x > 400) y = '#0C3600';
        if(x > 800) y = '#363200';
        if(x > 1200) y = '#360100';
        
        setState("sonoff.0.TempTheke.Color"/*Ampelfarbe*/, y, true);
      }
      
      setAmpel(getState(CO2).val); // Skriptstart
      
      on(CO2, function(dp) { // triggert bei Wertänderung
        setAmpel(dp.state.val);
      });
      

      Der Wert für die Farbe wird korrekt in den Datenpunkt geschrieben, aber scheinbar muss ich den dann aktualisieren damit der per Sonoff Adapter an den Wemos übertragen wird.
      Schreibe ich den Wert von Hand und bestätige wird der sofort übertragen und die Farbe ändert sich.
      Irgendwas übersehe ich, aber ich habe keine Idee was.

      Dann habe ich noch eine Fehlermeldung:

      javascript.1	2021-02-02 23:01:14.509	warn	(547) State "javascript.1.scriptEnabled.Umwelt.CO2Anzeige" has no existing object, this might lead to an error in future versions
      

      die ich so nicht verstehe. Ich habe doch ein Objekt definiert oder?

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

        @chaot sagte: Irgendwas übersehe ich, aber ich habe keine Idee was.

        Lass in Zeile 9 true am Ende des setState(id, val, ack) weg oder ändere es in false.

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

          @paul53 Danke.
          Das scheint zu klappen.
          Ich bin leider nicht ganz so fit in Javascript.
          Jetzt kommt aber folgende Meldung:

          javascript.0	2021-02-03 07:01:39.627	warn	(438) at script.js.Umwelt.CO2Anzeige:34:3
          javascript.0	2021-02-03 07:01:39.627	warn	(438) at script.js.Umwelt.CO2Anzeige:12:1
          javascript.0	2021-02-03 07:01:39.626	warn	(438) at setAmpel (script.js.Umwelt.CO2Anzeige:9:3)
          javascript.0	2021-02-03 07:01:39.625	warn	(438) at setState (/opt/iobroker/node_modules/iobroker.javascript/lib/sandbox.js:1417:20)
          javascript.0	2021-02-03 07:01:39.623	warn	(438) You are assigning a number to the state "sonoff.0.TempTheke.Color" which expects a string. Please fix your code to use a string or change the state type to number. This warning might become an
          

          Abhilfe 1 wäre den Datenpunkt zu ändern. Aber das geht doch auch im Script. Ich habe das irgendwann schon mal gehabt, weiß es aber nicht mehr. Kannst du mir da eventuell nochmal helfen?

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

            @chaot sagte: You are assigning a number to the state "sonoff.0.TempTheke.Color"

            Zeile 4 ändern.

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

              @paul53

              var y = '0';
              

              So? Ich muss ehrlich sagen das ich wirklich merke das ich alt werde. Früher habe ich mir so nen Kram einfach gemerkt und gut, aber das lässt einfach nach.

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

                @chaot sagte:

                var y = '0';
                

                So?

                Ja.

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

                Support us

                ioBroker
                Community Adapters
                Donate

                835
                Online

                31.9k
                Users

                80.1k
                Topics

                1.3m
                Posts

                javascript
                2
                6
                217
                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