Examples of advanced control rules



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


  • ADMIN

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



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



  • 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


  • ADMIN

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



  • 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


  • ADMIN

    @goranrad I will come up with a script shortly.



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


  • ADMIN

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


  • ADMIN

    @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



  • Thank you !



  • 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


  • ADMIN

    @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



  • 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


  • ADMIN

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



  • 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!


  • ADMIN

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

Log in to reply
 

6
Online

309
Users

206
Topics

1216
Posts

Looks like your connection to MYCONTROLLER.ORG was lost, please wait while we try to reconnect.