Help Coding own Conditional Function

Hi Guys,

I build an magnetic stirring unit for my base, acid and the fertilizer.
For this I glued two magnets on each fan. A housing was printed on the outside. The fan is mounted in the housing. The container with the respective liquid is then placed on the housing. There is also a magnet in each of the liquids. As soon as the fans start up, the magnets in the liquids are carried along by the magnetic force, causing the liquid to be stirred.

The hardware is ready and each fan is connected to a relay.

I tried to create a conditional function. However, I cannot get this to work. None of the outputs are acting.
Does anyone happen to see the mistake I made?
Or can anybody give me advice to create a function the right way if creating a function by a conditional function is the worng way?

# Example code for learning how to use a Conditional. See the manual for more information.
self.logger.info("This INFO log entry will appear in the Daemon Log")

self.loop_count += 1  # Counts how many times the run code has been executed

########################################################################################
#Declaration
measurement_ph = self.condition("9995db5f")  # Replace ID with correct Conditional ID
measurement_ec = self.condition("c5942d7c")  # Replace ID with correct Conditional ID
self.logger.info(f"pH measurement value is {measurement_ph}")
self.logger.info(f"EC measurement value is {measurement_ec}")

setpoint_ph = 8
hysteresis_ph = 0.35

setpoint_ec = 900
hysteresis_ec = 100

t_stirr = 20

########################################################################################
#Regulation pH

if measurement_ph is not None:  # If a measurement exists
    self.message += "This message appears in email alerts and notes.\n"

    #pH too low 
    if measurement_ph < (setpoint_ph-hysteresis_ph):  
        self.message += f"pH measurement is too Low! Measurement is {measurement_ph}\n"
        self.run_action(message=self.message)  # Run all actions sequentially
        self.run_action("08174ef9") #Stirring
        self.run_action("82ab9093") #Pause
        self.run_action("d3350900") #Dispense pH Upper
    

    #pH too high
    elif measurement_ph > (setpoint_ph+hysteresis_ph):  
        self.message += f"pH measurement is too High! Measurement is {measurement_ph}\n"
        self.run_action(message=self.message)  # Run a single specific Action
        self.run_action("98680d9e") #Stirring
        self.run_action("82ab9093") #Pause
        self.run_action("f237d75e") #Dispense pH Downer

#########################################################################################
#Regulation EC

if measurement_ph is not None:  # If a measurement exists
    self.message += "No EC measurement available.\n"

    #EC too Low --> add fertilizer
    if measurement_ec < (setpoint_ec-hysteresis_ec):  
        self.message += f"EC measurement is too Low! Measurement is {measurement_ec}\n"
        self.run_action(message=self.message)  # Run all actions sequentially
        self.run_action("d5b06b69", message=self.message) #Stirrer Fertilizer
        self.run_action("82ab9093") #Pause
        self.run_action("683361df") #Dispense Fertilizer


    elif measurement_ec > (setpoint_ec+2*hysteresis_ec):  
        self.message += f"EC measurement is too High! Measurement is {measurement_ph}\n"
        # Replace "qwer5678" with an Action ID

Regards

Edit: not sure if you can see the pictures

Have you looked at the log yet? Maybe none of the if conditions is true. I would execute the all actions to ensure the fans and the pumps work first, only then add more control logic. Good luck.

1 Like

I’m not sure of the exact issue you have, but I do notice you’re using self.run_action() without passing the required Action ID. You will generate an exception by not providing a required parameter to that function. Since that is the first function you attempt to call in the series of function calls, it would make sense you wouldn’t see any functions called, since the exception that occurs on that first one will prevent any later ones from running. As @truongqt mentioned, you should be referring to the logs for any errors. You should also get in the habit of encasing your code in try/except blocks with self.logger.exception() in the except block to capture exceptions in the log (if they don’t already appear in the log).