Examples of advanced control rules
-
@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. -
@blacksheepinc No, I never tried Domoticz. Let me have a look. thank you
-
@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 anoperation
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
-
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 -
@goranrad
The error looks like, you do not create UID-Tag as follows,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,
and the UDIs are there
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 -
@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!
-
@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 } }