What I’m trying to do is take an integer value of 0-100 that is outputted by a tag (Moisture). Then compare that value with a static number to see if it is below 30. If it is below 30, make the memory tag (Pump) True, else False. If the tag returns True, stay true for 5 seconds then revert to false; don’t allow the Pump to be true for 2 minutes. Then repeat the loop
I was looking at a few scripting functions. Through the Gateway Events, you can set it up to run a script on tag change. The issue with this is I don’t think it would play nicely with my delays. I need a 2-minute delay if the Pump value ever gets changed to true (this is to prevent overwatering of the plant hooked up to the moisture sensor). With the Gateway Event script it will execute the loop everytime the tag value changes (thus as far as I can see, constantly reinstating the loop and bypassing the 2-minute delay. The other way I see to do it is through tag scripting, though that would be based on tag change and I’d run into the same issue.
The viable option I see is to use the Sequential Function Chart function, which I messed around with, but am extremely confused about - there’s not a whole lot of documentation out there for it, especially for python amateurs.
Also, I just wanted to add in the code I have to change the value.
import time moisture = system.tag.read("[default]moisture").value wantedMoisture = 30 if (moisture < wantedMoisture): #if moisture is below 30 system.tag.write("[Plant]Pump", "True") #turn on pump time.sleep(5) #keep pump on for 5 seconds system.tag.write("[Plant]Pump", "False") #turn off pump time.sleep(120) #don't allow pump to turn back on for 2 minutes else: system.tag.write("[Plant]Pump", "False") #don't turn on pump if moisture is not below 30
I guess I’m asking a few questions. Is the code above the best and most straightforward way to implement this? If so, where is the best way to put this code so it implements correctly? Otherwise, what is a better way to implement this?