Battery level in rules or chart? [Script Rule to check battery level]



  • Hello, how can I work with an item Battery level? How do I keep track of battery usage nodes? It's going to add to the rules? It could based on the condition of batteries to generate rules for individual nodes? I Can add another item to the sensor, but why send another same item. thank you for the advice


  • ADMIN

    @DaTTcz For now direct battery support not available on Rules. However you can do it from script. I will update how to handle with script.

    Kindly create a request on github page to support battery level on rules.

    ALL these features are available on SNAPSHOT build

    Enter your condition via script,

    Steps:

    • Create UID Tag for your node,
    • Create script to check node battery level (script type: Condition)
    • Create rule with this condition script
    • Enjoy :)
    Create UID Tag:

    0_1479454456642_upload-6bd6f2c1-24c2-431c-b97e-6ae08892003c

    Add script:

    0_1479454321011_upload-df8f276c-45cd-4c6c-9ef2-1de1c50f4445
    Java Script to check battery level,

    var myImports = new JavaImporter(java.io, java.lang, java.util, java.text);
    
    with(myImports) {
      var mcResult = false; //By default this is false. When your condition meets change this to true
      var batteryLevel = mcApi.uidTag().getByUid("node1").resource.batteryLevel;
      if(batteryLevel >= 50){ // Your condition
         mcResult = true;
      }
    }
    
    Add rule:

    0_1479454517098_upload-ec78f98b-ead9-442b-80aa-28eda4e10dd4



  • Thank you for your response!



  • @jkandasa I'm using the 0.0.3.Final-SNAPSHOT - does this mean I dont need to create a script like above but find a rule/condition about battery levels of nodes? If so, I cannot find that, but I am currently using your script example, which works, but is of course a little cumbersome compared to another option of using a node's battery level directly somewhere in the rules panel...



7
Online

439
Users

231
Topics

1378
Posts

Looks like your connection to MYCONTROLLER.ORG was lost, please wait while we try to reconnect.