• Categories
  • Recent
  • Tags
  • Popular
  • Register
  • Login
  • Categories
  • Recent
  • Tags
  • Popular
  • Register
  • Login

Custom Output to display

Scheduled Pinned Locked Moved Scripts
12 Posts 2 Posters 4.5k Views 1 Watching
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    Darvos
    last edited by 2 Jun 2017, 11:44

    Sure, I want to multiply an input by a variable , put the result in a variable and show it at my dashboard !

    Example : I'm reading a light sensor, I wanna have both the raw value and the valia of the light multiplied by certain number in my dash board!

    So I create a "sensor viewer " and a "custom viewer " right?

    Well, for the custom viewer I need a script to do the job for me... taking both utags and variables and doing a simple multiplication , then show me the valeu ... right?

    Well I need help finishing the script because, I can make the simple code but can't make it show the valeu at the "custom viewer " . I guess I'm missing both the template and the script binding

    1 Reply Last reply Reply Quote 0
    • D Offline
      Darvos
      last edited by 2 Jun 2017, 18:32

      In other words , how can I display a variable, not a input or a tag, just a variable

      1 Reply Last reply Reply Quote 0
      • D Offline
        Darvos @jkandasa
        last edited by 8 Jun 2017, 22:16

        @jkandasa I forgot the reply you didn't I?

        Sorry, but I'm still hoping you can help me with this.

        Thank you very much

        J 1 Reply Last reply 9 Jun 2017, 09:06 Reply Quote 0
        • J Offline
          jkandasa @Darvos
          last edited by 9 Jun 2017, 09:06

          @Darvos You have to do all your calculations on your script and create an HTML template to display the value on the dashboard. Example: http://forum.mycontroller.org/topic/144/how-to-show-several-sensor-readings-in-a-single-widget/4

          D 1 Reply Last reply 9 Jun 2017, 09:09 Reply Quote 0
          • D Offline
            Darvos @jkandasa
            last edited by 9 Jun 2017, 09:09

            @jkandasa Thaaaats IIIITTT ^^

            Thank you thank you thanks aloooot jkandasa, you beatiful man!!

            I was expecting this for days, and I'm really excited with the outcome of this project

            J 1 Reply Last reply 9 Jun 2017, 09:19 Reply Quote 0
            • J Offline
              jkandasa @Darvos
              last edited by 9 Jun 2017, 09:19

              @Darvos

              JavaScript
              var myImports = new JavaImporter(java.io, java.lang, java.util); 
              with(myImports) {
                var amp1 = mcApi.variable().get("Amp1");
                var volt = mcApi.uidTag().getByUid("VoltRaw1").getResource();
                // custom value
                var finalData = amp1.value * volt.value;
              }
              
              HTML template
              <div>My custom value: ${finalData}</div>
              <div>Raw values:[Amp1:${amp1.value}, volt:${volt.value}]</div>
              

              Note: Use the latest version of MyController from here

              D 2 Replies Last reply 14 Jun 2017, 16:26 Reply Quote 0
              • D Offline
                Darvos @jkandasa
                last edited by 14 Jun 2017, 16:26

                @jkandasa J, my saivior!! the project is working just fine, i only have one question to make!! plz save me!!

                i've been trying to acumulate values (anyvar += anyvar) without sucess...

                I tried loops, timers, no sucess...

                I need to sum all the values I gather since the first reading.. any tip?

                1 Reply Last reply Reply Quote 0
                • D Offline
                  Darvos @jkandasa
                  last edited by jkandasa 14 Jun 2017, 18:00

                  @jkandasa Gosh, so.. I was doing some research over the forum... and I found this http://forum.mycontroller.org/topic/139/hour-meter wich I've been trying to use with no sucess...

                  let me put some good info here!

                  0_1497462933454_image.png
                  I've made those simple custom widgets, here is the script for them

                  var myImports = new JavaImporter(java.io, java.lang, java.util); 
                  var Custo = 0;
                  with(myImports) {
                    var amp1 = mcApi.uidTag().getByUid("AmpRaw1").getResource()
                    var volt = mcApi.uidTag().getByUid("VoltRaw1").getResource();
                    var taxa = mcApi.variable().get("Taxa"); 
                    var Custo_aux = mcApi.variable().get("CustoT"); 
                  
                    // custom value
                    var finalData = (amp1.value * volt.value)/ 1000;
                    Custo_aux.value = finalData * taxa.value;
                  }
                  

                  I just need a way to acumulate(a.k.a SUM) the values os the last line like Custo_aux.value += the rest...

                  I've been trying to use the .save() without success too..

                  Plz master J, help me out!!

                  J 1 Reply Last reply 15 Jun 2017, 10:47 Reply Quote 0
                  • J Offline
                    jkandasa @Darvos
                    last edited by 15 Jun 2017, 10:47

                    @Darvos By default, Repository and SensorVariable values will be stored as String You need to convert it to Integer, Float or as you like.

                    var myImports = new JavaImporter(java.io, java.lang, java.util); 
                    with(myImports) {
                      var amp1 = mcApi.uidTag().getByUid("AmpRaw1").getResource()
                      var volt = mcApi.uidTag().getByUid("VoltRaw1").getResource();
                      var taxa = mcApi.variable().get("Taxa"); 
                      var Custo_aux = mcApi.variable().get("CustoT"); 
                    
                      // custom value
                      var finalData = (parseFloat(amp1.value) * parseFloat(volt.value))/ 1000;
                      var currentCusto = finalData * parseFloat(taxa.value);
                      Custo_aux.value = parseFloat(Custo_aux.value) + currentCusto; //SUM with previous values
                      Custo_aux.save(); //store it on repository
                    }
                    

                    Note: Repository variables Taxa, CustoT should be created with default values. before to execute this script at first time.

                    1 Reply Last reply Reply Quote 0
                    • D Offline
                      Darvos
                      last edited by 15 Jun 2017, 12:08

                      Thank you thank you!

                      you are the best!

                      1 Reply Last reply Reply Quote 0
                      12 out of 12
                      • First post
                        12/12
                        Last post

                      0

                      Online

                      641

                      Users

                      532

                      Topics

                      3.4k

                      Posts
                      Copyright © 2015-2025 MyController.org | Contributors | Localization