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

    How to use custome widget

    Scheduled Pinned Locked Moved General Discussion
    10 Posts 2 Posters 2.2k 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.
    • A Offline
      Anduril
      last edited by

      Re: How to show several sensor readings in a single widget

      Thanks @jkandasa for your help. I had to let this project rest for some time, but returned now.

      I tried again without luck, so I decided to reduce the code to the bare minimum.
      I defined the UID:
      0_1504622993548_grafik.png

      The Script file:

      var myImports = new JavaImporter(java.io, java.lang, java.util, java.text);
      
      with(myImports) {
        var temperature = mcApi.uidTag().getByUid("Temp").getResource();
      }
      

      and HTML file:

      <div>Outside temperature: °C</div>
      

      But I still get the error when testing the html with script:
      0_1504623224385_grafik.png

      Realy don't know how to solve this (and been thinking about it for half a year)...

      jkandasaJ 1 Reply Last reply Reply Quote 0
      • jkandasaJ Offline
        jkandasa @Anduril
        last edited by

        @Anduril SNAPSHOT will be updated often. Can you update to the recent version of SNAPSHOT version?

        And your HTML file should be as follows:

        <div>Outside temperature:${temperature.value} °C</div>
        
        1 Reply Last reply Reply Quote 0
        • A Offline
          Anduril
          last edited by

          Hi @jkandasa,
          of course the html file code was a copy/paste mistake, it looked as you said.
          Upgrading to the latest snapshot did the trick, it's working now. Thank you very much (in this specific fact and for your amazing controller)
          One last thing: is there a way to read sensor information without defining a UID for it? I plan to build 5-10 identical nodes sending about 10-15 values each. Defining UIDs for each of them would be some work, maybe I can also adress them using kind of gateway>node>sensor terminology.

          jkandasaJ 1 Reply Last reply Reply Quote 0
          • jkandasaJ Offline
            jkandasa @Anduril
            last edited by jkandasa

            @Anduril

            One last thing: is there a way to read sensor information without defining a UID for it? I plan to build 5-10 identical nodes sending about 10-15 values each. Defining UIDs for each of them would be some work, maybe I can also adress them using kind of gateway>node>sensor terminology.

            Yes, it is possible. Have a look this blog: http://forum.mycontroller.org/topic/28/introduction
            ^ Here you can see how we used to query node data. the same way we have to use for sensors too. Inside each sensor list of sensor variables will be.

            var sensors = mcApi.sensor().getAll(options);
            

            Some of options to filter: nodeName, nodeEui, id, sensorId, name, type

            1 Reply Last reply Reply Quote 0
            • A Offline
              Anduril
              last edited by

              Well I tried, but did not get any useful output. Could you please give me an example code for reading node 1 sensor 1 and 2 and node 2 sensor 1 and 2? Do I have to cascade .getAll(node).getAll(sensor)?

              jkandasaJ 1 Reply Last reply Reply Quote 0
              • jkandasaJ Offline
                jkandasa @Anduril
                last edited by

                @Anduril No, cascade won't work. Let me find out a way for this.

                1 Reply Last reply Reply Quote 0
                • A Offline
                  Anduril
                  last edited by Anduril

                  Hey @jkandasa
                  I got a working system thanks to your help. Only one thing that doen't work as I like at the moment: Is it possible to write values to an imported variable?
                  I have a MySensors value (a number) that has an uidTag and can be read by js file. But how can I change the sensor and have it send to the node?
                  When I show the sensor in a sensor widget I can change it and it will update at the node.
                  A side question: is it normal/intended to deactivate focus on these sensor fields every few seconds (update: seems to be the update widget time)? When I click on the value to change it I have few seconds until it will get inactive and the old value. If I hit enter before that 'timeout' it will update correctly.

                  code:

                  var myImports = new JavaImporter(java.io, java.lang, java.util, java.text);
                  
                  with(myImports) {
                    var ID = mcApi.uidTag().getByUid("node-ID").getResource();
                  }
                  
                  ID.value = 123;
                  
                  jkandasaJ 1 Reply Last reply Reply Quote 0
                  • jkandasaJ Offline
                    jkandasa @Anduril
                    last edited by

                    @anduril

                    A side question: is it normal/intended to deactivate focus on these sensor fields every few seconds (update: seems to be the update widget time)? When I click on the value to change it I have few seconds until it will get inactive and the old value. If I hit enter before that 'timeout' it will update correctly.

                    I understand that you are asking the question on dashboard widget(sensors). Yes, as per current design value will be updated every X seconds once. It is not a real-time.

                    To send/update payload you can use,

                      mcApi.sensor().sendPayload(ID); 
                    

                    Refer this link for more details: https://forum.mycontroller.org/topic/146/how-to-set-sensor-value-with-javascript/5

                    1 Reply Last reply Reply Quote 0
                    • A Offline
                      Anduril
                      last edited by

                      Thank you. Is it also possible to create buttons on custom widget? This way I could trigger the sendPayload only when needed and not always when refreshing the widget...

                      jkandasaJ 1 Reply Last reply Reply Quote 0
                      • jkandasaJ Offline
                        jkandasa @Anduril
                        last edited by

                        @anduril There is no direct options available. Let me have a look and update you

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

                        0

                        Online

                        587

                        Users

                        529

                        Topics

                        3.4k

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