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

Examples of advanced control rules

Scheduled Pinned Locked Moved Troubleshooting
17 Posts 4 Posters 5.7k 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.
  • J Offline
    jkandasa @goranrad
    last edited by 14 May 2017, 08:53

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

    1 Reply Last reply Reply Quote 0
    • G Offline
      goranrad
      last edited by 14 May 2017, 09:25

      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

      J 2 Replies Last reply 15 May 2017, 08:14 Reply Quote 1
      • J Offline
        jkandasa @goranrad
        last edited by 15 May 2017, 08:14

        @goranrad I will come up with a script shortly.

        B 1 Reply Last reply 15 May 2017, 14:00 Reply Quote 0
        • B Offline
          blacksheepinc @jkandasa
          last edited by 15 May 2017, 14:00

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

          J 1 Reply Last reply 15 May 2017, 15:37 Reply Quote 0
          • J Offline
            jkandasa @blacksheepinc
            last edited by 15 May 2017, 15:37

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

            1 Reply Last reply Reply Quote 0
            • J Offline
              jkandasa @goranrad
              last edited by 16 May 2017, 03:04

              @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 Offline
                goranrad
                last edited by 16 May 2017, 18:12

                Thank you !

                1 Reply Last reply Reply Quote 0
                • G Offline
                  goranrad
                  last edited by 16 May 2017, 18:59

                  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

                  J 1 Reply Last reply 17 May 2017, 12:43 Reply Quote 0
                  • J Offline
                    jkandasa @goranrad
                    last edited by jkandasa 17 May 2017, 12:43

                    @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 Offline
                      goranrad
                      last edited by 17 May 2017, 14:40

                      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

                      J 1 Reply Last reply 17 May 2017, 16:42 Reply Quote 0
                      • J Offline
                        jkandasa @goranrad
                        last edited by jkandasa 17 May 2017, 16:42

                        @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 Offline
                          goranrad
                          last edited by goranrad 17 May 2017, 21:12

                          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!

                          J 1 Reply Last reply 19 May 2017, 14:02 Reply Quote 0
                          • J Offline
                            jkandasa @goranrad
                            last edited by 19 May 2017, 14:02

                            @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
                            14 out of 17
                            • First post
                              14/17
                              Last post

                            0

                            Online

                            628

                            Users

                            532

                            Topics

                            3.4k

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