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

    Examples of advanced control rules

    scheduled pinned locked moved Troubleshooting
    17 posts 4 posters 6.3k views 1 watching
    loading-more-posts
    • oldest-to-newest
    • newest-to-oldest
    • most-votes
    reply
    • reply-as-topic
    guest-login-reply
    deleted-message
    • G offline
      goranrad
      global:last-edited-by,

      I'm struggling with humidity in my greenhouse as well. Please help me with a python compare script example that reads a sensor value and a sensor state, then evaluates them and returns true or false. To be used as a compare script for a rule.

      Regards
      Goran

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

        @goranrad can you elaborate more about steps you want in script?

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

          Hi, what I want is when the humidity (humidity sensor value) is under a level to have my humidifier (relay) to switch on for 10 sec then switch of for 30 sec until the humidity have reached its threshold.

          Think I have to use two UDItag for humidity sensor and relay state.
          Then use one variable with two keys. on time and off time.

          Humidity control in a greenhouse is difficult that's why i want to use variables to easily be able to adjust on and off intervals.

          Kindest regards
          Goran

          jkandasaJ topic:replies-to-this-post, 2 last-reply-time reply quote 1
          • jkandasaJ offline
            jkandasa @goranrad
            global:last-edited-by,

            @goranrad I will come up with a script shortly.

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

              @jkandasa I think in these cases blockly would be very useful.
              Have you tried Domoticz before? It has blockly, and making the above mentioned algorithems with it are such an easy job.

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

                @blacksheepinc No, I never tried Domoticz. Let me have a look. thank you

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

                  @goranrad For this kind of work execute the script with timer suits perfectly. Use the following script to control your humidity-controller. you can use the following script as an operation type (NOT condition type) and configure a timer to execute this script for every 40 seconds once.

                  Note: do not forget to create UID tags for humidity and humidifier. 🙂

                  import time
                  
                  humidity = mcApi.uidTag().getByUid("uid-humidity").getResource();
                  humidifier = mcApi.uidTag().getByUid("uid-humidifier").getResource();
                  
                  humidity_threshold = 78.4
                  on_time = 10 # seconds
                  
                  if(float(humidity.value) < humidity_threshold):
                    humidifier.value = "1";
                    mcApi.sensor().sendPayload(humidifier); # sensd state
                    time.sleep(on_time)
                    humidifier.value = "0";
                    mcApi.sensor().sendPayload(humidifier); # sensd state
                  

                  0_1494903771553_humidity-controller.png

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

                    Thank you !

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

                      Hi again,

                      Sorry to disturb but I get the following error when i try to manually run the script.

                      {
                      "errorMessage": "AttributeError: 'org.mycontroller.standalone.db.tables.UidTag' object has no attribute 'getResource' in <script> at line number 3"
                      }

                      Sure I don't have to import mcAPI to python or something?

                      I have created the UDItags

                      Regards
                      Goran

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

                        @goranrad
                        The error looks like, you do not create UID-Tag as follows,

                        0_1495025133044_upload-be870e3c-7d60-4786-a4cc-ef5b5b651505

                        Do you have installed python script engine? By default, MyController does not have python script engine as it is eating more resource. I would recommend going with JavaScript(built-in, lightweight).

                        Refer this link to install python script engine support.

                        If you want, I can convert this script to JavaScript

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

                          Hi, I have python installed and have created UDI tags,
                          0_1495031706178_python.png

                          and the UDIs are there
                          0_1495031740468_udi.png

                          Reason I use Python is because its the language I'm most comfortable with. But i'll do as you say if you pleas can convert the code to JavaScript to get me started.

                          Much appreciated.
                          /goran

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

                            @goranrad You should use latest SNAPSHOT version from here: http://forum.mycontroller.org/topic/58/download-snapshot-build and these resources should have value.

                            I will convert this script to JavaScript by tomorrow and post here.

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

                              Hi J,
                              I did the update and the python script worked like a charm.
                              If you have time pleas post the JavaScript version.

                              Thank you!

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

                                @goranrad JavaScript,

                                var myImports = new JavaImporter(java.lang, java.util);
                                
                                with(myImports) {
                                  var humidity_threshold = 78.4;
                                  var on_time = 10; // seconds
                                  humidity = mcApi.uidTag().getByUid("uid-humidity").getResource();
                                  humidifier = mcApi.uidTag().getByUid("uid-humidifier").getResource();
                                
                                  if(parseFloat(humidity.value) < humidity_threshold){
                                    humidifier.value = "1";
                                    mcApi.sensor().sendPayload(humidifier); // sensd state
                                    Thread.sleep(on_time * 1000);
                                    humidifier.value = "0";
                                    mcApi.sensor().sendPayload(humidifier); // sensd state
                                  }
                                }
                                
                                
                                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