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. Visualisierung
  4. [solved] Custom HTML with Object ID bindings

NEWS

  • Monatsrückblick Januar/Februar 2026 ist online!
    BluefoxB
    Bluefox
    17
    1
    377

  • Jahresrückblick 2025 – unser neuer Blogbeitrag ist online! ✨
    BluefoxB
    Bluefox
    17
    1
    4.9k

  • Neuer Blogbeitrag: Monatsrückblick - Dezember 2025 🎄
    BluefoxB
    Bluefox
    13
    1
    1.3k

[solved] Custom HTML with Object ID bindings

Geplant Angeheftet Gesperrt Verschoben Visualisierung
vis
9 Beiträge 2 Kommentatoren 822 Aufrufe 1 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.
  • KarolisLK Offline
    KarolisLK Offline
    KarolisL
    schrieb am zuletzt editiert von KarolisL
    #1

    Hello, I've noticed this question was asked at least 2 times but without answers.

    I have custom html code:

    <!DOCTYPE html>
    <html>
        <body>
             
            <canvas id="myCanvas" width="401" height="401" style="border:1px solid #d3d3d3;">
                Your browser does not support the HTML5 canvas tag.
            </canvas>
             
            <script type="text/javascript">
                 
                var X = 200;
                var Y = 200;
                var outterRadius = 180;
                var innerRadius = 110;
     
                // 1. get a reference to myCanvas element.
                var c = document.getElementById("myCanvas");
                 
                // 2. get canvas context
                var context = c.getContext("2d");
                 
                // 3. draw donut chart
                 
                // RED
                setRadialGradient("#DC1C29", "#B7161B");
                drawDonut(Math.PI * 0.5, Math.PI * 0.75);
                 
                // GREEN
                setRadialGradient("#84BC3D", "#5B8829");
                drawDonut(Math.PI*0.75 , Math.PI* 1.5);
                 
                // BLUE
                setRadialGradient("#27A1D4", "#2182AD");
                drawDonut(Math.PI * 1.5, Math.PI*2);
                 
                // YELLOW
                setRadialGradient("#ECCF2D", "#F1C433");
                drawDonut(0, Math.PI*.5);
                 
                //*******************************************************//\        
                // drawDonut() function drawes 2 full or partial circles inside each other one clockwise and the other is counter-clockwise
                function drawDonut(sRadian, eRadian){
                     
                    context.beginPath();
                        context.arc(X, Y, outterRadius, sRadian, eRadian, false); // Outer: CCW
                        context.arc(X, Y, innerRadius, eRadian, sRadian, true); // Inner: CW
                    context.closePath();
                     
                    // add shadow
                    addShadow();
                                     
                    context.fill();
                }
                 
                function addShadow(){
                    context.shadowColor = "#333";
                    context.shadowBlur = 5;
                    context.shadowOffsetX = 0;
                    context.shadowOffsetY = 0;
                }
                 
                function setRadialGradient(sgc, bgc){
                    var grd = context.createRadialGradient(X, Y, innerRadius + 5, X, Y, outterRadius);
                    grd.addColorStop(0,sgc);
                    grd.addColorStop(1,bgc);
                    context.fillStyle = grd;
                }
            </script>
        </body>
    </html>
    

    How to make

                // RED
                setRadialGradient("#DC1C29", "#B7161B");
                drawDonut(Math.PI * 0.5, Math.PI * 0.75);
                 
                // GREEN
                setRadialGradient("#84BC3D", "#5B8829");
                drawDonut(Math.PI*0.75 , Math.PI* 1.5);
    

    dynamic Object ID bindings something like:

    drawDonut(Math.PI * {node-red.val1}, Math.PI * 0.75);
    

    ?

    foxriver76F 1 Antwort Letzte Antwort
    0
    • KarolisLK KarolisL

      Hello, I've noticed this question was asked at least 2 times but without answers.

      I have custom html code:

      <!DOCTYPE html>
      <html>
          <body>
               
              <canvas id="myCanvas" width="401" height="401" style="border:1px solid #d3d3d3;">
                  Your browser does not support the HTML5 canvas tag.
              </canvas>
               
              <script type="text/javascript">
                   
                  var X = 200;
                  var Y = 200;
                  var outterRadius = 180;
                  var innerRadius = 110;
       
                  // 1. get a reference to myCanvas element.
                  var c = document.getElementById("myCanvas");
                   
                  // 2. get canvas context
                  var context = c.getContext("2d");
                   
                  // 3. draw donut chart
                   
                  // RED
                  setRadialGradient("#DC1C29", "#B7161B");
                  drawDonut(Math.PI * 0.5, Math.PI * 0.75);
                   
                  // GREEN
                  setRadialGradient("#84BC3D", "#5B8829");
                  drawDonut(Math.PI*0.75 , Math.PI* 1.5);
                   
                  // BLUE
                  setRadialGradient("#27A1D4", "#2182AD");
                  drawDonut(Math.PI * 1.5, Math.PI*2);
                   
                  // YELLOW
                  setRadialGradient("#ECCF2D", "#F1C433");
                  drawDonut(0, Math.PI*.5);
                   
                  //*******************************************************//\        
                  // drawDonut() function drawes 2 full or partial circles inside each other one clockwise and the other is counter-clockwise
                  function drawDonut(sRadian, eRadian){
                       
                      context.beginPath();
                          context.arc(X, Y, outterRadius, sRadian, eRadian, false); // Outer: CCW
                          context.arc(X, Y, innerRadius, eRadian, sRadian, true); // Inner: CW
                      context.closePath();
                       
                      // add shadow
                      addShadow();
                                       
                      context.fill();
                  }
                   
                  function addShadow(){
                      context.shadowColor = "#333";
                      context.shadowBlur = 5;
                      context.shadowOffsetX = 0;
                      context.shadowOffsetY = 0;
                  }
                   
                  function setRadialGradient(sgc, bgc){
                      var grd = context.createRadialGradient(X, Y, innerRadius + 5, X, Y, outterRadius);
                      grd.addColorStop(0,sgc);
                      grd.addColorStop(1,bgc);
                      context.fillStyle = grd;
                  }
              </script>
          </body>
      </html>
      

      How to make

                  // RED
                  setRadialGradient("#DC1C29", "#B7161B");
                  drawDonut(Math.PI * 0.5, Math.PI * 0.75);
                   
                  // GREEN
                  setRadialGradient("#84BC3D", "#5B8829");
                  drawDonut(Math.PI*0.75 , Math.PI* 1.5);
      

      dynamic Object ID bindings something like:

      drawDonut(Math.PI * {node-red.val1}, Math.PI * 0.75);
      

      ?

      foxriver76F Offline
      foxriver76F Offline
      foxriver76
      Developer
      schrieb am zuletzt editiert von
      #2

      @KarolisL To the best of my knowledge, Bindings are not possible in Javascript code, only in the vis attributes. If your topic is realated to html in vis, then you could get the states value by using the value of vis.states. But note that vis.states only contains the values of the states which are necessary for your widgets. So you could add a dummy widget with the desired states and make it invisible. Probabaly there is also the possibility to use socket.emit('getState', 'yourState', function (err, state) {}) when socket io is included.

      Videotutorials & mehr

      Hier könnt ihr mich unterstützen.

      KarolisLK 1 Antwort Letzte Antwort
      0
      • foxriver76F foxriver76

        @KarolisL To the best of my knowledge, Bindings are not possible in Javascript code, only in the vis attributes. If your topic is realated to html in vis, then you could get the states value by using the value of vis.states. But note that vis.states only contains the values of the states which are necessary for your widgets. So you could add a dummy widget with the desired states and make it invisible. Probabaly there is also the possibility to use socket.emit('getState', 'yourState', function (err, state) {}) when socket io is included.

        KarolisLK Offline
        KarolisLK Offline
        KarolisL
        schrieb am zuletzt editiert von
        #3

        @foxriver76 Thanks for quick response. Sadly I didn't understand fully:

        Lets say I tried to use state admin.0.info.updatesNumber which is internal in admin.0 object

        var part1=vis.states(admin.0.info.updatesNumber);
                    // RED
                    setRadialGradient("#DC1C29", "#B7161B");
                    drawDonut(Math.PI * part1, Math.PI * 0.75);
        

        As I understand I'm missing something, how to extract state value by using:

        vis.states
        

        command?

        foxriver76F 1 Antwort Letzte Antwort
        0
        • KarolisLK KarolisL

          @foxriver76 Thanks for quick response. Sadly I didn't understand fully:

          Lets say I tried to use state admin.0.info.updatesNumber which is internal in admin.0 object

          var part1=vis.states(admin.0.info.updatesNumber);
                      // RED
                      setRadialGradient("#DC1C29", "#B7161B");
                      drawDonut(Math.PI * part1, Math.PI * 0.75);
          

          As I understand I'm missing something, how to extract state value by using:

          vis.states
          

          command?

          foxriver76F Offline
          foxriver76F Offline
          foxriver76
          Developer
          schrieb am zuletzt editiert von foxriver76
          #4

          @KarolisL vis.states is just an array. By logging it you can get the contained information in the browsers console.

          <script type="text/javascript">
              console.log(vis.states);
          </script>
          

          It's an array with the following structure:
          Bildschirmfoto von 2019-04-30 18-04-59.png

          So it contains the states value, ts, last changed ts and acknowledge flag. You can access an array by its unqiue id:

          <script type="text/javascript">
              console.log('The state has been changed at ' + vis.states["denon.0.zoneMain.volumeDown.lc"]);
          </script>
          

          which results in:

          Bildschirmfoto von 2019-04-30 18-10-46.png

          Videotutorials & mehr

          Hier könnt ihr mich unterstützen.

          KarolisLK 1 Antwort Letzte Antwort
          1
          • foxriver76F foxriver76

            @KarolisL vis.states is just an array. By logging it you can get the contained information in the browsers console.

            <script type="text/javascript">
                console.log(vis.states);
            </script>
            

            It's an array with the following structure:
            Bildschirmfoto von 2019-04-30 18-04-59.png

            So it contains the states value, ts, last changed ts and acknowledge flag. You can access an array by its unqiue id:

            <script type="text/javascript">
                console.log('The state has been changed at ' + vis.states["denon.0.zoneMain.volumeDown.lc"]);
            </script>
            

            which results in:

            Bildschirmfoto von 2019-04-30 18-10-46.png

            KarolisLK Offline
            KarolisLK Offline
            KarolisL
            schrieb am zuletzt editiert von
            #5

            @foxriver76 Thank you. For future references if anybody will have similar problems:

            to access global variables/objects you just have to address them through

             var variable = vis.states["node-red.0.DATA"] // or whatever you see in console.log (vis.states())
            

            can't thank you enough

            How to mark as solved?

            foxriver76F 1 Antwort Letzte Antwort
            0
            • KarolisLK KarolisL

              @foxriver76 Thank you. For future references if anybody will have similar problems:

              to access global variables/objects you just have to address them through

               var variable = vis.states["node-red.0.DATA"] // or whatever you see in console.log (vis.states())
              

              can't thank you enough

              How to mark as solved?

              foxriver76F Offline
              foxriver76F Offline
              foxriver76
              Developer
              schrieb am zuletzt editiert von
              #6

              @KarolisL you are welcome.

              When editing the first post, you can change the title and e. g. write ‘[solved]’ in front of it.

              Videotutorials & mehr

              Hier könnt ihr mich unterstützen.

              KarolisLK 1 Antwort Letzte Antwort
              0
              • foxriver76F foxriver76

                @KarolisL you are welcome.

                When editing the first post, you can change the title and e. g. write ‘[solved]’ in front of it.

                KarolisLK Offline
                KarolisLK Offline
                KarolisL
                schrieb am zuletzt editiert von KarolisL
                #7

                @foxriver76

                One last question, this is how it looks in editor (pic1)
                c38b831b-3255-48d6-b3f1-b04bd936bd15-image.png

                Why parts with vis.states are missing like that in runtime (pic2)?

                e60e8010-539f-49e3-97f2-168e4a24edc1-image.png

                <!DOCTYPE html>
                <html>
                    <body>
                         
                        <canvas id="myCanvas" width="401" height="401" style="border:1px solid #d3d3d3;">
                            Your browser does not support the HTML5 canvas tag.
                        </canvas>
                         
                        <script type="text/javascript">
                            console.log(vis.states["admin.0.info.updatesNumber.val"]);
                            var part1 = vis.states["admin.0.info.updatesNumber.val"]/7;
                            var X = 200;
                            var Y = 200;
                            var outterRadius = 180;
                            var innerRadius = 110;
                 
                            // 1. get a reference to myCanvas element.
                            var c = document.getElementById("myCanvas");
                             
                            // 2. get canvas context
                            var context = c.getContext("2d");
                             
                            // 3. draw donut chart
                             
                            // RED
                            setRadialGradient("#DC1C29", "#B7161B");
                            drawDonut(Math.PI *part1, Math.PI * 0.75);
                             
                            // GREEN
                            setRadialGradient("#84BC3D", "#5B8829");
                            drawDonut(Math.PI*0.75 , Math.PI* 1.5);
                             
                            // BLUE
                            setRadialGradient("#27A1D4", "#2182AD");
                            drawDonut(Math.PI * 2*part1, Math.PI*2);
                             
                            // YELLOW
                            setRadialGradient("#ECCF2D", "#F1C433");
                            drawDonut(0, Math.PI*.5);
                             
                            //*******************************************************//\        
                            // drawDonut() function drawes 2 full or partial circles inside each other one clockwise and the other is counter-clockwise
                            function drawDonut(sRadian, eRadian){
                                 
                                context.beginPath();
                                    context.arc(X, Y, outterRadius, sRadian, eRadian, false); // Outer: CCW
                                    context.arc(X, Y, innerRadius, eRadian, sRadian, true); // Inner: CW
                                context.closePath();
                                 
                                // add shadow
                                addShadow();
                                                 
                                context.fill();
                            }
                             
                            function addShadow(){
                                context.shadowColor = "#333";
                                context.shadowBlur = 5;
                                context.shadowOffsetX = 0;
                                context.shadowOffsetY = 0;
                            }
                             
                            function setRadialGradient(sgc, bgc){
                                var grd = context.createRadialGradient(X, Y, innerRadius + 5, X, Y, outterRadius);
                                grd.addColorStop(0,sgc);
                                grd.addColorStop(1,bgc);
                                context.fillStyle = grd;
                            }
                        </script>
                    </body>
                </html>
                
                foxriver76F 1 Antwort Letzte Antwort
                0
                • KarolisLK KarolisL

                  @foxriver76

                  One last question, this is how it looks in editor (pic1)
                  c38b831b-3255-48d6-b3f1-b04bd936bd15-image.png

                  Why parts with vis.states are missing like that in runtime (pic2)?

                  e60e8010-539f-49e3-97f2-168e4a24edc1-image.png

                  <!DOCTYPE html>
                  <html>
                      <body>
                           
                          <canvas id="myCanvas" width="401" height="401" style="border:1px solid #d3d3d3;">
                              Your browser does not support the HTML5 canvas tag.
                          </canvas>
                           
                          <script type="text/javascript">
                              console.log(vis.states["admin.0.info.updatesNumber.val"]);
                              var part1 = vis.states["admin.0.info.updatesNumber.val"]/7;
                              var X = 200;
                              var Y = 200;
                              var outterRadius = 180;
                              var innerRadius = 110;
                   
                              // 1. get a reference to myCanvas element.
                              var c = document.getElementById("myCanvas");
                               
                              // 2. get canvas context
                              var context = c.getContext("2d");
                               
                              // 3. draw donut chart
                               
                              // RED
                              setRadialGradient("#DC1C29", "#B7161B");
                              drawDonut(Math.PI *part1, Math.PI * 0.75);
                               
                              // GREEN
                              setRadialGradient("#84BC3D", "#5B8829");
                              drawDonut(Math.PI*0.75 , Math.PI* 1.5);
                               
                              // BLUE
                              setRadialGradient("#27A1D4", "#2182AD");
                              drawDonut(Math.PI * 2*part1, Math.PI*2);
                               
                              // YELLOW
                              setRadialGradient("#ECCF2D", "#F1C433");
                              drawDonut(0, Math.PI*.5);
                               
                              //*******************************************************//\        
                              // drawDonut() function drawes 2 full or partial circles inside each other one clockwise and the other is counter-clockwise
                              function drawDonut(sRadian, eRadian){
                                   
                                  context.beginPath();
                                      context.arc(X, Y, outterRadius, sRadian, eRadian, false); // Outer: CCW
                                      context.arc(X, Y, innerRadius, eRadian, sRadian, true); // Inner: CW
                                  context.closePath();
                                   
                                  // add shadow
                                  addShadow();
                                                   
                                  context.fill();
                              }
                               
                              function addShadow(){
                                  context.shadowColor = "#333";
                                  context.shadowBlur = 5;
                                  context.shadowOffsetX = 0;
                                  context.shadowOffsetY = 0;
                              }
                               
                              function setRadialGradient(sgc, bgc){
                                  var grd = context.createRadialGradient(X, Y, innerRadius + 5, X, Y, outterRadius);
                                  grd.addColorStop(0,sgc);
                                  grd.addColorStop(1,bgc);
                                  context.fillStyle = grd;
                              }
                          </script>
                      </body>
                  </html>
                  
                  foxriver76F Offline
                  foxriver76F Offline
                  foxriver76
                  Developer
                  schrieb am zuletzt editiert von
                  #8

                  @KarolisL only the states which are on the active view will be synced, that’s why in my screenshot so many values are null and browser console said only requested 5 states. So probably it’s due to this fact?

                  Videotutorials & mehr

                  Hier könnt ihr mich unterstützen.

                  KarolisLK 1 Antwort Letzte Antwort
                  0
                  • foxriver76F foxriver76

                    @KarolisL only the states which are on the active view will be synced, that’s why in my screenshot so many values are null and browser console said only requested 5 states. So probably it’s due to this fact?

                    KarolisLK Offline
                    KarolisLK Offline
                    KarolisL
                    schrieb am zuletzt editiert von
                    #9

                    @foxriver76 The problem was that all states were present in tab-objects, but for them to appear in visualization and to be synchronized, you have to create dummy widget and make it invisible later as you mentioned in post 2. "So you could add a dummy widget with the desired states and make it invisible. "

                    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

                    359

                    Online

                    32.7k

                    Benutzer

                    82.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