• header.categories
    • header.recent
    • header.tags
    • header.popular
    • register
    • login

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

    scheduled pinned locked moved Scripts
    battery levelbatterynodescriptrule
    4 posts 3 posters 3.9k views 2 watching
    loading-more-posts
    • oldest-to-newest
    • newest-to-oldest
    • most-votes
    reply
    • reply-as-topic
    guest-login-reply
    deleted-message
    • DaTTczD offline
      DaTTcz
      global:last-edited-by, jkandasa

      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

      I am sorry for my bad English. I speak Czech.

      jkandasaJ one-reply-to-this-post last-reply-time reply quote 0
      • jkandasaJ offline
        jkandasa @DaTTcz
        global:last-edited-by, jkandasa

        @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

        one-reply-to-this-post last-reply-time reply quote 1
        • DaTTczD offline
          DaTTcz
          global:last-edited-by, DaTTcz

          Thank you for your response!

          I am sorry for my bad English. I speak Czech.

          one-reply-to-this-post last-reply-time reply quote 0
          • V offline
            Velo17
            global:last-edited-by, Velo17

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

            one-reply-to-this-post last-reply-time reply quote 0
            • first-post
              last-post

            0

            online

            644

            users

            532

            topics

            3.4k

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