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

    How to delete a sensor variable from script

    Scheduled Pinned Locked Moved Scripts
    sensor variablesensorvariablescriptjavascript
    4 Posts 3 Posters 872 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.
    • jkandasaJ Offline
      jkandasa
      last edited by

      For now, there is no option to delete a sensor variable alone from the GUI. So I'm providing an option to delete a sensor variable from a script.

      Note: This API available from 1.4.0.Final version.

      • Now get SensorVariable id from Sensors page. Resources >> Sensors >> Click on view details,
        0_1482765833386_upload-d79d7e6b-d0f6-4bc6-b6b6-0366b8968b09
        Now click on edit of sensor variable
        0_1482765892413_upload-5797ae73-a6ee-4dec-b810-928013f4c2d3

      On the URL you can see sensor variable id, This is id is important note it for your target sensor variable
      0_1482765974523_upload-1240a386-2016-4a96-b144-d2444df9fc73

      Add the following script on your controller,
      Extension: JavaScript
      Type: Operation

      var myImports = new JavaImporter(java.io, java.lang, java.util);
      
      with(myImports) {
        // pass sensor variable as bindings, example: { id: 99 }
        mcApi.sensor().deleteSensorVariable(id);
      }
      

      Execute the script as Run now (select the script and in Actions you can see Run now),
      Pass the sensor variable id as bindings, here it is { id: 99 },
      0_1539689727209_cb4a5f9a-3264-4844-9f1f-920f7c76d063-image.png

      Click on Run. All done. Now your Sensor variable removed from MyController.

      skywatchS 1 Reply Last reply Reply Quote 1
      • skywatchS Offline
        skywatch @jkandasa
        last edited by

        @jkandasa Thank you so much for this! 🙂

        It had slipped my mind with other more important issues taking the focus away. Today I found some 'ghost' variables and remembered that I had the problem before, but not the solution. Now I know why!

        Anyway it worked perfectly and I will keep a lookout for any future ghost variables. This would be a good thing to have built into ver 2.0 😉

        1 Reply Last reply Reply Quote 1
        • F Offline
          fsgrazzutti
          last edited by

          @jkandasa I will never be thankful enough for MyController

          I found this looking for a way to delete sensors older than a time interval. The reason is that over time and trials I have accumulated a huge amount of sensor variables which I would like to get rid of.
          Sometimes they are just sensor variables added on top of the true ones.

          Since I have little practice with Javascript I would need some guidance to write a script which removes all the sensor variables older than a given (fixed) interval.

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

            @fsgrazzutti Currently I am actively working in V2.
            I will have a look in to this soon 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