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

    Examples of advanced control rules

    Troubleshooting
    4
    17
    4772
    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.
    • N
      njbuch last edited by

      Hi, I am delving into a challenge of controlling the humidity in a room, the algorithm for that is quite complicated, meaning:

      1. Wait 15 minutes, and measure humidity, when its stable, start the fan
      2. Run fan for max 10 minutes and measure humidity while doing it, if falling humidity (until a threshold) keep running
      3. Repeat 1-2 until there is no falling humidity.
      4. Keep monitoring humidty every few minutes, and when over threshold, start with 1.

      Can you guide me to documentation for scripting this stuff....

      jkandasa 1 Reply Last reply Reply Quote 0
      • jkandasa
        jkandasa @njbuch last edited by

        @njbuch can you elaborate the requirement bit more? if can give pseudo code I can address it easily.

        1 Reply Last reply Reply Quote 0
        • N
          njbuch last edited by

          I will try that, but was primarily looking for examples of scripts doing more advanced control stuff...

          1 Reply Last reply Reply Quote 0
          • G
            goranrad 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

            jkandasa 1 Reply Last reply Reply Quote 0
            • jkandasa
              jkandasa @goranrad last edited by

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

              1 Reply Last reply Reply Quote 0
              • G
                goranrad 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

                jkandasa 2 Replies Last reply Reply Quote 1
                • jkandasa
                  jkandasa @goranrad last edited by

                  @goranrad I will come up with a script shortly.

                  B 1 Reply Last reply Reply Quote 0
                  • B
                    blacksheepinc @jkandasa 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.

                    jkandasa 1 Reply Last reply Reply Quote 0
                    • jkandasa
                      jkandasa @blacksheepinc last edited by

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

                      1 Reply Last reply Reply Quote 0
                      • jkandasa
                        jkandasa @goranrad 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

                        1 Reply Last reply Reply Quote 0
                        • G
                          goranrad last edited by

                          Thank you !

                          1 Reply Last reply Reply Quote 0
                          • G
                            goranrad 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

                            jkandasa 1 Reply Last reply Reply Quote 0
                            • jkandasa
                              jkandasa @goranrad 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

                              1 Reply Last reply Reply Quote 0
                              • G
                                goranrad 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

                                jkandasa 1 Reply Last reply Reply Quote 0
                                • jkandasa
                                  jkandasa @goranrad 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.

                                  1 Reply Last reply Reply Quote 0
                                  • G
                                    goranrad 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!

                                    jkandasa 1 Reply Last reply Reply Quote 0
                                    • jkandasa
                                      jkandasa @goranrad 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
                                        }
                                      }
                                      
                                      
                                      1 Reply Last reply Reply Quote 0
                                      • First post
                                        Last post

                                      2
                                      Online

                                      646
                                      Users

                                      504
                                      Topics

                                      3.3k
                                      Posts

                                      Copyright © 2015-2022 MyController.org | Contributors | Localization