How to show several sensor readings in a single widget



  • Hey there,

    first I like to say that I'm completely new to MyController and realy like the idea of being so flexible about what and how to show it.
    I have a setup with MySensors and at the moment only one node sending multiple integer readings and receiving some text and integer from the controller. Sending text to the node works just fine. But when sending it seems to have a variable overflow. Sensing a value of 32766 is ok, but above that I see strange numbers on my node. Is there a int16_t declaration somewhere in your sending procedure? Because receiving a higher number from the node works fine.
    Second I want to Display some of those reading as overview in a single widget with some text explaining. How do I do that? I did not found an example. At the moment I have them all seperate and was not even able to set a specific order of the sensor IDs in the widget. Here an example of what I want to achiev: "Outside temperature of 12°C. \n The humidity is 75% and 20mm precipitation during the last 24h. [...]"

    Regards,
    Anduril


  • ADMIN

    @Anduril Thanks to having interest with MyController.

    Unfornatually, for now, there is no pre-filter in MyController. Have you tried getFloat(), getLong(), getULong() in the place of an integer on your node? https://github.com/mysensors/MySensors/blob/development/core/MyMessage.h#L303~L307

    Second I want to Display some of those reading as overview in a single widget with some text explaining. How do I do that? I did not found an example. At the moment I have them all seperate and was not even able to set a specific order of the sensor IDs in the widget. Here an example of what I want to achiev: "Outside temperature of 12°C. \n The humidity is 75% and 20mm precipitation during the last 24h. [...]"

    You have to create UidTags for your resources and write script and HTML templates. Kindly have a look on http://forum.mycontroller.org/topic/139/hour-meter/2 to get an idea.



  • Well, you got it. Thanks a lot @jkandasa for pointing me to the getLong() function in the receiving code of my node. I should have thought about that.

    I read the thread you linked and also some others, but I have to confess: I'm new also to js. So I might be using those methods in a wrong syntax. I have a script to get a variable filled with the data from a sensor (with UID "T1ID") and a template calling this variable. What am I doing wrong, I get an error message:

    script:

    var myImports = new JavaImporter(java.io, java.lang, java.util, java.text);
    
    with(myImports) {
      var T1_ID= mcApi.uidTag().getByUid("T1ID").getResource();
      var T1N1 = mcApi.uidTag().getByUid("T1Name1").getResource();
      var T1N2 = mcApi.uidTag().getByUid("T1Name2").getResource();
    

    template:

    <!DOCTYPE html>
    <html>
      <style>body {font-size: 12px;}</style>
      <body>
        <b>Dear User,</b>
        <br>
        <br>There is a rule triggered for you!
        <br>
        <br>
        ${T1_ID}
        <br>
        <br>-- Powered by <a href='http://www.MyController.org'>www.MyController.org</a>
      </body>
    </html>
    

    error:
    0_1490208204361_grafik.png

    UID:
    0_1490208253808_grafik.png


  • ADMIN

    @Anduril You have to create UidTag for required variables, For example. If you want to show outside temperature, humidity and precipitation. Create UidTag for all these variables as follows,

    • outside-temperature >> for outside temperature
    • humidity >> for Humidity
    • precipitation >> to show precipitation

    Note: Creat UidTag for the above value.

    Script:

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

    Now create an HTML template to show these values,

    <div>Outside temperature: ${temperature.value}°C</div>
    <div>Humidity: ${humidity.value}%</div>
    <div>${precipitation.value}mm precipitation during the last 24h</div>
    

    Use this script and template on dashboard custom widget.


Log in to reply