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

    How to delete a sensor variable from script

    scheduled pinned locked moved Scripts
    sensor variablesensorvariablescriptjavascript
    4 posts 3 posters 1.3k views 1 watching
    loading-more-posts
    • oldest-to-newest
    • newest-to-oldest
    • most-votes
    reply
    • reply-as-topic
    guest-login-reply
    deleted-message
    • jkandasaJ offline
      jkandasa
      global: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 one-reply-to-this-post last-reply-time reply quote 1
      • skywatchS offline
        skywatch @jkandasa
        global: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 😉

        one-reply-to-this-post last-reply-time reply quote 1
        • F offline
          fsgrazzutti
          global: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 one-reply-to-this-post last-reply-time reply quote 0
          • jkandasaJ offline
            jkandasa @fsgrazzutti
            global:last-edited-by,

            @fsgrazzutti Currently I am actively working in V2.
            I will have a look in to this soon and update you

            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